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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(worldpayvantiv): extend PSP mandate to include NTID (#12275)
Siddhesh Kulthef87c970f005d
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rsindex df933c28d8..95b7b9207a 100644--- a/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs@@ -398,6 +398,36 @@ pub struct TokenizationData {exp_date: Secret<String>,}+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct WorldpayvantivMandateMetadata {+ pub network_transaction_id: Option<Secret<String>>,+}++impl WorldpayvantivMandateMetadata {+ fn create_mandate_reference(+ token_data: &TokenResponse,+ network_transaction_id: Option<Secret<String>>,+ ) -> Option<MandateReference> {+ let mandate_metadata = network_transaction_id.map(|ntid| {+ let metadata = Self {+ network_transaction_id: Some(ntid),+ };+ serde_json::to_value(&metadata)+ .ok()+ .map(pii::SecretSerdeValue::new)+ .unwrap_or_else(|| pii::SecretSerdeValue::new(serde_json::Value::Null))+ });++ Some(MandateReference {+ connector_mandate_id: Some(token_data.cnp_token.peek().clone()),+ payment_method_id: None,+ mandate_metadata,+ connector_mandate_request_reference_id: None,+ })+ }+}+#[derive(Debug)]struct VantivMandateDetail {processing_type: Option<VantivProcessingType>,@@ -1090,21 +1120,30 @@ fn get_processing_info(token: None,}),Some(api_models::payments::MandateReferenceId::ConnectorMandateId(mandate_data)) => {+ let network_transaction_id =+ mandate_data+ .get_mandate_metadata()+ .as_ref()+ .and_then(|metadata| {+ serde_json::from_value::<WorldpayvantivMandateMetadata>(+ metadata.peek().clone(),+ )+ .ok()+ .and_then(|meta| meta.network_transaction_id)+ });+let card_mandate_data = request.get_card_mandate_info()?;+ let exp_date = card_mandate_data.get_expiry_date_as_mmyy()?;+Ok(VantivMandateDetail {processing_type: None,- network_transaction_id: None,+ network_transaction_id,token: Some(TokenizationData {cnp_token: mandate_data.get_connector_mandate_id().ok_or(errors::ConnectorError::MissingConnectorMandateID)?.into(),- exp_date: format!(- "{}{}",- card_mandate_data.card_exp_month.peek(),- card_mandate_data.card_exp_year.peek()- )- .into(),+ exp_date,}),})}@@ -1948,14 +1987,24 @@ impl<F>} else {sale_response.token_response- .clone()- .map(MandateReference::from)+ .as_ref()+ .and_then(|token_data| {+ WorldpayvantivMandateMetadata::create_mandate_reference(+ token_data,+ sale_response.network_transaction_id.clone(),+ )+ })}}false => sale_response.token_response- .clone()- .map(MandateReference::from)+ .as_ref()+ .and_then(|token_data| {+ WorldpayvantivMandateMetadata::create_mandate_reference(+ token_data,+ sale_response.network_transaction_id.clone(),+ )+ })};@@ -2107,7 +2156,15 @@ impl<F>};let connector_metadata = Some(report_group.encode_to_value().change_context(errors::ConnectorError::ResponseHandlingFailed)?);- let mandate_reference_data = auth_response.token_response.clone().map(MandateReference::from);+ let mandate_reference_data = auth_response+ .token_response+ .as_ref()+ .and_then(|token_data| {+ WorldpayvantivMandateMetadata::create_mandate_reference(+ token_data,+ auth_response.network_transaction_id.clone(),+ )+ });let connector_response = auth_response.fraud_result.as_ref().map(get_connector_response);Ok(Self {@@ -2242,10 +2299,16 @@ impl<F>.encode_to_value().change_context(errors::ConnectorError::ResponseHandlingFailed)?,);- let mandate_reference_data = auth_response- .token_response- .clone()- .map(MandateReference::from);+ let mandate_reference_data =+ auth_response+ .token_response+ .as_ref()+ .and_then(|token_data| {+ WorldpayvantivMandateMetadata::create_mandate_reference(+ token_data,+ auth_response.network_transaction_id.clone(),+ )+ });let connector_response = auth_response.fraud_result.as_ref()diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex 3c7b1236f3..5c79c926bc 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -272,6 +272,24 @@ pub struct CardMandateInfo {pub card_exp_year: Secret<String>,}+impl CardMandateInfo {+ pub fn get_expiry_date_as_mmyy(&self) -> Result<Secret<String>, errors::ConnectorError> {+ let year = self.card_exp_year.peek();+ let year_2_digit = if year.len() == 4 {+ year.get(2..)+ .ok_or(errors::ConnectorError::RequestEncodingFailed)?+ .to_string()+ } else if year.len() == 2 {+ year.to_string()+ } else {+ return Err(errors::ConnectorError::RequestEncodingFailed);+ };+ let month = self.card_exp_month.peek();+ let month_str = format!("{:0>2}", month);+ Ok(Secret::new(format!("{}{}", month_str, year_2_digit)))+ }+}+impl TryFrom<payment_method_data::GooglePayWalletData> for GooglePayWalletData {type Error = common_utils::errors::ValidationError;