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(webhooks): Send back mandate amount and currency in mandate outgoing webhooks (#15038)
Sayak Bhattacharya15051894857f
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex ab6d8d6703..85c065eb15 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -27611,6 +27611,30 @@"description": "The original setup payment associated with this mandate, when known.","nullable": true},+ "amount": {+ "type": "integer",+ "format": "int64",+ "description": "The original authorized amount for the connector mandate, when known.",+ "nullable": true+ },+ "currency": {+ "allOf": [+ {+ "$ref": "#/components/schemas/Currency"+ }+ ],+ "nullable": true+ },+ "profile_id": {+ "type": "string",+ "description": "The business profile associated with this mandate event, when known.",+ "nullable": true+ },+ "mandate_metadata": {+ "type": "object",+ "description": "Connector-specific mandate metadata associated with the original setup payment.",+ "nullable": true+ },"status": {"$ref": "#/components/schemas/MandateStatus"},diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex d15d9ff914..f3727b8ee8 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -19038,6 +19038,30 @@"description": "The original setup payment associated with this mandate, when known.","nullable": true},+ "amount": {+ "type": "integer",+ "format": "int64",+ "description": "The original authorized amount for the connector mandate, when known.",+ "nullable": true+ },+ "currency": {+ "allOf": [+ {+ "$ref": "#/components/schemas/Currency"+ }+ ],+ "nullable": true+ },+ "profile_id": {+ "type": "string",+ "description": "The business profile associated with this mandate event, when known.",+ "nullable": true+ },+ "mandate_metadata": {+ "type": "object",+ "description": "Connector-specific mandate metadata associated with the original setup payment.",+ "nullable": true+ },"status": {"$ref": "#/components/schemas/MandateStatus"},diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rsindex 1b0ac0a4fc..9047773731 100644--- a/crates/api_models/src/mandates.rs+++ b/crates/api_models/src/mandates.rs@@ -43,6 +43,26 @@ pub struct MandateResponse {#[schema(value_type = Option<String>)]#[smithy(value_type = "Option<String>")]pub payment_id: Option<common_utils::id_type::PaymentId>,+ /// The original authorized amount for the connector mandate, when known.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ #[schema(value_type = Option<i64>)]+ #[smithy(value_type = "Option<i64>")]+ pub amount: Option<common_utils::types::MinorUnit>,+ /// The currency of the original authorized amount for the connector mandate, when known.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ #[schema(value_type = Option<Currency>)]+ #[smithy(value_type = "Option<Currency>")]+ pub currency: Option<api_enums::Currency>,+ /// The business profile associated with this mandate event, when known.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ #[schema(value_type = Option<String>)]+ #[smithy(value_type = "Option<String>")]+ pub profile_id: Option<common_utils::id_type::ProfileId>,+ /// Connector-specific mandate metadata associated with the original setup payment.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ #[schema(value_type = Option<Object>)]+ #[smithy(value_type = "Option<Object>")]+ pub mandate_metadata: Option<common_utils::pii::SecretSerdeValue>,/// The status for mandates#[schema(value_type = MandateStatus)]#[smithy(value_type = "MandateStatus")]diff --git a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rsindex 9b089f6c76..1a962a9cb8 100644--- a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs@@ -90,6 +90,28 @@ use crate::{type Error = error_stack::Report<errors::ConnectorError>;+fn get_pix_automatico_cit_mandate_metadata(+ feature_metadata: Option<&FeatureMetadata>,+) -> Result<Option<Secret<Value>>, Error> {+ let mandate_details = feature_metadata+ .and_then(|metadata| metadata.pix_automatico_additional_details.as_ref())+ .and_then(|pix_automatico_details| match pix_automatico_details {+ api_models::payments::PixAutomaticoAdditionalDetails::PixAutomaticoPush(push) => {+ push.mandate_details.as_ref()+ }+ api_models::payments::PixAutomaticoAdditionalDetails::PixAutomaticoQr(qr) => {+ qr.mandate_details.as_ref()+ }+ api_models::payments::PixAutomaticoAdditionalDetails::PixAutomaticoMit(_) => None,+ });++ mandate_details+ .map(|details| details.encode_to_value().map(Secret::new))+ .transpose()+ .change_context(errors::ConnectorError::ParsingFailed)+ .attach_printable("Failed to serialize Pix Automático mandate details")+}+impl<T> From<(StringMajorUnit, T)> for SantanderRouterData<T> {fn from((amount, item): (StringMajorUnit, T)) -> Self {Self {@@ -173,7 +195,9 @@ impllet mandate_reference = Some(MandateReference {connector_mandate_id: Some(item.response.id_rec.clone().expose()),payment_method_id: None,- mandate_metadata: None,+ mandate_metadata: get_pix_automatico_cit_mandate_metadata(+ item.data.request.feature_metadata.as_ref(),+ )?,connector_mandate_request_reference_id: Some(item.response.id_solic_rec.clone().expose(),),@@ -247,7 +271,9 @@ impllet mandate_reference = Box::new(Some(MandateReference {connector_mandate_id: Some(item.response.id_rec.clone().expose()),payment_method_id: None,- mandate_metadata: None,+ mandate_metadata: get_pix_automatico_cit_mandate_metadata(+ item.data.request.feature_metadata.as_ref(),+ )?,connector_mandate_request_reference_id: connector_mandate_request_reference_id.clone(),}));let connector_transaction_id = match journey.as_ref() {@@ -3000,7 +3026,9 @@ impl<F>mandate_reference: Box::new(Some(MandateReference {connector_mandate_id: Some(item.response.id_rec.expose()),payment_method_id: None,- mandate_metadata: None,+ mandate_metadata: get_pix_automatico_cit_mandate_metadata(+ item.data.request.feature_metadata.as_ref(),+ )?,connector_mandate_request_reference_id: None,})),connector_metadata: None,diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rsindex aaf0c74435..12109f878f 100644--- a/crates/hyperswitch_domain_models/src/router_request_types.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs@@ -2044,6 +2044,7 @@ impl PushNotificationRequestData {pub struct GenerateQrRequestData {pub amount: Option<i64>,pub mandate_id: Option<mandates::MandateIds>,+ pub feature_metadata: Option<api_models::payments::FeatureMetadata>,}impl MandateIdSettable for GenerateQrRequestData {@@ -2075,6 +2076,7 @@ impl TryFrom<SetupMandateRequestData> for GenerateQrRequestData {Ok(Self {amount: Some(data.amount),mandate_id: data.mandate_id,+ feature_metadata: data.feature_metadata,})}}@@ -2086,6 +2088,7 @@ impl TryFrom<PaymentsAuthorizeData> for GenerateQrRequestData {Ok(Self {amount: Some(data.amount),mandate_id: data.mandate_id,+ feature_metadata: data.feature_metadata,})}}@@ -2097,6 +2100,7 @@ impl TryFrom<PaymentsAuthenticateData> for GenerateQrRequestData {Ok(Self {amount: None,mandate_id: None,+ feature_metadata: None,})}}@@ -2108,6 +2112,7 @@ impl TryFrom<CompleteAuthorizeData> for GenerateQrRequestData {Ok(Self {amount: None,mandate_id: None,+ feature_metadata: None,})}}diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 4016f07c37..faa72beb43 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -2574,13 +2574,16 @@ async fn update_payment_method_mandate_status(let updated_mandate_details = updated_mandate_details.ok_or(errors::ApiErrorResponse::WebhookProcessingFailure).attach_printable("no updated mandate details for payment method")?;- let connector_mandate_id = updated_mandate_details+ let mandate_record = updated_mandate_details.payments.as_ref().and_then(|payments| payments.get(merchant_connector_id))- .map(|mandate_record| mandate_record.connector_mandate_id.clone()).ok_or(errors::ApiErrorResponse::WebhookProcessingFailure)- .attach_printable("connector mandate id not found for payment method mandate webhook")?;+ .attach_printable("mandate record not found for payment method mandate webhook")?;+ let connector_mandate_id = mandate_record.connector_mandate_id.clone();+ let mandate_metadata = mandate_record.mandate_metadata.clone();+ let mandate_amount = mandate_record.original_payment_authorized_amount;+ let mandate_currency = mandate_record.original_payment_authorized_currency;let connector_mandate_details_value = updated_mandate_details.get_mandate_details_value().map_err(|err| {@@ -2624,6 +2627,10 @@ async fn update_payment_method_mandate_status(let mandate_response = api::mandates::MandateResponse {mandate_id: connector_mandate_id.clone(),payment_id: Some(payment_id.clone()),+ amount: mandate_amount.map(common_utils::types::MinorUnit::new),+ currency: mandate_currency,+ profile_id: Some(business_profile.get_id().to_owned()),+ mandate_metadata,status: mandate_status,payment_method_id: payment_method_id.to_string(),payment_method: payment_method_name,diff --git a/crates/router/src/types/api/mandates.rs b/crates/router/src/types/api/mandates.rsindex c2b3c56a88..1794d5b14e 100644--- a/crates/router/src/types/api/mandates.rs+++ b/crates/router/src/types/api/mandates.rs@@ -110,6 +110,10 @@ impl MandateResponseExt for MandateResponse {Ok(Self {mandate_id: mandate.mandate_id,payment_id: mandate.original_payment_id,+ amount: None,+ currency: None,+ profile_id: None,+ mandate_metadata: None,customer_acceptance: Some(api::payments::CustomerAcceptance {acceptance_type: if mandate.customer_ip_address.is_some() {api::payments::AcceptanceType::Online