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(core/connector): [SANTANDER] Implemented Boleto webhooks (#15046)

Sayak Bhattacharya492c89b827ab
diff --git a/crates/hyperswitch_connectors/src/connectors/santander.rs b/crates/hyperswitch_connectors/src/connectors/santander.rs
index e69cfc4f27..589ea8a4c0 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander.rs
@@ -1552,6 +1552,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for San
}
// No amount is sent back in Boleto response
SantanderPaymentsSyncResponse::Boleto(_)
+ | SantanderPaymentsSyncResponse::BoletoWebhook(_)
| SantanderPaymentsSyncResponse::PixAutomaticoCobrWebhook(_)
| SantanderPaymentsSyncResponse::PixQrWebhook(_)
| SantanderPaymentsSyncResponse::PixAutomaticoRecWebhook(_)
@@ -2197,6 +2198,12 @@ impl webhooks::IncomingWebhook for Santander {
PaymentIdType::ConnectorTransactionId(entry.txid.clone()),
))
}
+ SantanderWebhookBody::Boleto(boleto_data) => Ok(ObjectReferenceId::PaymentId(
+ PaymentIdType::ConnectorTransactionId(boleto_data.bank_number),
+ )),
+ SantanderWebhookBody::BoletoEndpointVerification(_) => {
+ Err(errors::ConnectorError::WebhookReferenceIdNotFound.into())
+ }
}
}
@@ -2301,6 +2308,12 @@ impl webhooks::IncomingWebhook for Santander {
}
}
}
+ // Santander's Billing API sends this notification only after a boleto
+ // has been paid; it does not include a separate payment status.
+ SantanderWebhookBody::Boleto(_) => Ok(IncomingWebhookEvent::PaymentIntentSuccess),
+ SantanderWebhookBody::BoletoEndpointVerification(_) => {
+ Ok(IncomingWebhookEvent::EndpointVerification)
+ }
}
}
@@ -2389,7 +2402,9 @@ impl webhooks::IncomingWebhook for Santander {
_ => Ok(None),
}
}
- SantanderWebhookBody::RecurringCharge(_) => Ok(None),
+ SantanderWebhookBody::RecurringCharge(_)
+ | SantanderWebhookBody::Boleto(_)
+ | SantanderWebhookBody::BoletoEndpointVerification(_) => Ok(None),
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/santander/responses.rs b/crates/hyperswitch_connectors/src/connectors/santander/responses.rs
index 6b87788547..7cd534f5a5 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander/responses.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander/responses.rs
@@ -1,5 +1,5 @@
use api_models::payments::PollConfig;
-use common_utils::types::StringMajorUnit;
+use common_utils::types::{FloatMajorUnit, StringMajorUnit};
use hyperswitch_masking::Secret;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
@@ -402,6 +402,7 @@ pub enum SantanderPaymentsSyncResponse {
PixAutomaticoRecWebhook(Box<SantanderPixAutomaticoRecWebhookBody>),
PixAutomaticoCobrSync(Box<SantanderPixAutomaticoCobrSyncResponse>),
Boleto(Box<SantanderBoletoPSyncResponse>),
+ BoletoWebhook(Box<SantanderBoletoWebhookBody>),
PixAutomaticoConsultAndActivateJourney(Box<SantanderPixAutomaticRecResponse>),
}
@@ -1019,12 +1020,66 @@ pub struct SantanderPixAutomaticoRecWebhookBody {
pub recs: Vec<SantanderPixAutomaticoRecWebhookEntry>,
}
+/// Payment notification sent by Santander's Billing API for a paid boleto.
+/// The Billing API does not include a status in this notification
+/// receiving one is itself confirmation that the boleto was paid
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderBoletoWebhookBody {
+ pub message: String,
+ #[serde(rename = "function")]
+ pub function_name: String,
+ pub payment_type: String,
+ pub issue_date: String,
+ pub payment_date: String,
+ pub bank_code: String,
+ pub payment_channel: String,
+ pub payment_kind: String,
+ pub covenant: Secret<String>,
+ pub type_of_person_agreement: String,
+ pub agreement_document: Secret<String>,
+ pub bank_number: String,
+ pub client_number: Secret<String>,
+ pub participant_code: String,
+ pub tx_id: String,
+ pub payer_document_type: String,
+ pub payer_document_number: Secret<String>,
+ pub payer_name: Secret<String>,
+ #[serde(rename = "finalBeneficiaryrDocumentType")]
+ pub final_beneficiary_document_type: String,
+ pub final_beneficiary_document_number: Secret<String>,
+ pub final_beneficiary_name: Secret<String>,
+ pub due_date: String,
+ pub nominal_value: FloatMajorUnit,
+ pub payed_value: FloatMajorUnit,
+ pub interest_value: FloatMajorUnit,
+ pub fine: FloatMajorUnit,
+ pub deduction_value: FloatMajorUnit,
+ pub rebate_value: FloatMajorUnit,
+ pub iof_value: FloatMajorUnit,
+ pub credit_date: String,
+}
+
+/// Santander posts this payload when validating a Billing API webhook URL
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct SantanderBoletoWebhookEndpointVerification {
+ pub message: SantanderBoletoWebhookEndpointVerificationMessage,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub enum SantanderBoletoWebhookEndpointVerificationMessage {
+ #[serde(rename = "Validação da URL do Webhook")]
+ UrlValidation,
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SantanderWebhookBody {
PixQr(SantanderPixQrWebhookBody),
Recurrence(SantanderPixAutomaticoRecWebhookBody),
RecurringCharge(SantanderPixAutomaticoCobrWebhookBody),
+ Boleto(Box<SantanderBoletoWebhookBody>),
+ BoletoEndpointVerification(SantanderBoletoWebhookEndpointVerification),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
index 1099b6dd85..422711f054 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
@@ -1661,6 +1661,12 @@ impl<F, T> TryFrom<ResponseRouterData<F, SantanderPaymentsSyncResponse, T, Payme
..item.data
})
}
+ // Santander's Billing API sends this notification only after the
+ // boleto is paid; unlike a boleto sync response, it has no status.
+ SantanderPaymentsSyncResponse::BoletoWebhook(_) => Ok(Self {
+ status: AttemptStatus::Charged,
+ ..item.data
+ }),
// MIT recurring charge sync (cobr endpoint consultation)
SantanderPaymentsSyncResponse::PixAutomaticoCobrSync(cobr_data) => {
let attempt_status = cobr_sync_status_to_attempt_status(&cobr_data);
diff --git a/crates/router/src/core/webhooks/gateway.rs b/crates/router/src/core/webhooks/gateway.rs
index f392165c90..c79c1040be 100644
--- a/crates/router/src/core/webhooks/gateway.rs
+++ b/crates/router/src/core/webhooks/gateway.rs
@@ -67,6 +67,7 @@ pub enum WebhookOutcome {
Skipped {
reference: Option<ObjectReferenceId>,
event_type: IncomingWebhookEvent,
+ masked_log_payload: common_utils::pii::SecretSerdeValue,
ack_response: WebhookResponse<serde_json::Value>,
},
Processed {
@@ -342,11 +343,40 @@ impl IncomingWebhookGateway for DirectIncomingWebhookGateway {
.attach_printable("Failed to build webhook ack via connector")?;
let outcome = match FilterDecision::evaluate(event_type, ctx).await {
- FilterDecision::Skip => WebhookOutcome::Skipped {
- reference,
- event_type,
- ack_response,
- },
+ FilterDecision::Skip => {
+ let masked_log_payload = if matches!(
+ event_type,
+ IncomingWebhookEvent::EndpointVerification
+ ) {
+ match ctx.connector.get_webhook_resource_object(&decoded_request) {
+ Ok(resource_object) => Secret::new(
+ resource_object.masked_serialize().unwrap_or_else(|error| {
+ logger::warn!(
+ ?error,
+ "Failed to mask-serialize endpoint-verification webhook resource object for logging"
+ );
+ serde_json::Value::Null
+ }),
+ ),
+ Err(error) => {
+ logger::warn!(
+ ?error,
+ "Failed to extract endpoint-verification webhook resource object for logging"
+ );
+ Secret::new(serde_json::Value::Null)
+ }
+ }
+ } else {
+ Secret::new(serde_json::Value::Null)
+ };
+
+ WebhookOutcome::Skipped {
+ reference,
+ event_type,
+ masked_log_payload,
+ ack_response,
+ }
+ }
FilterDecision::Proceed => {
let reference = reference.ok_or_else(|| {
error_stack::report!(errors::ApiErrorResponse::WebhookResourceNotFound)
@@ -433,6 +463,7 @@ impl IncomingWebhookGateway for UcsIncomingWebhookGateway {
FilterDecision::Skip => WebhookOutcome::Skipped {
reference,
event_type,
+ masked_log_payload: Secret::new(serde_json::Value::Null),
ack_response: WebhookResponse::StatusOk,
},
FilterDecision::Proceed => {
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index fe6e3cf88a..fb0e6352ef 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -366,6 +366,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
let (ack_response, webhook_effect, serialized_body) = match outcome {
Ok(super::gateway::WebhookOutcome::Skipped {
event_type,
+ masked_log_payload,
ack_response,
..
}) => {
@@ -380,7 +381,7 @@ async fn incoming_webhooks_core<W: types::OutgoingWebhookType>(
(
ack_response,
WebhookResponseTracker::NoEffect,
- Secret::new(serde_json::Value::Null),
+ masked_log_payload,
)
}
Ok(super::gateway::WebhookOutcome::Processed {
@@ -4080,6 +4081,7 @@ pub async fn process_uas_incoming_webhook<'a>(
return Ok(super::gateway::WebhookOutcome::Skipped {
reference: None,
event_type,
+ masked_log_payload: Secret::new(serde_json::Value::Null),
ack_response,
});
}