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

feat(connector): [WorldpayWPG][Checkout] Add support for AFT (#13889)

Vani Guptabde2cbf34c12
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index e8c9dd59e2..de9684799b 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -17367,6 +17367,18 @@
"add_to_unbilled_charges"
]
},
+ "CheckoutData": {
+ "type": "object",
+ "properties": {
+ "purpose_of_payment": {
+ "type": "string",
+ "description": "Purpose of Payment. Required for AFT.",
+ "example": "wallet top-up",
+ "nullable": true
+ }
+ },
+ "additionalProperties": false
+ },
"ClickToPayDetails": {
"type": "object",
"properties": {
@@ -18088,6 +18100,22 @@
}
],
"nullable": true
+ },
+ "worldpayxml": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WorldpayxmlData"
+ }
+ ],
+ "nullable": true
+ },
+ "checkout": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/CheckoutData"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -48420,6 +48448,79 @@
}
}
},
+ "WorldpayxmlData": {
+ "type": "object",
+ "properties": {
+ "funding_transaction_type": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WorldpayxmlFundingTransactionType"
+ }
+ ],
+ "nullable": true
+ },
+ "payment_purpose": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WorldpayxmlPaymentPurpose"
+ }
+ ],
+ "nullable": true
+ }
+ },
+ "additionalProperties": false
+ },
+ "WorldpayxmlFundingTransactionType": {
+ "type": "string",
+ "enum": [
+ "credit_card_bill_repayment",
+ "gift_card_purchase",
+ "gift_card_purchase_for_another",
+ "non_reloadable_prepaid_card",
+ "reloadable_prepaid_card_or_account",
+ "gaming_chips_purchase",
+ "gaming_stored_value_wallet",
+ "gaming_staged_digital_wallet",
+ "liquid_and_crypto_assets_purchase",
+ "liquid_and_crypto_stored_value_wallet_load",
+ "stored_value_digital_wallet_load",
+ "stored_value_digital_wallet_load_non_securities",
+ "securities_stored_value_digital_wallet_load",
+ "securities_staged_digital_wallet_load",
+ "single_merchant_wallet_load",
+ "debit_card_load",
+ "transfer_to_own_debit_account",
+ "funds_transfer_me_to_me",
+ "account_to_account",
+ "back_to_back_p2p_without_wallet",
+ "back_to_back_p2p_with_wallet",
+ "agent_cash_out",
+ "staged_digital_wallet_load",
+ "staged_digital_wallet_purchase",
+ "back_to_back_card_purchase",
+ "payroll_disbursement_funding",
+ "business_to_consumer_disbursement",
+ "business_to_business_invoice_payment"
+ ]
+ },
+ "WorldpayxmlPaymentPurpose": {
+ "type": "string",
+ "enum": [
+ "family_support",
+ "regular_labour_transfers",
+ "travel_and_tourism",
+ "education",
+ "hospitalisation_and_medical_treatment",
+ "emergency_need",
+ "savings",
+ "gifts",
+ "other",
+ "salary",
+ "crowd_lending",
+ "crypto_currency",
+ "high_risk_securities"
+ ]
+ },
"XenditChargeResponseData": {
"oneOf": [
{
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index c0e2f6aecb..88dbd70a9e 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -11710,6 +11710,18 @@
}
}
},
+ "CheckoutData": {
+ "type": "object",
+ "properties": {
+ "purpose_of_payment": {
+ "type": "string",
+ "description": "Purpose of Payment. Required for AFT.",
+ "example": "wallet top-up",
+ "nullable": true
+ }
+ },
+ "additionalProperties": false
+ },
"ClickToPaySessionResponse": {
"type": "object",
"required": [
@@ -12216,6 +12228,22 @@
}
],
"nullable": true
+ },
+ "worldpayxml": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WorldpayxmlData"
+ }
+ ],
+ "nullable": true
+ },
+ "checkout": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/CheckoutData"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -35441,6 +35469,79 @@
"Failure"
]
},
+ "WorldpayxmlData": {
+ "type": "object",
+ "properties": {
+ "funding_transaction_type": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WorldpayxmlFundingTransactionType"
+ }
+ ],
+ "nullable": true
+ },
+ "payment_purpose": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/WorldpayxmlPaymentPurpose"
+ }
+ ],
+ "nullable": true
+ }
+ },
+ "additionalProperties": false
+ },
+ "WorldpayxmlFundingTransactionType": {
+ "type": "string",
+ "enum": [
+ "credit_card_bill_repayment",
+ "gift_card_purchase",
+ "gift_card_purchase_for_another",
+ "non_reloadable_prepaid_card",
+ "reloadable_prepaid_card_or_account",
+ "gaming_chips_purchase",
+ "gaming_stored_value_wallet",
+ "gaming_staged_digital_wallet",
+ "liquid_and_crypto_assets_purchase",
+ "liquid_and_crypto_stored_value_wallet_load",
+ "stored_value_digital_wallet_load",
+ "stored_value_digital_wallet_load_non_securities",
+ "securities_stored_value_digital_wallet_load",
+ "securities_staged_digital_wallet_load",
+ "single_merchant_wallet_load",
+ "debit_card_load",
+ "transfer_to_own_debit_account",
+ "funds_transfer_me_to_me",
+ "account_to_account",
+ "back_to_back_p2p_without_wallet",
+ "back_to_back_p2p_with_wallet",
+ "agent_cash_out",
+ "staged_digital_wallet_load",
+ "staged_digital_wallet_purchase",
+ "back_to_back_card_purchase",
+ "payroll_disbursement_funding",
+ "business_to_consumer_disbursement",
+ "business_to_business_invoice_payment"
+ ]
+ },
+ "WorldpayxmlPaymentPurpose": {
+ "type": "string",
+ "enum": [
+ "family_support",
+ "regular_labour_transfers",
+ "travel_and_tourism",
+ "education",
+ "hospitalisation_and_medical_treatment",
+ "emergency_need",
+ "savings",
+ "gifts",
+ "other",
+ "salary",
+ "crowd_lending",
+ "crypto_currency",
+ "high_risk_securities"
+ ]
+ },
"XenditChargeResponseData": {
"oneOf": [
{
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 699a97a532..8145ddfabd 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -10168,6 +10168,91 @@ pub struct ConnectorMetadata {
pub peachpayments: Option<PeachpaymentsData>,
#[smithy(value_type = "Option<SantanderData>")]
pub santander: Option<SantanderConnectorMetadataData>,
+ #[smithy(value_type = "Option<WorldpayxmlData>")]
+ pub worldpayxml: Option<WorldpayxmlData>,
+ #[smithy(value_type = "Option<CheckoutData>")]
+ pub checkout: Option<CheckoutData>,
+}
+
+#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+#[serde(deny_unknown_fields)]
+pub struct CheckoutData {
+ /// Purpose of Payment. Required for AFT.
+ #[schema(value_type = Option<String>, example = "wallet top-up")]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub purpose_of_payment: Option<String>,
+}
+
+#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+#[serde(deny_unknown_fields)]
+pub struct WorldpayxmlData {
+ /// Funding Transfer Type. Required for AFT.
+ #[schema(value_type = Option<WorldpayxmlFundingTransactionType>, example = "account_to_account")]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub funding_transaction_type: Option<WorldpayxmlFundingTransactionType>,
+ /// Purpose of Payment. Required for AFT.
+ #[schema(value_type = Option<WorldpayxmlPaymentPurpose>, example = "savings")]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub payment_purpose: Option<WorldpayxmlPaymentPurpose>,
+}
+
+#[derive(
+ Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel,
+)]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+#[serde(rename_all = "snake_case")]
+pub enum WorldpayxmlFundingTransactionType {
+ CreditCardBillRepayment,
+ GiftCardPurchase,
+ GiftCardPurchaseForAnother,
+ NonReloadablePrepaidCard,
+ ReloadablePrepaidCardOrAccount,
+ GamingChipsPurchase,
+ GamingStoredValueWallet,
+ GamingStagedDigitalWallet,
+ LiquidAndCryptoAssetsPurchase,
+ LiquidAndCryptoStoredValueWalletLoad,
+ StoredValueDigitalWalletLoad,
+ StoredValueDigitalWalletLoadNonSecurities,
+ SecuritiesStoredValueDigitalWalletLoad,
+ SecuritiesStagedDigitalWalletLoad,
+ SingleMerchantWalletLoad,
+ DebitCardLoad,
+ TransferToOwnDebitAccount,
+ FundsTransferMeToMe,
+ AccountToAccount,
+ BackToBackP2pWithoutWallet,
+ BackToBackP2pWithWallet,
+ AgentCashOut,
+ StagedDigitalWalletLoad,
+ StagedDigitalWalletPurchase,
+ BackToBackCardPurchase,
+ PayrollDisbursementFunding,
+ BusinessToConsumerDisbursement,
+ BusinessToBusinessInvoicePayment,
+}
+
+#[derive(
+ Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel,
+)]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+#[serde(rename_all = "snake_case")]
+pub enum WorldpayxmlPaymentPurpose {
+ FamilySupport,
+ RegularLabourTransfers,
+ TravelAndTourism,
+ Education,
+ HospitalisationAndMedicalTreatment,
+ EmergencyNeed,
+ Savings,
+ Gifts,
+ Other,
+ Salary,
+ CrowdLending,
+ CryptoCurrency,
+ HighRiskSecurities,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]
diff --git a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
index 110368dd38..a2068f69db 100644
--- a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
@@ -27,7 +27,7 @@ use hyperswitch_domain_models::{
},
};
use hyperswitch_interfaces::{consts, errors, webhooks};
-use hyperswitch_masking::{ExposeInterface, Secret};
+use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_with::skip_serializing_none;
@@ -369,6 +369,8 @@ pub struct CheckoutPhoneDetails {
#[skip_serializing_none]
#[derive(Debug, Default, Serialize)]
pub struct CheckoutProcessing {
+ /// Marks the payment as an Account Funding Transaction.
+ pub aft: Option<bool>,
pub order_id: Option<String>,
pub scheme_transaction_link_id: Option<String>,
pub tax_amount: Option<MinorUnit>,
@@ -408,6 +410,159 @@ pub struct CheckoutBillingDescriptor {
pub reference: Option<String>,
}
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "lowercase")]
+pub enum CheckoutSenderType {
+ Individual,
+}
+
+#[skip_serializing_none]
+#[derive(Debug, Serialize)]
+pub struct CheckoutSender {
+ #[serde(rename = "type")]
+ pub sender_type: CheckoutSenderType,
+ pub first_name: Secret<String>,
+ pub last_name: Secret<String>,
+ pub address: CheckoutAddress,
+ pub date_of_birth: Secret<time::Date>,
+}
+
+#[skip_serializing_none]
+#[derive(Debug, Serialize)]
+pub struct CheckoutInstruction {
+ pub purpose: String,
+}
+
+#[skip_serializing_none]
+#[derive(Debug, Serialize)]
+pub struct CheckoutRecipient {
+ pub first_name: Secret<String>,
+ pub last_name: Secret<String>,
+ pub account_number: Secret<String>,
+ pub address: CheckoutAddress,
+}
+
+fn get_checkout_recipient_account_number(
+ account: &api_models::payments::RecipientAccount,
+) -> Result<Secret<String>, error_stack::Report<errors::ConnectorError>> {
+ use api_models::payments::{RecipientAccount, RecipientBankAccount};
+
+ let unsupported = |identifier: &str| {
+ error_stack::report!(errors::ConnectorError::NotSupported {
+ message: format!("{identifier} as a recipient account identifier"),
+ connector: "checkout",
+ })
+ };
+
+ match account {
+ RecipientAccount::BankAccount(bank_account) => match bank_account {
+ RecipientBankAccount::Iban { iban } => Ok(iban.clone()),
+ RecipientBankAccount::RoutingNumber { .. } => {
+ Err(unsupported("a bank account number with a routing number"))
+ }
+ RecipientBankAccount::Bic { .. } => {
+ Err(unsupported("a bank account number with a BIC"))
+ }
+ RecipientBankAccount::AccountNumber { .. } => {
+ Err(unsupported("a bare bank account number"))
+ }
+ // Checkout documents the first six and last four digits of the PAN as one of the
+ // accepted account number forms.
+ RecipientBankAccount::TruncatedPan { card_isin, last4 } => {
+ Ok(Secret::new(format!("{}{}", card_isin.peek(), last4.peek())))
+ }
+ },
+ RecipientAccount::Card { card_number } => Ok(Secret::new(card_number.get_card_no())),
+ RecipientAccount::Phone { phone_number } => Ok(phone_number.clone()),
+ RecipientAccount::Wallet { .. } => Err(unsupported("wallet_id")),
+ RecipientAccount::Email { .. } => Err(unsupported("email")),
+ RecipientAccount::SocialNetwork { .. } => Err(unsupported("social_network_id")),
+ }
+}
+
+fn build_checkout_recipient(
+ recipient_details: Option<&api_models::payments::RecipientDetails>,
+) -> Result<CheckoutRecipient, error_stack::Report<errors::ConnectorError>> {
+ let recipient_details =
+ recipient_details.ok_or_else(utils::missing_field_err("recipient_details"))?;
+
+ let address = recipient_details
+ .address
+ .as_ref()
+ .ok_or_else(utils::missing_field_err("recipient_details.address"))?;
+
+ let account_number = recipient_details
+ .account
+ .as_ref()
+ .ok_or_else(utils::missing_field_err("recipient_details.account"))
+ .and_then(get_checkout_recipient_account_number)?;
+
+ Ok(CheckoutRecipient {
+ first_name: address
+ .first_name
+ .clone()
+ .ok_or_else(utils::missing_field_err(
+ "recipient_details.address.first_name",
+ ))?,
+ last_name: address
+ .last_name
+ .clone()
+ .ok_or_else(utils::missing_field_err(
+ "recipient_details.address.last_name",
+ ))?,
+ account_number,
+ address: CheckoutAddress {
+ address_line1: Some(
+ address
+ .line1
+ .clone()
+ .ok_or_else(utils::missing_field_err("recipient_details.address.line1"))?,
+ ),
+ address_line2: address.line2.clone(),
+ city: Some(
+ address
+ .city
+ .clone()
+ .ok_or_else(utils::missing_field_err("recipient_details.address.city"))?,
+ ),
+ state: Some(
+ address
+ .state
+ .clone()
+ .ok_or_else(utils::missing_field_err("recipient_details.address.state"))?,
+ ),
+ zip: Some(
+ address
+ .zip
+ .clone()
+ .ok_or_else(utils::missing_field_err("recipient_details.address.zip"))?,
+ ),
+ country: Some(address.country.ok_or_else(utils::missing_field_err(
+ "recipient_details.address.country",
+ ))?),
+ },
+ })
+}
+
+fn build_checkout_sender(
+ router_data: &PaymentsAuthorizeRouterData,
+) -> Result<CheckoutSender, error_stack::Report<errors::ConnectorError>> {
+ Ok(CheckoutSender {
+ sender_type: CheckoutSenderType::Individual,
+ first_name: router_data.get_billing_first_name()?,
+ last_name: router_data.get_billing_last_name()?,
+ date_of_birth: router_data.get_customer_date_of_birth()?,
+ address: CheckoutAddress {
+ address_line1: Some(router_data.get_billing_line1()?),
+ address_line2: router_data.get_optional_billing_line2(),
+ city: Some(router_data.get_billing_city()?),
+ state: Some(router_data.get_billing_state()?),
+ zip: Some(router_data.get_billing_zip()?),
+ country: Some(router_data.get_billing_country()?),
+ },
+ })
+}
+
#[skip_serializing_none]
#[derive(Debug, Serialize)]
pub struct PaymentsRequest {
@@ -435,6 +590,9 @@ pub struct PaymentsRequest {
pub items: Option<Vec<CheckoutLineItem>>,
pub partial_authorization: Option<CheckoutPartialAuthorization>,
pub payment_ip: Option<Secret<String, common_utils::pii::IpAddress>>,
+ pub recipient: Option<CheckoutRecipient>,
+ pub sender: Option<CheckoutSender>,
+ pub instruction: Option<CheckoutInstruction>,
}
#[skip_serializing_none]
@@ -1030,6 +1188,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
tax_number: l2l3_data.get_customer_tax_registration_id(),
}),
l2l3_data.order_info.as_ref().map(|_| CheckoutProcessing {
+ aft: None,
order_id: l2l3_data.get_merchant_order_reference_id(),
scheme_transaction_link_id: None,
tax_amount: l2l3_data.get_order_tax_amount(),
@@ -1103,6 +1262,39 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
})
});
+ let is_account_funded_transaction = item
+ .router_data
+ .request
+ .is_account_funded_transaction
+ .unwrap_or(false);
+
+ let (recipient, sender, instruction) = if is_account_funded_transaction {
+ processing
+ .get_or_insert_with(CheckoutProcessing::default)
+ .aft = Some(true);
+
+ let purpose = item
+ .router_data
+ .request
+ .connector_intent_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.checkout.as_ref())
+ .and_then(|checkout| checkout.purpose_of_payment.clone())
+ .ok_or_else(utils::missing_field_err(
+ "connector_metadata.checkout.purpose_of_payment",
+ ))?;
+
+ (
+ Some(build_checkout_recipient(
+ item.router_data.request.recipient_details.as_ref(),
+ )?),
+ Some(build_checkout_sender(item.router_data)?),
+ Some(CheckoutInstruction { purpose }),
+ )
+ } else {
+ (None, None, None)
+ };
+
let request = Self {
source: source_var,
amount: item.amount.to_owned(),
@@ -1124,6 +1316,9 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
partial_authorization,
payment_ip,
billing_descriptor,
+ recipient,
+ sender,
+ instruction,
};
Ok(request)
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs
index 16c62d5e99..c61ac3794f 100644
--- a/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/worldpayxml/transformers.rs
@@ -36,7 +36,7 @@ use hyperswitch_domain_models::{
},
};
use hyperswitch_interfaces::{consts, errors};
-use hyperswitch_masking::{ExposeInterface, Secret};
+use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
use josekit;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
@@ -71,6 +71,7 @@ impl<T> From<(StringMinorUnit, T)> for WorldpayxmlRouterData<T> {
pub mod worldpayxml_constants {
pub const WORLDPAYXML_VERSION: &str = "1.4";
+ pub const WORLDPAYXML_FUNDING_CATEGORY: &str = "PULL_FROM_CARD";
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""#;
@@ -385,6 +386,8 @@ struct Order {
create_token: Option<CreateToken>,
#[serde(skip_serializing_if = "Option::is_none", rename = "additional3DSData")]
additional_threeds_data: Option<AdditionalThreeDSData>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ funding_transfer: Option<FundingTransfer>,
}
#[derive(Debug, Serialize, Deserialize)]
@@ -447,6 +450,103 @@ struct WorldpayxmlPayinAddress {
address: WorldpayxmlAddressData,
}
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct FundingTransfer {
+ #[serde(rename = "@type")]
+ transfer_type: String,
+ #[serde(rename = "@category")]
+ category: String,
+ payment_purpose: String,
+ funding_party: Vec<FundingParty>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+enum FundingPartyType {
+ Sender,
+ Recipient,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct FundingParty {
+ #[serde(rename = "@type")]
+ party_type: FundingPartyType,
+ account_reference: AccountReference,
+ full_name: FullName,
+ funding_address: FundingAddress,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ funding_data: Option<FundingData>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ tax_id: Option<Secret<String>>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+struct AccountReference {
+ #[serde(rename = "@accountType")]
+ account_type: String,
+ #[serde(rename = "$text")]
+ value: Secret<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct FullName {
+ first: Secret<String>,
+ last: Secret<String>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct FundingAddress {
+ address1: Secret<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ address2: Option<Secret<String>>,
+ postal_code: Secret<String>,
+ city: String,
+ state: Secret<String>,
+ country_code: common_enums::CountryAlpha2,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct FundingData {
+ #[serde(skip_serializing_if = "Option::is_none")]
+ birth_date: Option<BirthDate>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ telephone_number: Option<Secret<String>>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct BirthDate {
+ date: WorldpayxmlDate,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+struct WorldpayxmlDate {
+ #[serde(rename = "@dayOfMonth")]
+ day_of_month: Secret<String>,
+ #[serde(rename = "@month")]
+ month: Secret<String>,
+ #[serde(rename = "@year")]
+ year: Secret<String>,
+}
+
+impl From<Secret<time::Date>> for BirthDate {
+ fn from(date_of_birth: Secret<time::Date>) -> Self {
+ let date = date_of_birth.expose();
+ Self {
+ date: WorldpayxmlDate {
+ day_of_month: Secret::new(date.day().to_string()),
+ month: Secret::new(u8::from(date.month()).to_string()),
+ year: Secret::new(date.year().to_string()),
+ },
+ }
+ }
+}
+
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct WorldpayxmlAddressData {
@@ -748,6 +848,8 @@ pub struct WorldpayxmlConnectorMetadataObject {
pub issuer_id: Option<String>,
pub organizational_unit_id: Option<String>,
pub jwt_mac_key: Option<String>,
+ pub funding_transaction_type: Option<String>,
+ pub payment_purpose: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
@@ -1311,6 +1413,274 @@ fn get_shopper_details_cauth(
}
}
+fn get_worldpayxml_account_reference(
+ account: &api_models::payments::RecipientAccount,
+) -> Result<AccountReference, error_stack::Report<errors::ConnectorError>> {
+ use api_models::payments::{RecipientAccount, RecipientBankAccount};
+
+ let (account_type, value) = match account {
+ RecipientAccount::BankAccount(bank_account) => match bank_account {
+ RecipientBankAccount::Iban { iban } => ("02", iban.clone()),
+ RecipientBankAccount::RoutingNumber {
+ account_number,
+ routing_number,
+ } => (
+ "01",
+ Secret::new(format!(
+ "{}+{}",
+ account_number.peek(),
+ routing_number.peek()
+ )),
+ ),
+ RecipientBankAccount::Bic {
+ account_number,
+ bic,
+ } => (
+ "06",
+ Secret::new(format!("{}+{}", account_number.peek(), bic.peek())),
+ ),
+ RecipientBankAccount::AccountNumber { account_number } => {
+ ("03", account_number.clone())
+ }
+ RecipientBankAccount::TruncatedPan { .. } => {
+ Err(errors::ConnectorError::NotSupported {
+ message: "a truncated PAN as a recipient account identifier".to_string(),
+ connector: "worldpayxml",
+ })?
+ }
+ },
+ RecipientAccount::Card { card_number } => ("03", Secret::new(card_number.get_card_no())),
+ RecipientAccount::Email { email } => ("04", Secret::new(email.clone().expose().expose())),
+ RecipientAccount::Phone { phone_number } => ("05", phone_number.clone()),
+ RecipientAccount::Wallet { wallet_id } => ("07", wallet_id.clone()),
+ RecipientAccount::SocialNetwork { social_network_id } => ("08", social_network_id.clone()),
+ };
+
+ Ok(AccountReference {
+ account_type: account_type.to_string(),
+ value,
+ })
+}
+
+fn build_worldpayxml_recipient_party(
+ recipient_details: Option<&api_models::payments::RecipientDetails>,
+ business_country: Option<common_enums::CountryAlpha2>,
+) -> Result<FundingParty, error_stack::Report<errors::ConnectorError>> {
+ let recipient_details =
+ recipient_details.ok_or_else(connector_utils::missing_field_err("recipient_details"))?;
+
+ let address =
+ recipient_details
+ .address
+ .as_ref()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address",
+ ))?;
+
+ let account_reference = recipient_details
+ .account
+ .as_ref()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.account",
+ ))
+ .and_then(get_worldpayxml_account_reference)?;
+
+ Ok(FundingParty {
+ party_type: FundingPartyType::Recipient,
+ account_reference,
+ full_name: FullName {
+ first: address
+ .first_name
+ .clone()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.first_name",
+ ))?,
+ last: address
+ .last_name
+ .clone()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.last_name",
+ ))?,
+ },
+ funding_address: FundingAddress {
+ address1: address
+ .line1
+ .clone()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.line1",
+ ))?,
+ address2: address.line2.clone(),
+ postal_code: address
+ .zip
+ .clone()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.zip",
+ ))?,
+ city: address
+ .city
+ .clone()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.city",
+ ))?,
+ state: address
+ .state
+ .clone()
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.state",
+ ))?,
+ country_code: address
+ .country
+ .ok_or_else(connector_utils::missing_field_err(
+ "recipient_details.address.country",
+ ))?,
+ },
+ funding_data: recipient_details
+ .phone_number
+ .clone()
+ .map(|telephone_number| FundingData {
+ birth_date: None,
+ telephone_number: Some(telephone_number),
+ }),
+ // Worldpay require the recipient's CPF or CNPJ from merchants in Brazil, and treat the
+ // tax ID as optional elsewhere.
+ tax_id: match business_country {
+ Some(common_enums::CountryAlpha2::BR) => {
+ Some(recipient_details.tax_id.clone().ok_or_else(
+ connector_utils::missing_field_err("recipient_details.tax_id"),
+ )?)
+ }
+ _ => recipient_details.tax_id.clone(),
+ },
+ })
+}
+
+fn build_worldpayxml_sender_party<F, Req, Res>(
+ router_data: &RouterData<F, Req, Res>,
+ card_number: Secret<String>,
+) -> Result<FundingParty, error_stack::Report<errors::ConnectorError>> {
+ Ok(FundingParty {
+ party_type: FundingPartyType::Sender,
+ account_reference: AccountReference {
+ account_type: "03".to_string(),
+ value: card_number,
+ },
+ full_name: FullName {
+ first: router_data.get_billing_first_name()?,
+ last: router_data.get_billing_last_name()?,
+ },
+ funding_address: FundingAddress {
+ address1: router_data.get_billing_line1()?,
+ address2: router_data.get_optional_billing_line2(),
+ postal_code: router_data.get_billing_zip()?,
+ city: router_data.get_billing_city()?,
+ state: router_data.get_billing_state()?,
+ country_code: router_data.get_billing_country()?,
+ },
+ funding_data: Some(FundingData {
+ birth_date: Some(BirthDate::from(router_data.get_customer_date_of_birth()?)),
+ telephone_number: router_data.get_optional_billing_phone_number(),
+ }),
+ tax_id: None,
+ })
+}
+
+fn get_worldpayxml_funding_transaction_type_code(
+ funding_transaction_type: api_models::payments::WorldpayxmlFundingTransactionType,
+) -> &'static str {
+ use api_models::payments::WorldpayxmlFundingTransactionType as TransactionType;
+
+ match funding_transaction_type {
+ TransactionType::CreditCardBillRepayment => "CR",
+ TransactionType::GiftCardPurchase => "GP",
+ TransactionType::GiftCardPurchaseForAnother => "GO",
+ TransactionType::NonReloadablePrepaidCard => "PC",
+ TransactionType::ReloadablePrepaidCardOrAccount => "TP",
+ TransactionType::GamingChipsPurchase => "GC",
+ TransactionType::GamingStoredValueWallet => "GS",
+ TransactionType::GamingStagedDigitalWallet => "GW",
+ TransactionType::LiquidAndCryptoAssetsPurchase => "LC",
+ TransactionType::LiquidAndCryptoStoredValueWalletLoad => "LS",
+ TransactionType::StoredValueDigitalWalletLoad => "SW",
+ TransactionType::StoredValueDigitalWalletLoadNonSecurities => "WV",
+ TransactionType::SecuritiesStoredValueDigitalWalletLoad => "WO",
+ TransactionType::SecuritiesStagedDigitalWalletLoad => "WH",
+ TransactionType::SingleMerchantWalletLoad => "WS",
+ TransactionType::DebitCardLoad => "FC",
+ TransactionType::TransferToOwnDebitAccount => "TA",
+ TransactionType::FundsTransferMeToMe => "FM",
+ TransactionType::AccountToAccount => "AA",
+ TransactionType::BackToBackP2pWithoutWallet => "PB",
+ TransactionType::BackToBackP2pWithWallet => "PN",
+ TransactionType::AgentCashOut => "AC",
+ TransactionType::StagedDigitalWalletLoad => "WA",
+ TransactionType::StagedDigitalWalletPurchase => "WP",
+ TransactionType::BackToBackCardPurchase => "BB",
+ TransactionType::PayrollDisbursementFunding => "PD",
+ TransactionType::BusinessToConsumerDisbursement => "BD",
+ TransactionType::BusinessToBusinessInvoicePayment => "BT",
+ }
+}
+
+fn get_worldpayxml_payment_purpose_code(
+ payment_purpose: api_models::payments::WorldpayxmlPaymentPurpose,
+) -> &'static str {
+ use api_models::payments::WorldpayxmlPaymentPurpose as Purpose;
+
+ match payment_purpose {
+ Purpose::FamilySupport => "00",
+ Purpose::RegularLabourTransfers => "01",
+ Purpose::TravelAndTourism => "02",
+ Purpose::Education => "03",
+ Purpose::HospitalisationAndMedicalTreatment => "04",
+ Purpose::EmergencyNeed => "05",
+ Purpose::Savings => "06",
+ Purpose::Gifts => "07",
+ Purpose::Other => "08",
+ Purpose::Salary => "09",
+ Purpose::CrowdLending => "10",
+ Purpose::CryptoCurrency => "11",
+ Purpose::HighRiskSecurities => "16",
+ }
+}
+
+fn build_worldpayxml_funding_transfer<F, Req, Res>(
+ router_data: &RouterData<F, Req, Res>,
+ card_number: Secret<String>,
+ recipient_details: Option<&api_models::payments::RecipientDetails>,
+ business_country: Option<common_enums::CountryAlpha2>,
+ connector_intent_metadata: Option<&api_models::payments::ConnectorMetadata>,
+) -> Result<FundingTransfer, error_stack::Report<errors::ConnectorError>> {
+ let worldpayxml_data = connector_intent_metadata
+ .and_then(|metadata| metadata.worldpayxml.clone())
+ .ok_or_else(connector_utils::missing_field_err(
+ "connector_metadata.worldpayxml",
+ ))?;
+
+ let transfer_type = worldpayxml_data
+ .funding_transaction_type
+ .map(get_worldpayxml_funding_transaction_type_code)
+ .ok_or_else(connector_utils::missing_field_err(
+ "connector_metadata.worldpayxml.funding_transaction_type",
+ ))?;
+
+ let payment_purpose = worldpayxml_data
+ .payment_purpose
+ .map(get_worldpayxml_payment_purpose_code)
+ .ok_or_else(connector_utils::missing_field_err(
+ "connector_metadata.worldpayxml.payment_purpose",
+ ))?;
+
+ Ok(FundingTransfer {
+ transfer_type: transfer_type.to_string(),
+ category: worldpayxml_constants::WORLDPAYXML_FUNDING_CATEGORY.to_string(),
+ payment_purpose: payment_purpose.to_string(),
+ funding_party: vec![
+ build_worldpayxml_sender_party(router_data, card_number)?,
+ build_worldpayxml_recipient_party(recipient_details, business_country)?,
+ ],
+ })
+}
+
impl TryFrom<&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>> for PaymentService {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
@@ -1456,6 +1826,33 @@ impl TryFrom<&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>> for PaymentSe
None
};
+ let funding_transfer = item
+ .router_data
+ .request
+ .is_account_funded_transaction
+ .unwrap_or(false)
+ .then(|| {
+ let card_number = match &item.router_data.request.payment_method_data {
+ PaymentMethodData::Card(card) => {
+ Ok(Secret::new(card.card_number.get_card_no()))
+ }
+ _ => Err(errors::ConnectorError::NotSupported {
+ message: "account funded transactions for non-card payment methods"
+ .to_string(),
+ connector: "worldpayxml",
+ }),
+ }?;
+
+ build_worldpayxml_funding_transfer(
+ item.router_data,
+ card_number,
+ item.router_data.request.recipient_details.as_ref(),
+ item.router_data.request.business_country,
+ item.router_data.request.connector_intent_metadata.as_ref(),
+ )
+ })
+ .transpose()?;
+
let submit = Some(Submit {
order: Order {
order_code,
@@ -1470,6 +1867,7 @@ impl TryFrom<&WorldpayxmlRouterData<&PaymentsAuthorizeRouterData>> for PaymentSe
info_threed_secure: None,
session: None,
create_token,
+ funding_transfer,
},
});
@@ -2327,6 +2725,7 @@ impl TryFrom<WorldpayxmlRouterData<&PaymentsCompleteAuthorizeRouterData>> for Pa
info_threed_secure,
session,
create_token: None,
+ funding_transfer: None,
},
})
} else {
@@ -2436,6 +2835,33 @@ impl TryFrom<WorldpayxmlRouterData<&PaymentsCompleteAuthorizeRouterData>> for Pa
None
};
+ let funding_transfer = item
+ .router_data
+ .request
+ .is_account_funded_transaction
+ .unwrap_or(false)
+ .then(|| {
+ let card_number = match &item.router_data.request.payment_method_data {
+ Some(PaymentMethodData::Card(card)) => {
+ Ok(Secret::new(card.card_number.get_card_no()))
+ }
+ _ => Err(errors::ConnectorError::NotSupported {
+ message: "account funded transactions for non-card payment methods"
+ .to_string(),
+ connector: "worldpayxml",
+ }),
+ }?;
+
+ build_worldpayxml_funding_transfer(
+ item.router_data,
+ card_number,
+ item.router_data.request.recipient_details.as_ref(),
+ item.router_data.request.business_country,
+ item.router_data.request.connector_intent_metadata.as_ref(),
+ )
+ })
+ .transpose()?;
+
Some(Submit {
order: Order {
order_code,
@@ -2450,6 +2876,7 @@ impl TryFrom<WorldpayxmlRouterData<&PaymentsCompleteAuthorizeRouterData>> for Pa
info_threed_secure: None,
session: None,
create_token,
+ funding_transfer,
},
})
};
@@ -3211,6 +3638,7 @@ impl TryFrom<&WorldpayxmlRouterData<&PayoutsRouterData<PoFulfill>>> for PaymentS
billing_address: None,
shipping_address: None,
create_token: None,
+ funding_transfer: None,
},
});
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index a6929e51a5..1fc6e04dfa 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -7854,6 +7854,7 @@ pub(crate) fn convert_setup_mandate_router_data_to_authorize_router_data(
installment_details: None,
is_account_funded_transaction: data.request.is_account_funded_transaction,
recipient_details: data.request.recipient_details.clone(),
+ business_country: data.request.business_country,
connector_intent_metadata: data.request.connector_intent_metadata.clone(),
}
}
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index a1d8d94fee..f97081eda4 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -171,6 +171,9 @@ pub struct PaymentsAuthorizeData {
/// Indicates whether this payment is an account funded transaction.
pub is_account_funded_transaction: Option<bool>,
pub recipient_details: Option<api_models::payments::RecipientDetails>,
+ /// The merchant's business country for this payment. Connectors use it for requirements that
+ /// apply only to merchants in particular countries.
+ pub business_country: Option<common_enums::CountryAlpha2>,
}
#[derive(Debug, Clone, Serialize)]
@@ -1131,6 +1134,10 @@ pub struct CompleteAuthorizeData {
pub tokenization: Option<common_enums::Tokenization>,
pub router_return_url: Option<String>,
pub merchant_order_reference_id: Option<String>,
+ pub is_account_funded_transaction: Option<bool>,
+ pub recipient_details: Option<api_models::payments::RecipientDetails>,
+ pub business_country: Option<common_enums::CountryAlpha2>,
+ pub connector_intent_metadata: Option<ConnectorMetadata>,
}
#[derive(Debug, Clone, Serialize)]
@@ -1982,6 +1989,9 @@ pub struct SetupMandateRequestData {
pub mit_category: Option<common_enums::MitCategory>,
pub is_account_funded_transaction: Option<bool>,
pub recipient_details: Option<api_models::payments::RecipientDetails>,
+ /// The merchant's business country for this payment. Connectors use it for requirements that
+ /// apply only to merchants in particular countries.
+ pub business_country: Option<common_enums::CountryAlpha2>,
}
#[derive(Debug, Clone)]
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 7391a04d1d..74b5f42adc 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -617,6 +617,10 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::ConnectorMetadata,
api_models::payments::ConnectorMetadataResponse,
api_models::payments::SantanderData,
+ api_models::payments::WorldpayxmlData,
+ api_models::payments::CheckoutData,
+ api_models::payments::WorldpayxmlFundingTransactionType,
+ api_models::payments::WorldpayxmlPaymentPurpose,
api_models::payments::FeatureMetadata,
api_models::payments::FinixAdditionalDetails,
api_models::payments::ApplepayConnectorMetadataRequest,
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 37803e17a7..eba371a2db 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -513,6 +513,10 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::ConnectorMetadata,
api_models::payments::ConnectorMetadataResponse,
api_models::payments::SantanderData,
+ api_models::payments::WorldpayxmlData,
+ api_models::payments::CheckoutData,
+ api_models::payments::WorldpayxmlFundingTransactionType,
+ api_models::payments::WorldpayxmlPaymentPurpose,
api_models::payments::FeatureMetadata,
api_models::payments::FinixAdditionalDetails,
api_models::payments::SdkType,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 5352ebc83e..9a47bf738c 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -514,6 +514,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
connector_intent_metadata: None,
is_account_funded_transaction: payment_data.payment_intent.is_account_funded_transaction,
recipient_details,
+ business_country: None,
};
let connector_mandate_request_reference_id = payment_data
.payment_attempt
@@ -1845,6 +1846,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
mit_category: None,
is_account_funded_transaction: payment_data.payment_intent.is_account_funded_transaction,
recipient_details,
+ business_country: None,
};
let connector_mandate_request_reference_id = payment_data
.payment_attempt
@@ -5281,6 +5283,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
.payment_intent
.is_account_funded_transaction,
recipient_details,
+ business_country: None,
})
}
}
@@ -5563,6 +5566,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
.payment_intent
.is_account_funded_transaction,
recipient_details,
+ business_country: payment_data.payment_intent.business_country,
})
}
}
@@ -7219,6 +7223,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
.payment_intent
.is_account_funded_transaction,
recipient_details,
+ business_country: payment_data.payment_intent.business_country,
})
}
}
@@ -7342,6 +7347,19 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
connector_name,
payment_data.clone().get_creds_identifier(),
));
+
+ let recipient_details = payment_data
+ .payment_intent
+ .get_recipient_details()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to parse recipient details")?;
+
+ let connector_intent_metadata = payment_data
+ .payment_intent
+ .get_connector_metadata_from_intent()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to parse connector metadata")?;
+
Ok(Self {
setup_future_usage: payment_data
.payment_attempt
@@ -7387,6 +7405,12 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
tokenization: payment_data.payment_intent.tokenization,
router_return_url,
merchant_order_reference_id: payment_data.payment_intent.merchant_order_reference_id,
+ is_account_funded_transaction: payment_data
+ .payment_intent
+ .is_account_funded_transaction,
+ recipient_details,
+ business_country: payment_data.payment_intent.business_country,
+ connector_intent_metadata,
})
}
}
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index c2e391a02b..368ecdfc44 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1443,6 +1443,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData {
billing_descriptor: data.request.billing_descriptor.clone(),
is_account_funded_transaction: data.request.is_account_funded_transaction,
recipient_details: data.request.recipient_details.clone(),
+ business_country: data.request.business_country,
tokenization: None,
partner_merchant_identifier_details: data
.request
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index fc9ff37d6a..bf377e9b99 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -75,6 +75,7 @@ impl VerifyConnectorData {
billing_descriptor: None,
is_account_funded_transaction: None,
recipient_details: None,
+ business_country: None,
tokenization: None,
partner_merchant_identifier_details: None,
feature_metadata: None,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index f1c8e84098..418cb9362a 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -1042,6 +1042,7 @@ impl Default for PaymentAuthorizeType {
feature_metadata: None,
installment_details: None,
connector_intent_metadata: None,
+ business_country: None,
};
Self(data)
}