From b96687c3fa863af76afef68170ee2c59946b76fd Mon Sep 17 00:00:00 2001 From: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:12:31 +0530 Subject: [PATCH] fix(Connector): [Noon] Update ApplePay Payment Struct (#1794) Co-authored-by: Jagan --- config/config.example.toml | 4 ++ config/development.toml | 2 +- config/docker_compose.toml | 3 + .../router/src/connector/noon/transformers.rs | 67 ++++++++++++++++++- loadtest/config/development.toml | 3 + 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/config/config.example.toml b/config/config.example.toml index e96b54a20c1..bae450663a5 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -200,6 +200,10 @@ trustpay.base_url_bank_redirects = "https://aapi.trustpay.eu/" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" +#Payment Method Filters Based on Country and Currency +[pm_filters.default] +apple_pay = { country = "AU,CN,HK,JP,MO,MY,NZ,SG,TW,AM,AT,AZ,BY,BE,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GR,GL,GG,HU,IS,IE,IM,IT,KZ,JE,LV,LI,LT,LU,MT,MD,MC,ME,NL,NO,PL,PT,RO,SM,RS,SK,SI,ES,SE,CH,UA,GB,AR,CO,CR,BR,MX,PE,BH,IL,JO,KW,PS,QA,SA,AE,CA,UM,US", currency = "AED,AUD,CHF,CAD,EUR,GBP,HKD,SGD,USD" } + # Bank redirect configs for allowed banks through online_banking_czech_republic payment method [bank_config.online_banking_czech_republic] adyen = { banks = "ceska_sporitelna,komercni_banka,platnosc_online_karta_platnicza" } diff --git a/config/development.toml b/config/development.toml index 237154253f7..11c268dca3d 100644 --- a/config/development.toml +++ b/config/development.toml @@ -204,7 +204,7 @@ adyen.banks = "bangkok_bank,krungsri_bank,krung_thai_bank,the_siam_commercial_ba [pm_filters.default] google_pay = { country = "AL,DZ,AS,AO,AG,AR,AU,AT,AZ,BH,BY,BE,BR,BG,CA,CL,CO,HR,CZ,DK,DO,EG,EE,FI,FR,DE,GR,HK,HU,IN,ID,IE,IL,IT,JP,JO,KZ,KE,KW,LV,LB,LT,LU,MY,MX,NL,NZ,NO,OM,PK,PA,PE,PH,PL,PT,QA,RO,RU,SA,SG,SK,ZA,ES,LK,SE,CH,TW,TH,TR,UA,AE,GB,US,UY,VN" } -apple_pay = { country = "AU,CN,HK,JP,MO,MY,NZ,SG,TW,AM,AT,AZ,BY,BE,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GR,GL,GG,HU,IS,IE,IM,IT,KZ,JE,LV,LI,LT,LU,MT,MD,MC,ME,NL,NO,PL,PT,RO,SM,RS,SK,SI,ES,SE,CH,UA,GB,AR,CO,CR,BR,MX,PE,BH,IL,JO,KW,PS,QA,SA,AE,CA,UM,US", currency = "AUD,CHF,CAD,EUR,GBP,HKD,SGD,USD" } +apple_pay = { country = "AU,CN,HK,JP,MO,MY,NZ,SG,TW,AM,AT,AZ,BY,BE,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GR,GL,GG,HU,IS,IE,IM,IT,KZ,JE,LV,LI,LT,LU,MT,MD,MC,ME,NL,NO,PL,PT,RO,SM,RS,SK,SI,ES,SE,CH,UA,GB,AR,CO,CR,BR,MX,PE,BH,IL,JO,KW,PS,QA,SA,AE,CA,UM,US", currency = "AED,AUD,CHF,CAD,EUR,GBP,HKD,SGD,USD" } paypal = { currency = "AUD,BRL,CAD,CZK,DKK,EUR,HKD,HUF,INR,JPY,MYR,MXN,NZD,NOK,PHP,PLN,RUB,GBP,SGD,SEK,CHF,THB,USD" } klarna = { country = "AT,BE,DK,FI,FR,DE,IE,IT,NL,NO,ES,SE,GB,US,CA", currency = "USD,GBP,EUR,CHF,DKK,SEK,NOK,AUD,PLN,CAD" } affirm = { country = "US", currency = "USD" } diff --git a/config/docker_compose.toml b/config/docker_compose.toml index 073abc578cc..f142e31a15a 100644 --- a/config/docker_compose.toml +++ b/config/docker_compose.toml @@ -123,6 +123,9 @@ zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" +[pm_filters.default] +apple_pay = { country = "AU,CN,HK,JP,MO,MY,NZ,SG,TW,AM,AT,AZ,BY,BE,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GR,GL,GG,HU,IS,IE,IM,IT,KZ,JE,LV,LI,LT,LU,MT,MD,MC,ME,NL,NO,PL,PT,RO,SM,RS,SK,SI,ES,SE,CH,UA,GB,AR,CO,CR,BR,MX,PE,BH,IL,JO,KW,PS,QA,SA,AE,CA,UM,US", currency = "AED,AUD,CHF,CAD,EUR,GBP,HKD,SGD,USD" } + [connectors.supported] wallets = ["klarna", "braintree", "applepay"] rewards = ["cashtocode", "zen"] diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs index 648a7082453..b7b200804cf 100644 --- a/crates/router/src/connector/noon/transformers.rs +++ b/crates/router/src/connector/noon/transformers.rs @@ -1,13 +1,16 @@ +use error_stack::ResultExt; use masking::Secret; use serde::{Deserialize, Serialize}; use crate::{ connector::utils::{ self as conn_utils, PaymentsAuthorizeRequestData, RefundsRequestData, RouterData, + WalletData, }, core::errors, services, types::{self, api, storage::enums, ErrorResponse}, + utils, }; // These needs to be accepted from SDK, need to be done after 1.0.0 stability as API contract will change @@ -77,10 +80,49 @@ pub struct NoonCard { cvv: Secret, } +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct NoonApplePayPaymentMethod { + pub display_name: String, + pub network: String, + #[serde(rename = "type")] + pub pm_type: String, +} + +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct NoonApplePayHeader { + ephemeral_public_key: Secret, + public_key_hash: Secret, + transaction_id: Secret, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct NoonApplePaymentData { + version: Secret, + data: Secret, + signature: Secret, + header: NoonApplePayHeader, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct NoonApplePayData { + payment_data: NoonApplePaymentData, + payment_method: NoonApplePayPaymentMethod, + transaction_identifier: Secret, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct NoonApplePayTokenData { + token: NoonApplePayData, +} + #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct NoonApplePay { - payment_token: Secret, + payment_info: Secret, } #[derive(Debug, Serialize)] @@ -145,7 +187,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { expiry_year: req_card.card_exp_year, cvv: req_card.card_cvc, })), - api::PaymentMethodData::Wallet(wallet_data) => match wallet_data { + api::PaymentMethodData::Wallet(wallet_data) => match wallet_data.clone() { api_models::payments::WalletData::GooglePay(google_pay_data) => { Ok(NoonPaymentData::GooglePay(NoonGooglePay { api_version_minor: GOOGLEPAY_API_VERSION_MINOR, @@ -156,8 +198,27 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { })) } api_models::payments::WalletData::ApplePay(apple_pay_data) => { + let payment_token_data = NoonApplePayTokenData { + token: NoonApplePayData { + payment_data: wallet_data.get_wallet_token_as_json()?, + payment_method: NoonApplePayPaymentMethod { + display_name: apple_pay_data.payment_method.display_name, + network: apple_pay_data.payment_method.network, + pm_type: apple_pay_data.payment_method.pm_type, + }, + transaction_identifier: Secret::new( + apple_pay_data.transaction_identifier, + ), + }, + }; + let payment_token = + utils::Encode::::encode_to_string_of_json( + &payment_token_data, + ) + .change_context(errors::ConnectorError::RequestEncodingFailed)?; + Ok(NoonPaymentData::ApplePay(NoonApplePay { - payment_token: Secret::new(apple_pay_data.payment_data), + payment_info: Secret::new(payment_token), })) } api_models::payments::WalletData::PaypalRedirect(_) => { diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml index 3291e442d27..b3e599be96c 100644 --- a/loadtest/config/development.toml +++ b/loadtest/config/development.toml @@ -109,6 +109,9 @@ trustpay.base_url_bank_redirects = "https://aapi.trustpay.eu/" zen.base_url = "https://api.zen-test.com/" zen.secondary_base_url = "https://secure.zen-test.com/" +[pm_filters.default] +apple_pay = { country = "AU,CN,HK,JP,MO,MY,NZ,SG,TW,AM,AT,AZ,BY,BE,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GE,DE,GR,GL,GG,HU,IS,IE,IM,IT,KZ,JE,LV,LI,LT,LU,MT,MD,MC,ME,NL,NO,PL,PT,RO,SM,RS,SK,SI,ES,SE,CH,UA,GB,AR,CO,CR,BR,MX,PE,BH,IL,JO,KW,PS,QA,SA,AE,CA,UM,US", currency = "AED,AUD,CHF,CAD,EUR,GBP,HKD,SGD,USD" } + [connectors.supported] wallets = ["klarna", "braintree", "applepay"] rewards = ["cashtocode", "zen"]