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:
Kashif
2024-09-19 18:54:56 +05:30
committed by GitHub
parent 82574c0e8e
commit 8320dc07fe
7 changed files with 205 additions and 7 deletions

View File

@ -11912,7 +11912,7 @@
], ],
"properties": { "properties": {
"wallet": { "wallet": {
"type": "object" "$ref": "#/components/schemas/WalletResponse"
} }
} }
}, },
@ -19124,6 +19124,28 @@
} }
] ]
}, },
"WalletAdditionalDataForCard": {
"type": "object",
"required": [
"last4",
"card_network",
"type"
],
"properties": {
"last4": {
"type": "string",
"description": "Last 4 digits of the card number"
},
"card_network": {
"type": "string",
"description": "The information of the payment method"
},
"type": {
"type": "string",
"description": "The type of payment method"
}
}
},
"WalletData": { "WalletData": {
"oneOf": [ "oneOf": [
{ {
@ -19428,6 +19450,47 @@
} }
] ]
}, },
"WalletResponse": {
"allOf": [
{
"allOf": [
{
"$ref": "#/components/schemas/WalletResponseData"
}
],
"nullable": true
},
{
"type": "object"
}
]
},
"WalletResponseData": {
"oneOf": [
{
"type": "object",
"required": [
"apple_pay"
],
"properties": {
"apple_pay": {
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
},
{
"type": "object",
"required": [
"google_pay"
],
"properties": {
"google_pay": {
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
}
]
},
"WeChatPay": { "WeChatPay": {
"type": "object" "type": "object"
}, },

View File

@ -15726,7 +15726,7 @@
], ],
"properties": { "properties": {
"wallet": { "wallet": {
"type": "object" "$ref": "#/components/schemas/WalletResponse"
} }
} }
}, },
@ -23465,6 +23465,28 @@
} }
] ]
}, },
"WalletAdditionalDataForCard": {
"type": "object",
"required": [
"last4",
"card_network",
"type"
],
"properties": {
"last4": {
"type": "string",
"description": "Last 4 digits of the card number"
},
"card_network": {
"type": "string",
"description": "The information of the payment method"
},
"type": {
"type": "string",
"description": "The type of payment method"
}
}
},
"WalletData": { "WalletData": {
"oneOf": [ "oneOf": [
{ {
@ -23769,6 +23791,47 @@
} }
] ]
}, },
"WalletResponse": {
"allOf": [
{
"allOf": [
{
"$ref": "#/components/schemas/WalletResponseData"
}
],
"nullable": true
},
{
"type": "object"
}
]
},
"WalletResponseData": {
"oneOf": [
{
"type": "object",
"required": [
"apple_pay"
],
"properties": {
"apple_pay": {
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
},
{
"type": "object",
"required": [
"google_pay"
],
"properties": {
"google_pay": {
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
}
]
},
"WeChatPay": { "WeChatPay": {
"type": "object" "type": "object"
}, },

View File

@ -2046,6 +2046,7 @@ pub enum AdditionalPaymentData {
}, },
Wallet { Wallet {
apple_pay: Option<ApplepayPaymentMethod>, apple_pay: Option<ApplepayPaymentMethod>,
google_pay: Option<additional_info::WalletAdditionalDataForCard>,
}, },
PayLater { PayLater {
klarna_sdk: Option<KlarnaSdkPaymentMethod>, klarna_sdk: Option<KlarnaSdkPaymentMethod>,
@ -3069,7 +3070,7 @@ where
| PaymentMethodDataResponse::PayLater(_) | PaymentMethodDataResponse::PayLater(_)
| PaymentMethodDataResponse::RealTimePayment(_) | PaymentMethodDataResponse::RealTimePayment(_)
| PaymentMethodDataResponse::Upi(_) | PaymentMethodDataResponse::Upi(_)
| PaymentMethodDataResponse::Wallet {} | PaymentMethodDataResponse::Wallet(_)
| PaymentMethodDataResponse::BankTransfer(_) | PaymentMethodDataResponse::BankTransfer(_)
| PaymentMethodDataResponse::OpenBanking(_) | PaymentMethodDataResponse::OpenBanking(_)
| PaymentMethodDataResponse::Voucher(_) => { | PaymentMethodDataResponse::Voucher(_) => {
@ -3090,7 +3091,7 @@ where
pub enum PaymentMethodDataResponse { pub enum PaymentMethodDataResponse {
Card(Box<CardResponse>), Card(Box<CardResponse>),
BankTransfer(Box<BankTransferResponse>), BankTransfer(Box<BankTransferResponse>),
Wallet {}, Wallet(Box<WalletResponse>),
PayLater(Box<PaylaterResponse>), PayLater(Box<PaylaterResponse>),
BankRedirect(Box<BankRedirectResponse>), BankRedirect(Box<BankRedirectResponse>),
Crypto(Box<CryptoResponse>), Crypto(Box<CryptoResponse>),
@ -3187,6 +3188,21 @@ pub struct PaylaterResponse {
klarna_sdk: Option<KlarnaSdkPaymentMethodResponse>, 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)] #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct KlarnaSdkPaymentMethodResponse { pub struct KlarnaSdkPaymentMethodResponse {
@ -4422,7 +4438,33 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
Some(sdk) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))), Some(sdk) => Self::PayLater(Box::new(PaylaterResponse::from(sdk))),
None => Self::PayLater(Box::new(PaylaterResponse { klarna_sdk: None })), 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 } => { AdditionalPaymentData::BankRedirect { bank_name, details } => {
Self::BankRedirect(Box::new(BankRedirectResponse { bank_name, details })) Self::BankRedirect(Box::new(BankRedirectResponse { bank_name, details }))
} }

View File

@ -205,9 +205,19 @@ pub enum UpiAdditionalData {
} }
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)] #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct UpiCollectAdditionalData { pub struct UpiCollectAdditionalData {
/// Masked VPA ID /// Masked VPA ID
#[schema(value_type = Option<String>, example = "ab********@okhdfcbank")] #[schema(value_type = Option<String>, example = "ab********@okhdfcbank")]
pub vpa_id: Option<MaskedUpiVpaId>, 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,
}

