mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(payments): store and propagate additional wallet pm details in payments response (#5869)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -2046,6 +2046,7 @@ pub enum AdditionalPaymentData {
|
||||
},
|
||||
Wallet {
|
||||
apple_pay: Option<ApplepayPaymentMethod>,
|
||||
google_pay: Option<additional_info::WalletAdditionalDataForCard>,
|
||||
},
|
||||
PayLater {
|
||||
klarna_sdk: Option<KlarnaSdkPaymentMethod>,
|
||||
@ -3069,7 +3070,7 @@ where
|
||||
| PaymentMethodDataResponse::PayLater(_)
|
||||
| PaymentMethodDataResponse::RealTimePayment(_)
|
||||
| PaymentMethodDataResponse::Upi(_)
|
||||
| PaymentMethodDataResponse::Wallet {}
|
||||
| PaymentMethodDataResponse::Wallet(_)
|
||||
| PaymentMethodDataResponse::BankTransfer(_)
|
||||
| PaymentMethodDataResponse::OpenBanking(_)
|
||||
| PaymentMethodDataResponse::Voucher(_) => {
|
||||
@ -3090,7 +3091,7 @@ where
|
||||
pub enum PaymentMethodDataResponse {
|
||||
Card(Box<CardResponse>),
|
||||
BankTransfer(Box<BankTransferResponse>),
|
||||
Wallet {},
|
||||
Wallet(Box<WalletResponse>),
|
||||
PayLater(Box<PaylaterResponse>),
|
||||
BankRedirect(Box<BankRedirectResponse>),
|
||||
Crypto(Box<CryptoResponse>),
|
||||
@ -3187,6 +3188,21 @@ pub struct PaylaterResponse {
|
||||
klarna_sdk: Option<KlarnaSdkPaymentMethodResponse>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct WalletResponse {
|
||||
#[serde(flatten)]
|
||||
details: Option<WalletResponseData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum WalletResponseData {
|
||||
#[schema(value_type = WalletAdditionalDataForCard)]
|
||||
ApplePay(Box<additional_info::WalletAdditionalDataForCard>),
|
||||
#[schema(value_type = WalletAdditionalDataForCard)]
|
||||
GooglePay(Box<additional_info::WalletAdditionalDataForCard>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
|
||||
pub struct KlarnaSdkPaymentMethodResponse {
|
||||
@ -4422,7 +4438,33 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
|
||||
Some(sdk) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))),
|
||||
None => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None })),
|
||||
},
|
||||
AdditionalPaymentData::Wallet { .. } => Self::Wallet {},
|
||||
AdditionalPaymentData::Wallet {
|
||||
apple_pay,
|
||||
google_pay,
|
||||
} => match (apple_pay, google_pay) {
|
||||
(Some(apple_pay_pm), _) => Self::Wallet(Box::new(WalletResponse {
|
||||
details: Some(WalletResponseData::ApplePay(Box::new(
|
||||
additional_info::WalletAdditionalDataForCard {
|
||||
last4: apple_pay_pm
|
||||
.display_name
|
||||
.clone()
|
||||
.chars()
|
||||
.rev()
|
||||
.take(4)
|
||||
.collect::<String>()
|
||||
.chars()
|
||||
.rev()
|
||||
.collect::<String>(),
|
||||
card_network: apple_pay_pm.network.clone(),
|
||||
card_type: apple_pay_pm.pm_type.clone(),
|
||||
},
|
||||
))),
|
||||
})),
|
||||
(_, Some(google_pay_pm)) => Self::Wallet(Box::new(WalletResponse {
|
||||
details: Some(WalletResponseData::GooglePay(Box::new(google_pay_pm))),
|
||||
})),
|
||||
_ => Self::Wallet(Box::new(WalletResponse { details: None })),
|
||||
},
|
||||
AdditionalPaymentData::BankRedirect { bank_name, details } => {
|
||||
Self::BankRedirect(Box::new(BankRedirectResponse { bank_name, details }))
|
||||
}
|
||||
|
||||
@ -205,9 +205,19 @@ pub enum UpiAdditionalData {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct UpiCollectAdditionalData {
|
||||
/// Masked VPA ID
|
||||
#[schema(value_type = Option<String>, example = "ab********@okhdfcbank")]
|
||||
pub vpa_id: Option<MaskedUpiVpaId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
pub struct WalletAdditionalDataForCard {
|
||||
/// Last 4 digits of the card number
|
||||
pub last4: String,
|
||||
/// The information of the payment method
|
||||
pub card_network: String,
|
||||
/// The type of payment method
|
||||
#[serde(rename = "type")]
|
||||
pub card_type: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user