Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(connector): [Worldpayxml] correctly map authenticate_shopper_id and scheme transaction id (#11483)

Mrudul Vajpayee8ad2cf459a0d
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index 253ec2ae31..eb9e436f54 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -339,6 +339,7 @@ pub struct PaymentsMandateReferenceRecord {
pub original_payment_authorized_amount: Option<i64>,
pub original_payment_authorized_currency: Option<common_enums::Currency>,
pub connector_customer_id: Option<String>,
+ pub connector_mandate_request_reference_id: Option<String>,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
@@ -3281,6 +3282,7 @@ pub struct PaymentMethodRecord {
pub nick_name: Option<masking::Secret<String>>,
pub payment_instrument_id: Option<masking::Secret<String>>,
pub connector_customer_id: Option<String>,
+ pub connector_mandate_request_reference_id: Option<String>,
// Card fields are optional to support non-card CSV rows (e.g., ACH bank debit).
// For card rows these will still be populated normally from the CSV columns.
#[serde(default)]
@@ -3589,7 +3591,10 @@ impl
original_payment_authorized_amount: record.original_transaction_amount,
original_payment_authorized_currency: record
.original_transaction_currency,
- connector_customer_id: record.connector_customer_id.clone(),
+ connector_customer_id: None,
+ connector_mandate_request_reference_id: record
+ .connector_mandate_request_reference_id
+ .clone(),
},
)
})
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs b/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs
index 3c4e5c99e7..f3849f02ba 100644
--- a/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs
+++ b/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs
@@ -1452,4 +1452,14 @@ impl ConnectorSpecifications for Worldpayxml {
fn get_supported_webhook_flows(&self) -> Option<&'static [common_enums::EventClass]> {
Some(WORLDPAYXML_SUPPORTED_WEBHOOK_FLOWS)
}
+
+ fn generate_connector_customer_id(
+ &self,
+ customer_id: &Option<common_utils::id_type::CustomerId>,
+ _merchant_id: &common_utils::id_type::MerchantId,
+ ) -> Option<String> {
+ customer_id
+ .as_ref()
+ .map(|cid| cid.get_string_repr().to_string())
+ }
}
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs
index f132fad9fb..ea74e319c9 100644
--- a/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs
@@ -35,7 +35,7 @@ use hyperswitch_domain_models::{
};
use hyperswitch_interfaces::{consts, errors};
use josekit;
-use masking::{ExposeInterface, Secret, WithType};
+use masking::{ExposeInterface, Secret};
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
@@ -931,43 +931,17 @@ fn get_shopper_details(
time_zone: browser_info.time_zone,
});
- let authenticated_shopper_i_d =
- if item.request.payment_method_data == PaymentMethodData::MandatePayment {
- let mandate_data = item.request.get_connector_mandate_data().ok_or(
- errors::ConnectorError::MissingRequiredField {
- field_name: "mandate_data",
- },
- )?;
-
- let metadata = mandate_data.get_mandate_metadata().ok_or_else(|| {
- errors::ConnectorError::MissingRequiredField {
- field_name: "mandate_metadata",
- }
- })?;
-
- let customer_id = metadata
- .expose()
- .get("customer_id")
- .and_then(|v| v.as_str())
- .ok_or_else(|| errors::ConnectorError::MissingRequiredField {
- field_name: "customer_id in metadata",
- })?
- .to_owned();
-
- Some(Secret::new(customer_id))
- } else {
- item.request
- .is_cit_mandate_payment()
- .then(|| {
- item.get_customer_id()
- .change_context(errors::ConnectorError::MissingRequiredField {
- field_name: "customer_id for authenticatedShopperID",
- })
- .map(|cid| cid.get_string_repr().to_owned())
- .map(Secret::new)
- })
- .transpose()?
- };
+ let authenticated_shopper_i_d = match item.get_connector_customer_id().ok() {
+ Some(id) => Some(Secret::new(id)),
+ None if item.request.payment_method_data == PaymentMethodData::MandatePayment
+ || item.request.is_cit_mandate_payment() =>
+ {
+ Err(errors::ConnectorError::MissingRequiredField {
+ field_name: "connector_customer_id",
+ })?
+ }
+ None => None,
+ };
if shopper_email.is_some() || browser_info.is_some() || authenticated_shopper_i_d.is_some() {
Ok(Some(WorldpayxmlShopper {
@@ -2832,15 +2806,10 @@ fn process_payment_response(
connector_metadata: None,
}))
} else {
- let mandate_metadata: Option<Secret<Value, WithType>> = token
- .as_ref()
- .map(|token| &token.authenticated_shopper_i_d)
- .map(|customer_id| Secret::new(json!({ "customer_id": customer_id })));
-
let mandate_reference = token.map(|token| MandateReference {
connector_mandate_id: Some(token.token_details.payment_token_i_d.expose()),
payment_method_id: None,
- mandate_metadata,
+ mandate_metadata: None,
connector_mandate_request_reference_id: payment_data
.scheme_response
.as_ref()