Skip to content

Commit

Permalink
fix(payment_methods): log and ignore the apple pay metadata parsing e…
Browse files Browse the repository at this point in the history
…rror while fetching apple pay retry connectors (#4747)
  • Loading branch information
ShankarSinghC committed May 24, 2024
1 parent ff5bba5 commit a7fc4c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
6 changes: 6 additions & 0 deletions crates/router/src/core/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3163,8 +3163,14 @@ where
routing_data.business_sub_label = choice.sub_label.clone();
}

#[cfg(feature = "retry")]
let should_do_retry =
retry::config_should_call_gsm(&*state.store, &merchant_account.merchant_id).await;

#[cfg(feature = "retry")]
if payment_data.payment_attempt.payment_method_type
== Some(storage_enums::PaymentMethodType::ApplePay)
&& should_do_retry
{
let retryable_connector_data = helpers::get_apple_pay_retryable_connectors(
state,
Expand Down
50 changes: 33 additions & 17 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3890,18 +3890,27 @@ pub fn validate_customer_access(

pub fn is_apple_pay_simplified_flow(
connector_metadata: Option<pii::SecretSerdeValue>,
connector_name: Option<&String>,
) -> CustomResult<bool, errors::ApiErrorResponse> {
let apple_pay_metadata = get_applepay_metadata(connector_metadata)?;

Ok(match apple_pay_metadata {
api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined(
apple_pay_combined_metadata,
) => match apple_pay_combined_metadata {
api_models::payments::ApplePayCombinedMetadata::Simplified { .. } => true,
api_models::payments::ApplePayCombinedMetadata::Manual { .. } => false,
},
api_models::payments::ApplepaySessionTokenMetadata::ApplePay(_) => false,
})
let option_apple_pay_metadata = get_applepay_metadata(connector_metadata)
.map_err(|error| {
logger::info!(
"Apple pay metadata parsing for {:?} in is_apple_pay_simplified_flow {:?}",
connector_name,
error
)
})
.ok();

// return true only if the apple flow type is simplified
Ok(matches!(
option_apple_pay_metadata,
Some(
api_models::payments::ApplepaySessionTokenMetadata::ApplePayCombined(
api_models::payments::ApplePayCombinedMetadata::Simplified { .. }
)
)
))
}

pub fn get_applepay_metadata(
Expand Down Expand Up @@ -3954,7 +3963,7 @@ where
field_name: "profile_id",
})?;

let merchant_connector_account = get_merchant_connector_account(
let merchant_connector_account_type = get_merchant_connector_account(
&state,
merchant_account.merchant_id.as_str(),
payment_data.creds_identifier.to_owned(),
Expand All @@ -3963,15 +3972,19 @@ where
&decided_connector_data.connector_name.to_string(),
merchant_connector_id,
)
.await?
.get_metadata();
.await?;

let connector_data_list = if is_apple_pay_simplified_flow(merchant_connector_account)? {
let connector_data_list = if is_apple_pay_simplified_flow(
merchant_connector_account_type.get_metadata(),
merchant_connector_account_type
.get_connector_name()
.as_ref(),
)? {
let merchant_connector_account_list = state
.store
.find_merchant_connector_account_by_merchant_id_and_disabled_list(
merchant_account.merchant_id.as_str(),
true,
false,
key_store,
)
.await
Expand All @@ -3980,7 +3993,10 @@ where
let mut connector_data_list = vec![decided_connector_data.clone()];

for merchant_connector_account in merchant_connector_account_list {
if is_apple_pay_simplified_flow(merchant_connector_account.metadata)? {
if is_apple_pay_simplified_flow(
merchant_connector_account.metadata,
Some(&merchant_connector_account.connector_name),
)? {
let connector_data = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
&merchant_connector_account.connector_name.to_string(),
Expand Down

0 comments on commit a7fc4c6

Please sign in to comment.