View File

@ -613,7 +613,10 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::additional_info::GivexGiftCardAdditionalData, api_models::payments::additional_info::GivexGiftCardAdditionalData,
api_models::payments::additional_info::UpiAdditionalData, api_models::payments::additional_info::UpiAdditionalData,
api_models::payments::additional_info::UpiCollectAdditionalData, api_models::payments::additional_info::UpiCollectAdditionalData,
api_models::payments::additional_info::WalletAdditionalDataForCard,
api_models::payments::PaymentsDynamicTaxCalculationRequest, api_models::payments::PaymentsDynamicTaxCalculationRequest,
api_models::payments::WalletResponse,
api_models::payments::WalletResponseData,
api_models::payments::PaymentsDynamicTaxCalculationResponse, api_models::payments::PaymentsDynamicTaxCalculationResponse,
api_models::payments::DisplayAmountOnSdk, api_models::payments::DisplayAmountOnSdk,
)), )),

View File

@ -530,6 +530,9 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::additional_info::GivexGiftCardAdditionalData, api_models::payments::additional_info::GivexGiftCardAdditionalData,
api_models::payments::additional_info::UpiAdditionalData, api_models::payments::additional_info::UpiAdditionalData,
api_models::payments::additional_info::UpiCollectAdditionalData, api_models::payments::additional_info::UpiCollectAdditionalData,
api_models::payments::additional_info::WalletAdditionalDataForCard,
api_models::payments::WalletResponse,
api_models::payments::WalletResponseData,
api_models::payments::PaymentsDynamicTaxCalculationRequest, api_models::payments::PaymentsDynamicTaxCalculationRequest,
api_models::payments::PaymentsDynamicTaxCalculationResponse, api_models::payments::PaymentsDynamicTaxCalculationResponse,
api_models::payments::DisplayAmountOnSdk, api_models::payments::DisplayAmountOnSdk,

View File

@ -4261,9 +4261,23 @@ pub async fn get_additional_payment_data(
network: apple_pay_wallet_data.payment_method.network.clone(), network: apple_pay_wallet_data.payment_method.network.clone(),
pm_type: apple_pay_wallet_data.payment_method.pm_type.clone(), pm_type: apple_pay_wallet_data.payment_method.pm_type.clone(),
}), }),
google_pay: None,
}) })
} }
_ => Some(api_models::payments::AdditionalPaymentData::Wallet { apple_pay: None }), domain::WalletData::GooglePay(google_pay_pm_data) => {
Some(api_models::payments::AdditionalPaymentData::Wallet {
apple_pay: None,
google_pay: Some(payment_additional_types::WalletAdditionalDataForCard {
last4: google_pay_pm_data.info.card_details.clone(),
card_network: google_pay_pm_data.info.card_network.clone(),
card_type: google_pay_pm_data.pm_type.clone(),
}),
})
}
_ => Some(api_models::payments::AdditionalPaymentData::Wallet {
apple_pay: None,
google_pay: None,
}),
}, },
domain::PaymentMethodData::PayLater(_) => { domain::PaymentMethodData::PayLater(_) => {
Some(api_models::payments::AdditionalPaymentData::PayLater { klarna_sdk: None }) Some(api_models::payments::AdditionalPaymentData::PayLater { klarna_sdk: None })