diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 93fa3ed44b81..d8959dac0e2a 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -778,37 +778,18 @@ where .as_ref() .map(ToString::to_string) .unwrap_or("".to_owned()); - let additional_payment_method_data: Option = - match payment_data.get_payment_method_data(){ - Some(payment_method_data) => match payment_method_data{ - hyperswitch_domain_models::payment_method_data::PaymentMethodData::Card(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardRedirect(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::Wallet(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::PayLater(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankRedirect(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankDebit(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::BankTransfer(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::Crypto(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::MandatePayment | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::Reward | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::RealTimePayment(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::Upi(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::Voucher(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::GiftCard(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::CardToken(_) | - hyperswitch_domain_models::payment_method_data::PaymentMethodData::OpenBanking(_) => {payment_attempt - .payment_method_data - .clone() - .map(|data| data.parse_value("payment_method_data")) - .transpose() - .change_context(errors::ApiErrorResponse::InvalidDataValue { - field_name: "payment_method_data", - })?}, - hyperswitch_domain_models::payment_method_data::PaymentMethodData::NetworkToken(_) => None, - } - None => None - }; + let additional_payment_method_data: Option = + payment_attempt + .payment_method_data + .clone() + .and_then(|data| match data { + serde_json::Value::Null => None, // This is to handle the case when the payment_method_data is null + _ => Some(data.parse_value("AdditionalPaymentData")), + }) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to parse the AdditionalPaymentData from payment_attempt.payment_method_data")?; let surcharge_details = payment_attempt