Skip to content

Commit

Permalink
feat(apple_pay): add support for decrypted apple pay token for checko…
Browse files Browse the repository at this point in the history
…ut (#2628)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Prajjwal Kumar <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2023
1 parent 01410bb commit 794dbc6
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions crates/router/src/connector/checkout/transformers.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()? {
Expand All @@ -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(_)
Expand Down

0 comments on commit 794dbc6

Please sign in to comment.