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
feat(connectors): [worldpayxml] add browser, shipping, shopper and billing data to the connector's payment request (#10357)
AkshayaFoiger34497cad5b96
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs b/crates/hyperswitch_connectors/src/connectors/worldpayxml.rsindex b828765c05..93f1a95144 100644--- a/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs+++ b/crates/hyperswitch_connectors/src/connectors/worldpayxml.rs@@ -263,6 +263,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseDatalet connector_router_data = worldpayxml::WorldpayxmlRouterData::from((amount, req));let connector_req_object = worldpayxml::PaymentService::try_from(&connector_router_data)?;+ router_env::logger::info!(raw_connector_request=?connector_req_object);let connector_req = utils::XmlSerializer::serialize_to_xml_bytes(&connector_req_object,@@ -349,6 +350,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for Wor_connectors: &Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> {let connector_req_object = worldpayxml::PaymentService::try_from(req)?;+ router_env::logger::info!(raw_connector_request=?connector_req_object);let connector_req = utils::XmlSerializer::serialize_to_xml_bytes(&connector_req_object,worldpayxml::worldpayxml_constants::XML_VERSION,@@ -436,6 +438,7 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo)?;let connector_router_data = worldpayxml::WorldpayxmlRouterData::from((amount, req));let connector_req_object = worldpayxml::PaymentService::try_from(&connector_router_data)?;+ router_env::logger::info!(raw_connector_request=?connector_req_object);let connector_req = utils::XmlSerializer::serialize_to_xml_bytes(&connector_req_object,@@ -520,6 +523,7 @@ impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Wo_connectors: &Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> {let connector_req_object = worldpayxml::PaymentService::try_from(req)?;+ router_env::logger::info!(raw_connector_request=?connector_req_object);let connector_req = utils::XmlSerializer::serialize_to_xml_bytes(&connector_req_object,@@ -607,6 +611,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Worldpalet connector_router_data = worldpayxml::WorldpayxmlRouterData::from((refund_amount, req));let connector_req_object = worldpayxml::PaymentService::try_from(&connector_router_data)?;+ router_env::logger::info!(raw_connector_request=?connector_req_object);let connector_req = utils::XmlSerializer::serialize_to_xml_bytes(&connector_req_object,worldpayxml::worldpayxml_constants::XML_VERSION,@@ -689,6 +694,7 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Worldpayx_connectors: &Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> {let connector_req_object = worldpayxml::PaymentService::try_from(req)?;+ router_env::logger::info!(raw_connector_request=?connector_req_object);let connector_req = utils::XmlSerializer::serialize_to_xml_bytes(&connector_req_object,@@ -1101,4 +1107,22 @@ impl ConnectorSpecifications for Worldpayxml {fn get_supported_webhook_flows(&self) -> Option<&'static [common_enums::EventClass]> {Some(&WORLDPAYXML_SUPPORTED_WEBHOOK_FLOWS)}++ #[cfg(feature = "v1")]+ fn generate_connector_request_reference_id(+ &self,+ payment_intent: &hyperswitch_domain_models::payments::PaymentIntent,+ payment_attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,+ is_config_enabled_to_send_payment_id_as_connector_request_id: bool,+ ) -> String {+ if is_config_enabled_to_send_payment_id_as_connector_request_id+ && payment_intent.is_payment_id_from_merchant.unwrap_or(false)+ {+ payment_attempt.payment_id.get_string_repr().to_owned()+ } else {+ let max_payment_reference_id_length =+ worldpayxml::worldpayxml_constants::MAX_PAYMENT_REFERENCE_ID_LENGTH;+ nanoid::nanoid!(max_payment_reference_id_length)+ }+ }}diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rsindex 9622f4f112..5a5047cddb 100644--- a/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs@@ -7,6 +7,13 @@ use common_enums::CardNetwork;use common_utils::pii;use common_utils::types::StringMinorUnit;use error_stack::ResultExt;+#[cfg(feature = "payouts")]+use hyperswitch_domain_models::{+ address::Address,+ router_flow_types::payouts::{PoCancel, PoFulfill},+ router_response_types::PayoutsResponseData,+ types::PayoutsRouterData,+};use hyperswitch_domain_models::{payment_method_data::{Card, PaymentMethodData},router_data::{ConnectorAuthType, ErrorResponse, RouterData},@@ -18,12 +25,6 @@ use hyperswitch_domain_models::{PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData,},};-#[cfg(feature = "payouts")]-use hyperswitch_domain_models::{- router_flow_types::payouts::{PoCancel, PoFulfill},- router_response_types::PayoutsResponseData,- types::PayoutsRouterData,-};use hyperswitch_interfaces::{consts, errors};use masking::Secret;use serde::{Deserialize, Serialize};@@ -36,8 +37,8 @@ use crate::{RefundsResponseRouterData, ResponseRouterData,},utils::{- self as connector_utils, CardData, PaymentsAuthorizeRequestData, PaymentsSyncRequestData,- RouterData as _,+ self as connector_utils, AddressDetailsData, CardData, PaymentsAuthorizeRequestData,+ PaymentsSyncRequestData, RouterData as _,},};@@ -60,6 +61,7 @@ pub mod worldpayxml_constants {pub const XML_VERSION: &str = "1.0";pub const XML_ENCODING: &str = "UTF-8";pub const WORLDPAYXML_DOC_TYPE: &str = r#"paymentService PUBLIC "-//Worldpay//DTD Worldpay PaymentService v1//EN" "http://dtd.worldpay.com/paymentService_v1.dtd""#;+ pub const MAX_PAYMENT_REFERENCE_ID_LENGTH: usize = 64;}#[derive(Debug, Serialize, Deserialize)]@@ -301,6 +303,73 @@ struct Order {description: String,amount: WorldpayXmlAmount,payment_details: PaymentDetails,+ #[serde(skip_serializing_if = "Option::is_none")]+ shopper: Option<WorldpayxmlShopper>,+ #[serde(skip_serializing_if = "Option::is_none")]+ shipping_address: Option<WorldpayxmlPayinAddress>,+ #[serde(skip_serializing_if = "Option::is_none")]+ billing_address: Option<WorldpayxmlPayinAddress>,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct WorldpayxmlShopper {+ #[serde(skip_serializing_if = "Option::is_none")]+ pub shopper_email_address: Option<pii::Email>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser: Option<WPGBrowserData>,+}++#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct WPGBrowserData {+ #[serde(skip_serializing_if = "Option::is_none")]+ pub accept_header: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub user_agent_header: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub http_accept_language: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub http_referer: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub time_zone: Option<i32>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser_language: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser_java_enabled: Option<bool>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser_java_script_enabled: Option<bool>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser_colour_depth: Option<u8>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser_screen_height: Option<u32>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub browser_screen_width: Option<u32>,+}++#[derive(Debug, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+struct WorldpayxmlPayinAddress {+ address: WorldpayxmlAddressData,+}++#[derive(Debug, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+struct WorldpayxmlAddressData {+ #[serde(skip_serializing_if = "Option::is_none")]+ first_name: Option<Secret<String>>,+ #[serde(skip_serializing_if = "Option::is_none")]+ last_name: Option<Secret<String>>,+ address1: Secret<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ address2: Option<Secret<String>>,+ #[serde(skip_serializing_if = "Option::is_none")]+ address3: Option<Secret<String>>,+ postal_code: Secret<String>,+ city: String,+ #[serde(skip_serializing_if = "Option::is_none")]+ state: Option<Secret<String>>,+ country_code: common_enums::CountryAlpha2,}#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]@@ -425,14 +494,22 @@ pub struct WorldpayxmlPayoutConnectorMetadataObject {#[derive(Debug, Serialize, Deserialize)]#[serde(rename_all = "SCREAMING_SNAKE_CASE")]enum Action {+ Authorise,+ Sale,Refund,}-impl TryFrom<&Card> for PaymentDetails {+impl TryFrom<(&Card, Option<enums::CaptureMethod>)> for PaymentDetails {type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(card_data: &Card) -> Result<Self, Self::Error> {+ fn try_from(+ (card_data, capture_method): (&Card, Option<enums::CaptureMethod>),+ ) -> Result<Self, Self::Error> {Ok(Self {- action: None,+ action: if connector_utils::is_manual_capture(capture_method) {+ Some(Action::Authorise)+ } else {+ Some(Action::Sale)+ },payment_method: PaymentMethod::CardSSL(CardSSL {card_number: card_data.card_number.clone(),expiry_date: ExpiryDate {@@ -460,10 +537,28 @@ impl TryFrom<(&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>, &Card)> forlet auth = WorldpayxmlAuthType::try_from(&authorize_data.router_data.connector_auth_type).change_context(errors::ConnectorError::FailedToObtainAuthType)?;- let order_code = authorize_data+ let order_code = if authorize_data.router_data.connector_request_reference_id- .to_owned();+ .len()+ <= worldpayxml_constants::MAX_PAYMENT_REFERENCE_ID_LENGTH+ {+ Ok(authorize_data+ .router_data+ .connector_request_reference_id+ .clone())+ } else {+ Err(errors::ConnectorError::MaxFieldLengthViolated {+ connector: "Worldpayxml".to_string(),+ field_name: "order_code".to_string(),+ max_length: worldpayxml_constants::MAX_PAYMENT_REFERENCE_ID_LENGTH,+ received_length: authorize_data+ .router_data+ .connector_request_reference_id+ .len(),+ })+ }?;+let capture_delay = if authorize_data.router_data.request.is_auto_capture()? {Some(AutoCapture::On)} else {@@ -485,7 +580,20 @@ impl TryFrom<(&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>, &Card)> forexponent,value: authorize_data.amount.to_owned(),};- let payment_details = PaymentDetails::try_from(card_data)?;+ let shopper = get_shopper_details(authorize_data.router_data);+ let billing_address = authorize_data+ .router_data+ .get_optional_billing()+ .and_then(get_address_details);+ let shipping_address = authorize_data+ .router_data+ .get_optional_shipping()+ .and_then(get_address_details);++ let payment_details = PaymentDetails::try_from((+ card_data,+ authorize_data.router_data.request.capture_method,+ ))?;let submit = Some(Submit {order: Order {order_code,@@ -493,6 +601,9 @@ impl TryFrom<(&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>, &Card)> fordescription,amount,payment_details,+ shopper,+ billing_address,+ shipping_address,},});@@ -507,6 +618,79 @@ impl TryFrom<(&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>, &Card)> for}}+fn get_address_details(data: &Address) -> Option<WorldpayxmlPayinAddress> {+ let address1_option = data+ .address+ .as_ref()+ .and_then(|address| address.get_optional_line1());+ let postal_code_option = data+ .address+ .as_ref()+ .and_then(|address| address.get_optional_zip());+ let country_code_option = data+ .address+ .as_ref()+ .and_then(|address| address.get_optional_country());+ let city_option = data+ .address+ .as_ref()+ .and_then(|address| address.get_optional_city());++ if let (Some(address1), Some(postal_code), Some(country_code), Some(city), Some(address_data)) = (+ address1_option,+ postal_code_option,+ country_code_option,+ city_option,+ data.address.as_ref(),+ ) {+ Some(WorldpayxmlPayinAddress {+ address: WorldpayxmlAddressData {+ first_name: address_data.get_optional_first_name(),+ last_name: address_data.get_optional_last_name(),+ address1,+ address2: address_data.get_optional_line2(),+ address3: address_data.get_optional_line2(),+ postal_code,+ city,+ state: address_data.get_optional_state(),+ country_code,+ },+ })+ } else {+ None+ }+}++fn get_shopper_details(item: &PaymentsAuthorizeRouterData) -> Option<WorldpayxmlShopper> {+ let shopper_email = item.request.email.clone();+ let browser_info = item+ .request+ .browser_info+ .as_ref()+ .map(|browser_info| WPGBrowserData {+ accept_header: browser_info.accept_header.clone(),+ http_accept_language: browser_info.accept_language.clone(),+ http_referer: browser_info.referer.clone(),+ browser_language: browser_info.language.clone(),+ browser_java_enabled: browser_info.java_enabled,+ browser_java_script_enabled: browser_info.java_script_enabled,+ browser_colour_depth: browser_info.color_depth,+ browser_screen_height: browser_info.screen_height,+ browser_screen_width: browser_info.screen_width,+ user_agent_header: browser_info.user_agent.clone(),+ time_zone: browser_info.time_zone,+ });++ if shopper_email.is_some() || browser_info.is_some() {+ Some(WorldpayxmlShopper {+ shopper_email_address: shopper_email,+ browser: browser_info,+ })+ } else {+ None+ }+}+impl TryFrom<&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>> for PaymentService {type Error = error_stack::Report<errors::ConnectorError>;fn try_from(@@ -1378,6 +1562,9 @@ impl TryFrom<&WorldpayxmlRouterData<&PayoutsRouterData<PoFulfill>>> for PaymentSdescription,amount,payment_details,+ shopper: None,+ billing_address: None,+ shipping_address: None,},});diff --git a/crates/payment_methods/src/configs/payment_connector_required_fields.rs b/crates/payment_methods/src/configs/payment_connector_required_fields.rsindex 543808dc43..41a1b235f5 100644--- a/crates/payment_methods/src/configs/payment_connector_required_fields.rs+++ b/crates/payment_methods/src/configs/payment_connector_required_fields.rs@@ -1674,6 +1674,10 @@ fn get_cards_required_fields() -> HashMap<Connector, RequiredFieldFinal> {],),),+ (+ Connector::Worldpayxml,+ fields(vec![], card_with_name(), vec![]),+ ),(Connector::Worldpayvantiv,fields(vec![], card_basic(), vec![]),