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

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Prajjwal Kumar <prajjwal.kumar@juspay.in>
This commit is contained in:
Shankar Singh C
2023-10-18 18:49:49 +05:30
committed by GitHub
parent 01410bb9f2
commit 794dbc6a76

View File

@ -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(_)