refactor(router): restructure Samsung Pay connector wallet details (#6089)

This commit is contained in:
Shankar Singh C
2024-09-26 22:01:24 +05:30
committed by GitHub
parent 0add20930e
commit cfcf9187b9
2 changed files with 38 additions and 9 deletions

View File

@ -4922,19 +4922,36 @@ pub struct GpaySessionTokenData {
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SamsungPaySessionTokenData {
#[serde(rename = "samsung_pay")]
pub data: SamsungPayMetadata,
#[serde(rename_all = "snake_case")]
pub enum SamsungPayCombinedMetadata {
// This is to support the Samsung Pay decryption flow with application credentials,
// where the private key, certificates, or any other information required for decryption
// will be obtained from the environment variables.
ApplicationCredentials(SamsungPayApplicationCredentials),
MerchantCredentials(SamsungPayMerchantCredentials),
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SamsungPayMetadata {
pub struct SamsungPaySessionTokenData {
#[serde(rename = "samsung_pay")]
pub data: SamsungPayCombinedMetadata,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SamsungPayMerchantCredentials {
pub service_id: String,
pub merchant_display_name: String,
pub merchant_business_country: api_enums::CountryAlpha2,
pub allowed_brands: Vec<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SamsungPayApplicationCredentials {
pub merchant_display_name: String,
pub merchant_business_country: api_enums::CountryAlpha2,
pub allowed_brands: Vec<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PaypalSdkMetaData {
pub client_id: String,

View File

@ -502,7 +502,7 @@ fn create_samsung_pay_session_token(
router_data: &types::PaymentsSessionRouterData,
header_payload: api_models::payments::HeaderPayload,
) -> RouterResult<types::PaymentsSessionRouterData> {
let samsung_pay_wallet_details = router_data
let samsung_pay_session_token_data = router_data
.connector_wallets_details
.clone()
.parse_value::<payment_types::SamsungPaySessionTokenData>("SamsungPaySessionTokenData")
@ -527,18 +527,30 @@ fn create_samsung_pay_session_token(
.get_required_value("samsung pay domain")
.attach_printable("Failed to get domain for samsung pay session call")?;
let samsung_pay_wallet_details = match samsung_pay_session_token_data.data {
payment_types::SamsungPayCombinedMetadata::MerchantCredentials(
samsung_pay_merchant_credentials,
) => samsung_pay_merchant_credentials,
payment_types::SamsungPayCombinedMetadata::ApplicationCredentials(
_samsung_pay_application_credentials,
) => Err(errors::ApiErrorResponse::NotSupported {
message: "Samsung Pay decryption flow with application credentials is not implemented"
.to_owned(),
})?,
};
Ok(types::PaymentsSessionRouterData {
response: Ok(types::PaymentsResponseData::SessionResponse {
session_token: payment_types::SessionToken::SamsungPay(Box::new(
payment_types::SamsungPaySessionTokenResponse {
version: "2".to_string(),
service_id: samsung_pay_wallet_details.data.service_id,
service_id: samsung_pay_wallet_details.service_id,
order_number: router_data.payment_id.clone(),
merchant_payment_information:
payment_types::SamsungPayMerchantPaymentInformation {
name: samsung_pay_wallet_details.data.merchant_display_name,
name: samsung_pay_wallet_details.merchant_display_name,
url: merchant_domain,
country_code: samsung_pay_wallet_details.data.merchant_business_country,
country_code: samsung_pay_wallet_details.merchant_business_country,
},
amount: payment_types::SamsungPayAmountDetails {
amount_format: payment_types::SamsungPayAmountFormat::FormatTotalPriceOnly,
@ -546,7 +558,7 @@ fn create_samsung_pay_session_token(
total_amount: samsung_pay_amount,
},
protocol: payment_types::SamsungPayProtocolType::Protocol3ds,
allowed_brands: samsung_pay_wallet_details.data.allowed_brands,
allowed_brands: samsung_pay_wallet_details.allowed_brands,
},
)),
}),