Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(apple_pay): add support for decrypted apple pay token for checkout (#2628)

Shankar Singh C794dbc6a766d
diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs
index 31deae0236..53182e65ed 100644
--- a/crates/router/src/connector/checkout/transformers.rs
+++ b/crates/router/src/connector/checkout/transformers.rs
@@ -1,6 +1,6 @@
use common_utils::{errors::CustomResult, ext_traits::ByteSliceExt};
use error_stack::{IntoReport, ResultExt};
-use masking::{ExposeInterface, Secret};
+use masking::{ExposeInterface, PeekInterface, Secret};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
use url::Url;
@@ -282,8 +282,7 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
Ok(a)
}
api::PaymentMethodData::Wallet(wallet_data) => match wallet_data {
- api_models::payments::WalletData::GooglePay(_)
- | api_models::payments::WalletData::ApplePay(_) => {
+ api_models::payments::WalletData::GooglePay(_) => {
Ok(PaymentSource::Wallets(WalletSource {
source_type: CheckoutSourceTypes::Token,
token: match item.router_data.get_payment_method_token()? {
@@ -294,6 +293,48 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
},
}))
}
+ api_models::payments::WalletData::ApplePay(_) => {
+ let payment_method_token = item.router_data.get_payment_method_token()?;
+ match payment_method_token {
+ types::PaymentMethodToken::Token(apple_pay_payment_token) => {
+ Ok(PaymentSource::Wallets(WalletSource {
+ source_type: CheckoutSourceTypes::Token,
+ token: apple_pay_payment_token,
+ }))
+ }
+ types::PaymentMethodToken::ApplePayDecrypt(decrypt_data) => {
+ let expiry_year_4_digit = Secret::new(format!(
+ "20{}",
+ decrypt_data
+ .clone()
+ .application_expiration_date
+ .peek()
+ .get(0..2)
+ .ok_or(errors::ConnectorError::RequestEncodingFailed)?
+ ));
+ let exp_month = Secret::new(
+ decrypt_data
+ .clone()
+ .application_expiration_date
+ .peek()
+ .get(2..4)
+ .ok_or(errors::ConnectorError::RequestEncodingFailed)?
+ .to_owned(),
+ );
+ Ok(PaymentSource::ApplePayPredecrypt(Box::new(
+ ApplePayPredecrypt {
+ token: decrypt_data.application_primary_account_number,
+ decrypt_type: "network_token".to_string(),
+ token_type: "applepay".to_string(),
+ expiry_month: exp_month,
+ expiry_year: expiry_year_4_digit,
+ eci: decrypt_data.payment_data.eci_indicator,
+ cryptogram: decrypt_data.payment_data.online_payment_cryptogram,
+ },
+ )))
+ }
+ }
+ }
api_models::payments::WalletData::AliPayQr(_)
| api_models::payments::WalletData::AliPayRedirect(_)
| api_models::payments::WalletData::AliPayHkRedirect(_)