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
fix(connector): [trustpay] [SEPA] Consume debtor based information in webhooks (#11052)
Nithin N83ff77978a12
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 434030246a..3dcfe16d35 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -12283,7 +12283,7 @@],"properties": {"sepa": {- "type": "object"+ "$ref": "#/components/schemas/SepaBankTransferPaymentAdditionalData"}}},@@ -36998,6 +36998,35 @@}}},+ "SepaBankTransferPaymentAdditionalData": {+ "type": "object",+ "properties": {+ "debitor_iban": {+ "type": "string",+ "description": "debitor IBAN",+ "example": "DE89370400440532013000",+ "nullable": true+ },+ "debitor_bic": {+ "type": "string",+ "description": "debitor BIC",+ "example": "MARKDEF1100",+ "nullable": true+ },+ "debitor_name": {+ "type": "string",+ "description": "debitor name",+ "example": "John Doe",+ "nullable": true+ },+ "debitor_email": {+ "type": "string",+ "description": "debitor email",+ "example": "[email protected]",+ "nullable": true+ }+ }+ },"SessionToken": {"oneOf": [{diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 39369ab529..1656829274 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -8122,7 +8122,7 @@],"properties": {"sepa": {- "type": "object"+ "$ref": "#/components/schemas/SepaBankTransferPaymentAdditionalData"}}},@@ -28135,6 +28135,35 @@}}},+ "SepaBankTransferPaymentAdditionalData": {+ "type": "object",+ "properties": {+ "debitor_iban": {+ "type": "string",+ "description": "debitor IBAN",+ "example": "DE89370400440532013000",+ "nullable": true+ },+ "debitor_bic": {+ "type": "string",+ "description": "debitor BIC",+ "example": "MARKDEF1100",+ "nullable": true+ },+ "debitor_name": {+ "type": "string",+ "description": "debitor name",+ "example": "John Doe",+ "nullable": true+ },+ "debitor_email": {+ "type": "string",+ "description": "debitor email",+ "example": "[email protected]",+ "nullable": true+ }+ }+ },"SessionToken": {"oneOf": [{diff --git a/crates/api_models/src/payments/additional_info.rs b/crates/api_models/src/payments/additional_info.rsindex e26af9fc8d..35f26bcb18 100644--- a/crates/api_models/src/payments/additional_info.rs+++ b/crates/api_models/src/payments/additional_info.rs@@ -193,6 +193,31 @@ pub struct GiropayBankRedirectAdditionalData {pub country: Option<api_enums::CountryAlpha2>,}+#[derive(+ Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema, SmithyModel,+)]+#[smithy(namespace = "com.hyperswitch.smithy.types")]+pub struct SepaBankTransferPaymentAdditionalData {+ /// debitor IBAN+ #[schema(value_type = Option<String>, example = "DE89370400440532013000")]+ #[smithy(value_type = "Option<String>")]+ pub debitor_iban: Option<Secret<String>>,++ /// debitor BIC+ #[schema(value_type = Option<String>, example = "MARKDEF1100")]+ #[smithy(value_type = "Option<String>")]+ pub debitor_bic: Option<Secret<String>>,++ /// debitor name+ #[schema(value_type = Option<String>, example = "John Doe")]+ #[smithy(value_type = "Option<String>")]+ pub debitor_name: Option<Secret<String>>,++ /// debitor email+ #[schema(value_type = Option<String>, example = "[email protected]")]+ #[smithy(value_type = "Option<String>")]+ pub debitor_email: Option<Secret<String>>,+}#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema, SmithyModel,)]@@ -201,8 +226,8 @@ pub struct GiropayBankRedirectAdditionalData {pub enum BankTransferAdditionalData {#[smithy(nested_value_type)]Ach {},- #[smithy(nested_value_type)]- Sepa {},+ #[smithy(value_type = "SepaBankTransferPaymentAdditionalData")]+ Sepa(Box<SepaBankTransferPaymentAdditionalData>),#[smithy(nested_value_type)]Bacs {},#[smithy(nested_value_type)]diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 538b7e1061..c959d5c88a 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -2596,13 +2596,12 @@ impl PaymentMethod {pub fn is_additional_payment_method_data_sensitive(&self) -> bool {match self {- Self::BankRedirect => true,+ Self::BankTransfer | Self::BankRedirect => true,Self::Card| Self::CardRedirect| Self::PayLater| Self::Wallet| Self::GiftCard- | Self::BankTransfer| Self::Crypto| Self::BankDebit| Self::Rewarddiff --git a/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rsindex 50e24db3fc..c3a6e7ae11 100644--- a/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/trustpay/transformers.rs@@ -13,7 +13,10 @@ use common_utils::{use error_stack::{report, ResultExt};use hyperswitch_domain_models::{payment_method_data::{BankRedirectData, BankTransferData, Card, PaymentMethodData},- router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},+ router_data::{+ AccessToken, AdditionalPaymentMethodConnectorResponse, ConnectorAuthType,+ ConnectorResponseData, ErrorResponse, RouterData,+ },router_request_types::{BrowserInformation, PaymentsPreProcessingData, ResponseId},router_response_types::{PaymentsResponseData, PreprocessingResponseId, RedirectForm, RefundsResponseData,@@ -840,11 +843,12 @@ impl<F, T> TryFrom<ResponseRouterData<F, TrustpayPaymentsResponse, T, PaymentsRefn try_from(item: ResponseRouterData<F, TrustpayPaymentsResponse, T, PaymentsResponseData>,) -> Result<Self, Self::Error> {- let (status, error, payment_response_data) =+ let (status, error, payment_response_data, connector_response) =get_trustpay_response(item.response, item.http_code, item.data.status)?;Ok(Self {status,response: error.map_or_else(|| Ok(payment_response_data), Err),+ connector_response,..item.data})}@@ -858,6 +862,7 @@ fn handle_cards_response(enums::AttemptStatus,Option<ErrorResponse>,PaymentsResponseData,+ Option<ConnectorResponseData>,),errors::ConnectorError,> {@@ -904,7 +909,7 @@ fn handle_cards_response(authentication_data: None,charges: None,};- Ok((status, error, payment_response_data))+ Ok((status, error, payment_response_data, None))}fn handle_bank_redirects_response(@@ -914,6 +919,7 @@ fn handle_bank_redirects_response(enums::AttemptStatus,Option<ErrorResponse>,PaymentsResponseData,+ Option<ConnectorResponseData>,),errors::ConnectorError,> {@@ -933,7 +939,7 @@ fn handle_bank_redirects_response(authentication_data: None,charges: None,};- Ok((status, error, payment_response_data))+ Ok((status, error, payment_response_data, None))}fn handle_bank_redirects_error_response(@@ -945,6 +951,7 @@ fn handle_bank_redirects_error_response(enums::AttemptStatus,Option<ErrorResponse>,PaymentsResponseData,+ Option<ConnectorResponseData>,),errors::ConnectorError,> {@@ -981,7 +988,7 @@ fn handle_bank_redirects_error_response(authentication_data: None,charges: None,};- Ok((status, error, payment_response_data))+ Ok((status, error, payment_response_data, None))}fn handle_bank_redirects_sync_response(@@ -992,6 +999,7 @@ fn handle_bank_redirects_sync_response(enums::AttemptStatus,Option<ErrorResponse>,PaymentsResponseData,+ Option<ConnectorResponseData>,),errors::ConnectorError,> {@@ -1048,7 +1056,7 @@ fn handle_bank_redirects_sync_response(authentication_data: None,charges: None,};- Ok((status, error, payment_response_data))+ Ok((status, error, payment_response_data, None))}pub fn handle_webhook_response(@@ -1059,13 +1067,15 @@ pub fn handle_webhook_response(enums::AttemptStatus,Option<ErrorResponse>,PaymentsResponseData,+ Option<ConnectorResponseData>,),errors::ConnectorError,> {- let status = enums::AttemptStatus::try_from(payment_information.status)?;+ let status = enums::AttemptStatus::try_from(payment_information.status.clone())?;let error = if utils::is_payment_failure(status) {let reason_info = payment_information.status_reason_information+ .clone().unwrap_or_default();Some(ErrorResponse {code: reason_info@@ -1102,7 +1112,9 @@ pub fn handle_webhook_response(authentication_data: None,charges: None,};- Ok((status, error, payment_response_data))+ let connector_response = payment_information.get_connector_response();++ Ok((status, error, payment_response_data, connector_response))}pub fn get_trustpay_response(@@ -1114,6 +1126,7 @@ pub fn get_trustpay_response(enums::AttemptStatus,Option<ErrorResponse>,PaymentsResponseData,+ Option<ConnectorResponseData>,),errors::ConnectorError,> {@@ -2058,6 +2071,83 @@ pub struct WebhookPaymentInformation {pub status: WebhookStatus,pub amount: WebhookAmount,pub status_reason_information: Option<StatusReasonInformation>,+ // sepa direct debit fields+ #[serde(skip_serializing_if = "Option::is_none")]+ pub debtor: Option<Debtor>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub debtor_account: Option<DebtorAccount>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub debtor_agent: Option<DebtorAgent>,+ // sepa credit transfer fields+ #[serde(skip_serializing_if = "Option::is_none")]+ pub creditor: Option<Creditor>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub creditor_account: Option<CreditorAccount>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub creditor_agent: Option<CreditorAgent>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub sepa_direct_debit_information: Option<SepaDirectDebitInformation>,+}++#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct Creditor {+ pub name: Option<Secret<String>>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct CreditorAccount {+ pub iban: Option<Secret<String>>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct CreditorAgent {+ pub bic: Option<Secret<String>>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct SepaDirectDebitInformation {+ pub sequence_type: Option<String>,+ pub mandate_information: Option<MandateInformation>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct MandateInformation {+ #[serde(rename = "UMR")]+ pub umr: Option<Secret<String>>,+ pub signing_city: Option<Secret<String>>,+ pub signing_date: Option<Secret<String>>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct Debtor {+ #[serde(skip_serializing_if = "Option::is_none")]+ pub name: Option<Secret<String>>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub email: Option<Secret<String>>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub phone: Option<Secret<String>>,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub address: Option<DebtorAddress>,+}++#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct DebtorAddress {+ pub lines: Option<Vec<Secret<String>>>,+ pub city: Option<Secret<String>>,+ pub postal_code: Option<Secret<String>>,+ pub country_code: Option<Secret<String>>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct DebtorAccount {+ pub iban: Option<Secret<String>>,+}+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+#[serde(rename_all = "PascalCase")]+pub struct DebtorAgent {+ pub bic: Option<Secret<String>>,}#[derive(Debug, Serialize, Deserialize, PartialEq)]@@ -2067,6 +2157,38 @@ pub struct TrustpayWebhookResponse {pub signature: String,}+impl WebhookPaymentInformation {+ pub fn get_connector_response(&self) -> Option<ConnectorResponseData> {+ let (debitor_iban, debitor_bic, debitor_name, debitor_email) = (+ self.debtor_account+ .as_ref()+ .and_then(|acc| acc.iban.clone()),+ self.debtor_agent+ .as_ref()+ .and_then(|agent| agent.bic.clone()),+ self.debtor.as_ref().and_then(|debtor| debtor.name.clone()),+ self.debtor.as_ref().and_then(|debtor| debtor.email.clone()),+ );++ if debitor_iban.is_some()+ || debitor_bic.is_some()+ || debitor_name.is_some()+ || debitor_email.is_some()+ {+ Some(ConnectorResponseData::with_additional_payment_method_data(+ AdditionalPaymentMethodConnectorResponse::SepaBankTransfer {+ debitor_iban,+ debitor_bic,+ debitor_name,+ debitor_email,+ },+ ))+ } else {+ None+ }+ }+}+impl From<Errors> for utils::ErrorCodeAndMessage {fn from(error: Errors) -> Self {Self {diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rsindex f3e7d671ab..1ae45e214f 100644--- a/crates/hyperswitch_domain_models/src/payment_method_data.rs+++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs@@ -2267,7 +2267,15 @@ impl From<BankTransferData> for api_models::payments::additional_info::BankTransfn from(value: BankTransferData) -> Self {match value {BankTransferData::AchBankTransfer {} => Self::Ach {},- BankTransferData::SepaBankTransfer {} => Self::Sepa {},++ BankTransferData::SepaBankTransfer {} => Self::Sepa(Box::new(+ api_models::payments::additional_info::SepaBankTransferPaymentAdditionalData {+ debitor_iban: None,+ debitor_bic: None,+ debitor_name: None,+ debitor_email: None,+ },+ )),BankTransferData::BacsBankTransfer {} => Self::Bacs {},BankTransferData::MultibancoBankTransfer {} => Self::Multibanco {},BankTransferData::PermataBankTransfer {} => Self::Permata {},diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rsindex 4562685d65..c772aeca07 100644--- a/crates/hyperswitch_domain_models/src/router_data.rs+++ b/crates/hyperswitch_domain_models/src/router_data.rs@@ -731,6 +731,12 @@ pub enum AdditionalPaymentMethodConnectorResponse {ApplePay {auth_code: Option<String>,},+ SepaBankTransfer {+ debitor_iban: Option<Secret<String>>,+ debitor_bic: Option<Secret<String>>,+ debitor_name: Option<Secret<String>>,+ debitor_email: Option<Secret<String>>,+ },}#[derive(Debug, Clone, Serialize, Deserialize)]pub struct ExtendedAuthorizationResponseData {diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex de7cbb36db..e98eb2c88b 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -896,6 +896,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::additional_info::UpiAdditionalData,api_models::payments::additional_info::UpiCollectAdditionalData,api_models::payments::additional_info::WalletAdditionalDataForCard,+ api_models::payments::additional_info::SepaBankTransferPaymentAdditionalData,api_models::payments::PaymentsDynamicTaxCalculationRequest,api_models::payments::WalletResponse,api_models::payments::WalletResponseData,diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex 2f40b44378..1932561876 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -859,6 +859,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::additional_info::UpiAdditionalData,api_models::payments::additional_info::UpiCollectAdditionalData,api_models::payments::additional_info::WalletAdditionalDataForCard,+ api_models::payments::additional_info::SepaBankTransferPaymentAdditionalData,api_models::payments::WalletResponse,api_models::payments::WalletResponseData,api_models::payments::PaymentsDynamicTaxCalculationRequest,diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex a3447987dc..a726fc92f4 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -7584,6 +7584,26 @@ pub fn add_connector_response_to_additional_payment_data(details: None,interac: Some(api_models::payments::InteracPaymentMethod { customer_info }),},+ (+ api_models::payments::AdditionalPaymentData::BankTransfer { .. },+ AdditionalPaymentMethodConnectorResponse::SepaBankTransfer {+ debitor_iban,+ debitor_bic,+ debitor_name,+ debitor_email,+ },+ ) => api_models::payments::AdditionalPaymentData::BankTransfer {+ details: Some(+ api_models::payments::additional_info::BankTransferAdditionalData::Sepa(Box::new(+ api_models::payments::additional_info::SepaBankTransferPaymentAdditionalData {+ debitor_iban,+ debitor_bic,+ debitor_name,+ debitor_email,+ },+ )),+ ),+ },(api_models::payments::AdditionalPaymentData::Wallet {apple_pay,