Skip to content

Commit

Permalink
fix(samsung_pay): populate payment_method_data in the payment respo…
Browse files Browse the repository at this point in the history
…nse (#7095)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
ShankarSinghC and hyperswitch-bot[bot] authored Feb 3, 2025
1 parent ae39374 commit 04a5e38
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 17 deletions.
17 changes: 14 additions & 3 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21493,8 +21493,7 @@
"type": "object",
"required": [
"last4",
"card_network",
"type"
"card_network"
],
"properties": {
"last4": {
Expand All @@ -21507,7 +21506,8 @@
},
"type": {
"type": "string",
"description": "The type of payment method"
"description": "The type of payment method",
"nullable": true
}
}
},
Expand Down Expand Up @@ -21864,6 +21864,17 @@
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
},
{
"type": "object",
"required": [
"samsung_pay"
],
"properties": {
"samsung_pay": {
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
}
],
"description": "Hyperswitch supports SDK integration with Apple Pay and Google Pay wallets. For other wallets, we integrate with their respective connectors, redirecting the customer to the connector for wallet payments. As a result, we don’t receive any payment method data in the confirm call for payments made through other wallets."
Expand Down
17 changes: 14 additions & 3 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -26102,8 +26102,7 @@
"type": "object",
"required": [
"last4",
"card_network",
"type"
"card_network"
],
"properties": {
"last4": {
Expand All @@ -26116,7 +26115,8 @@
},
"type": {
"type": "string",
"description": "The type of payment method"
"description": "The type of payment method",
"nullable": true
}
}
},
Expand Down Expand Up @@ -26473,6 +26473,17 @@
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
},
{
"type": "object",
"required": [
"samsung_pay"
],
"properties": {
"samsung_pay": {
"$ref": "#/components/schemas/WalletAdditionalDataForCard"
}
}
}
],
"description": "Hyperswitch supports SDK integration with Apple Pay and Google Pay wallets. For other wallets, we integrate with their respective connectors, redirecting the customer to the connector for wallet payments. As a result, we don’t receive any payment method data in the confirm call for payments made through other wallets."
Expand Down
2 changes: 1 addition & 1 deletion crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ pub struct PaymentMethodDataWalletInfo {
pub card_network: String,
/// The type of payment method
#[serde(rename = "type")]
pub card_type: String,
pub card_type: Option<String>,
}

