mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
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:
@ -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(_)
|
||||
|
||||
Reference in New Issue
Block a user