Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(samsung_pay): populate payment_method_data in the payment response #7095

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
}
}
}
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
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
Loading