impl From<payments::additional_info::WalletAdditionalDataForCard> for PaymentMethodDataWalletInfo {
Expand Down
15 changes: 11 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,7 @@ pub enum AdditionalPaymentData {
Wallet {
apple_pay: Option<ApplepayPaymentMethod>,
google_pay: Option<additional_info::WalletAdditionalDataForCard>,
samsung_pay: Option<additional_info::WalletAdditionalDataForCard>,
},
PayLater {
klarna_sdk: Option<KlarnaSdkPaymentMethod>,
Expand Down Expand Up @@ -3874,6 +3875,8 @@ pub enum WalletResponseData {
ApplePay(Box<additional_info::WalletAdditionalDataForCard>),
#[schema(value_type = WalletAdditionalDataForCard)]
GooglePay(Box<additional_info::WalletAdditionalDataForCard>),
#[schema(value_type = WalletAdditionalDataForCard)]
SamsungPay(Box<additional_info::WalletAdditionalDataForCard>),
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -5410,8 +5413,9 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
AdditionalPaymentData::Wallet {
apple_pay,
google_pay,
} => match (apple_pay, google_pay) {
(Some(apple_pay_pm), _) => Self::Wallet(Box::new(WalletResponse {
samsung_pay,
} => match (apple_pay, google_pay, samsung_pay) {
(Some(apple_pay_pm), _, _) => Self::Wallet(Box::new(WalletResponse {
details: Some(WalletResponseData::ApplePay(Box::new(
additional_info::WalletAdditionalDataForCard {
last4: apple_pay_pm
Expand All @@ -5425,13 +5429,16 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
.rev()
.collect::<String>(),
card_network: apple_pay_pm.network.clone(),
card_type: apple_pay_pm.pm_type.clone(),
card_type: Some(apple_pay_pm.pm_type.clone()),
},
))),
})),
(_, Some(google_pay_pm)) => Self::Wallet(Box::new(WalletResponse {
(_, Some(google_pay_pm), _) => Self::Wallet(Box::new(WalletResponse {
details: Some(WalletResponseData::GooglePay(Box::new(google_pay_pm))),
})),
(_, _, Some(samsung_pay_pm)) => Self::Wallet(Box::new(WalletResponse {
details: Some(WalletResponseData::SamsungPay(Box::new(samsung_pay_pm))),
})),
_ => Self::Wallet(Box::new(WalletResponse { details: None })),
},
AdditionalPaymentData::BankRedirect { bank_name, details } => {
Expand Down
2 changes: 1 addition & 1 deletion crates/api_models/src/payments/additional_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,5 @@ pub struct WalletAdditionalDataForCard {
pub card_network: String,
/// The type of payment method
#[serde(rename = "type")]
pub card_type: String,
pub card_type: Option<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ impl From<GooglePayWalletData> for payment_methods::PaymentMethodDataWalletInfo
Self {
last4: item.info.card_details,
card_network: item.info.card_network,
card_type: item.pm_type,
card_type: Some(item.pm_type),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,15 @@ where
connector: router_data.connector,
payment_id: router_data.payment_id.clone(),
attempt_id: router_data.attempt_id,
request: FrmRequest::Checkout(FraudCheckCheckoutData {
request: FrmRequest::Checkout(Box::new(FraudCheckCheckoutData {
amount: router_data.request.amount,
order_details: router_data.request.order_details,
currency: router_data.request.currency,
browser_info: router_data.request.browser_info,
payment_method_data: router_data.request.payment_method_data,
email: router_data.request.email,
gateway: router_data.request.gateway,
}),
})),
response: FrmResponse::Checkout(router_data.response),
})
}
Expand Down
22 changes: 21 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4671,6 +4671,7 @@ pub async fn get_additional_payment_data(
pm_type: apple_pay_wallet_data.payment_method.pm_type.clone(),
}),
google_pay: None,
samsung_pay: None,
}))
}
domain::WalletData::GooglePay(google_pay_pm_data) => {
Expand All @@ -4679,13 +4680,32 @@ pub async fn get_additional_payment_data(
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(),
card_type: Some(google_pay_pm_data.pm_type.clone()),
}),
samsung_pay: None,
}))
}
domain::WalletData::SamsungPay(samsung_pay_pm_data) => {
Ok(Some(api_models::payments::AdditionalPaymentData::Wallet {
apple_pay: None,
google_pay: None,
samsung_pay: Some(payment_additional_types::WalletAdditionalDataForCard {
last4: samsung_pay_pm_data
.payment_credential
.card_last_four_digits
.clone(),
card_network: samsung_pay_pm_data
.payment_credential
.card_brand
.to_string(),
card_type: None,
}),
}))
}
_ => Ok(Some(api_models::payments::AdditionalPaymentData::Wallet {
apple_pay: None,
google_pay: None,
samsung_pay: None,
})),
},
domain::PaymentMethodData::PayLater(_) => Ok(Some(
Expand Down
8 changes: 8 additions & 0 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,14 @@ impl PaymentCreate {
Some(api_models::payments::AdditionalPaymentData::Wallet {
apple_pay: None,
google_pay: Some(wallet.into()),
samsung_pay: None,
})
}
Some(enums::PaymentMethodType::SamsungPay) => {
Some(api_models::payments::AdditionalPaymentData::Wallet {
apple_pay: None,
google_pay: None,
samsung_pay: Some(wallet.into()),
})
}
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/types/fraud_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct FrmRouterData {
#[derive(Debug, Clone)]
pub enum FrmRequest {
Sale(FraudCheckSaleData),
Checkout(FraudCheckCheckoutData),
Checkout(Box<FraudCheckCheckoutData>),
Transaction(FraudCheckTransactionData),
Fulfillment(FraudCheckFulfillmentData),
RecordReturn(FraudCheckRecordReturnData),
Expand Down

0 comments on commit 04a5e38

Please sign in to comment.