From ef1efe48afd647abdaa267d5e2cdf6e27e0569cd Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Fri, 29 Sep 2023 16:13:22 +0530 Subject: [PATCH 1/2] desrialize apple_pay and apple_pay_combaioned separatly --- crates/api_models/src/payments.rs | 8 +++- .../src/connector/bluesnap/transformers.rs | 46 ++++++++++++++++--- crates/router/src/core/payments.rs | 28 +++++++++-- .../src/core/payments/flows/session_flow.rs | 25 ++++++++-- 4 files changed, 93 insertions(+), 14 deletions(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 6a06b76d0e47..6711f202e976 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -2375,8 +2375,12 @@ pub struct ApplepayConnectorMetadataRequest { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ApplepaySessionTokenData { - #[serde(flatten)] - pub data: ApplepaySessionTokenMetadata, + pub apple_pay: ApplePayMetadata, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct ApplepayCombinedSessionTokenData { + pub apple_pay_combined: ApplePayCombinedMetadata, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] diff --git a/crates/router/src/connector/bluesnap/transformers.rs b/crates/router/src/connector/bluesnap/transformers.rs index fc9238f84e87..fe92c337a012 100644 --- a/crates/router/src/connector/bluesnap/transformers.rs +++ b/crates/router/src/connector/bluesnap/transformers.rs @@ -423,11 +423,28 @@ impl TryFrom<&types::PaymentsSessionRouterData> for BluesnapCreateWalletToken { fn try_from(item: &types::PaymentsSessionRouterData) -> Result { let apple_pay_metadata = item.get_connector_meta()?.expose(); let applepay_metadata = apple_pay_metadata - .parse_value::( - "ApplepaySessionTokenData", + .clone() + .parse_value::( + "ApplepayCombinedSessionTokenData", ) + .map(|combined_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined( + combined_metadata.apple_pay_combined, + ) + }) + .or_else(|_| { + apple_pay_metadata + .parse_value::( + "ApplepaySessionTokenData", + ) + .map(|old_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePay( + old_metadata.apple_pay, + ) + }) + }) .change_context(errors::ConnectorError::ParsingFailed)?; - let session_token_data = match applepay_metadata.data { + let session_token_data = match applepay_metadata { payments::ApplepaySessionTokenMetadata::ApplePay(apple_pay_data) => { Ok(apple_pay_data.session_token_data) } @@ -468,12 +485,29 @@ impl TryFrom( - "ApplepaySessionTokenData", + .clone() + .parse_value::( + "ApplepayCombinedSessionTokenData", ) + .map(|combined_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined( + combined_metadata.apple_pay_combined, + ) + }) + .or_else(|_| { + metadata + .parse_value::( + "ApplepaySessionTokenData", + ) + .map(|old_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePay( + old_metadata.apple_pay, + ) + }) + }) .change_context(errors::ConnectorError::ParsingFailed)?; - let (payment_request_data, session_token_data) = match applepay_metadata.data { + let (payment_request_data, session_token_data) = match applepay_metadata { payments::ApplepaySessionTokenMetadata::ApplePayCombined(_apple_pay_combined) => { Err(errors::ConnectorError::FlowNotSupported { flow: "apple pay combined".to_string(), diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 170a780e701d..cb2b24c4158c 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -1127,10 +1127,32 @@ fn check_apple_pay_metadata( merchant_connector_account.clone().and_then(|mca| { let metadata = mca.get_metadata(); metadata.and_then(|apple_pay_metadata| { - let parsed_metadata: Result = - apple_pay_metadata.parse_value("ApplepaySessionTokenData").map_err(|error| logger::error!(%error, "Failed to Parse Value to ApplepaySessionTokenData")); + let parsed_metadata = apple_pay_metadata + .clone() + .parse_value::( + "ApplepayCombinedSessionTokenData", + ) + .map(|combined_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined( + combined_metadata.apple_pay_combined, + ) + }) + .or_else(|_| { + apple_pay_metadata + .parse_value::( + "ApplepaySessionTokenData", + ) + .map(|old_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePay( + old_metadata.apple_pay, + ) + }) + }) + .map_err( + |error| logger::error!(%error, "Failed to Parse Value to ApplepaySessionTokenData"), + ); - parsed_metadata.ok().map(|metadata| match metadata.data { + parsed_metadata.ok().map(|metadata| match metadata { api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined( apple_pay_combined, ) => match apple_pay_combined { diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs index 8b8ae990c0ad..a6ae83ac1572 100644 --- a/crates/router/src/core/payments/flows/session_flow.rs +++ b/crates/router/src/core/payments/flows/session_flow.rs @@ -87,9 +87,28 @@ impl Feature for types::PaymentsSessio fn get_applepay_metadata( connector_metadata: Option, -) -> RouterResult { +) -> RouterResult { connector_metadata - .parse_value::("ApplepaySessionTokenData") + .clone() + .parse_value::( + "ApplepayCombinedSessionTokenData", + ) + .map(|combined_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined( + combined_metadata.apple_pay_combined, + ) + }) + .or_else(|_| { + connector_metadata + .parse_value::( + "ApplepaySessionTokenData", + ) + .map(|old_metadata| { + api_models::payments::ApplepaySessionTokenMetadata::ApplePay( + old_metadata.apple_pay, + ) + }) + }) .change_context(errors::ApiErrorResponse::InvalidDataFormat { field_name: "connector_metadata".to_string(), expected_format: "applepay_metadata_format".to_string(), @@ -154,7 +173,7 @@ async fn create_applepay_session_token( apple_pay_session_request, apple_pay_merchant_cert, apple_pay_merchant_cert_key, - ) = match apple_pay_metadata.data { + ) = match apple_pay_metadata { payment_types::ApplepaySessionTokenMetadata::ApplePayCombined( apple_pay_combined_metadata, ) => match apple_pay_combined_metadata { From 11e6612504a92aca9a23ffbb5a36a5ced3e22a2d Mon Sep 17 00:00:00 2001 From: Shankar Singh C Date: Tue, 3 Oct 2023 10:35:00 +0530 Subject: [PATCH 2/2] fix typo --- crates/router/tests/connectors/authorizedotnet.rs | 14 +++++++------- crates/router/tests/connectors/cybersource.rs | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/router/tests/connectors/authorizedotnet.rs b/crates/router/tests/connectors/authorizedotnet.rs index 125851d0bea1..4750e122a217 100644 --- a/crates/router/tests/connectors/authorizedotnet.rs +++ b/crates/router/tests/connectors/authorizedotnet.rs @@ -512,31 +512,31 @@ async fn should_fail_capture_for_invalid_payment() { } #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_partially_refund_manually_captured_payment() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_refund_manually_captured_payment() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_sync_manually_captured_refund() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_refund_auto_captured_payment() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_partially_refund_succeeded_payment() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_refund_succeeded_payment_multiple_times() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_fail_for_refund_amount_higher_than_payment_amount() {} // Connector dependent test cases goes here diff --git a/crates/router/tests/connectors/cybersource.rs b/crates/router/tests/connectors/cybersource.rs index bcc5aaa2a209..5f9adf39f9b9 100644 --- a/crates/router/tests/connectors/cybersource.rs +++ b/crates/router/tests/connectors/cybersource.rs @@ -314,7 +314,7 @@ async fn should_partially_refund_succeeded_payment() { } #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_partially_refund_manually_captured_payment() { let connector = Cybersource {}; let response = connector @@ -373,17 +373,17 @@ async fn should_sync_refund() { } #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_sync_manually_captured_refund() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_refund_auto_captured_payment() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_refund_succeeded_payment_multiple_times() {} #[actix_web::test] -#[ignore = "refunds tests are ignored for this connector becuase it takes one day for a payment to be settled."] +#[ignore = "refunds tests are ignored for this connector because it takes one day for a payment to be settled."] async fn should_fail_for_refund_amount_higher_than_payment_amount() {}