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

fix(connector): [SANTANDER] Pix and Boleto fixes (#11388)

Sayak Bhattacharya2f72996c8d02
diff --git a/Cargo.lock b/Cargo.lock
index cd1493339b..9428bee39d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -65,7 +65,7 @@ dependencies = [
"mime",
"percent-encoding",
"pin-project-lite",
- "rand 0.9.1",
+ "rand 0.9.2",
"sha1",
"smallvec 1.15.0",
"tokio 1.48.0",
@@ -739,7 +739,7 @@ dependencies = [
"mime",
"percent-encoding",
"pin-project-lite",
- "rand 0.9.1",
+ "rand 0.9.2",
"rustls 0.20.9",
"serde",
"serde_json",
@@ -2075,6 +2075,7 @@ dependencies = [
"cards",
"common_enums",
"common_utils",
+ "cpf_cnpj",
"diesel",
"error-stack 0.4.1",
"euclid",
@@ -2306,6 +2307,15 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
+[[package]]
+name = "cpf_cnpj"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3564ecde97fae9d4d28ae212e207337c0e92ee6c438930ae9b75ec3e9355a924"
+dependencies = [
+ "rand 0.9.2",
+]
+
[[package]]
name = "cpufeatures"
version = "0.2.17"
@@ -6856,7 +6866,7 @@ dependencies = [
"bytes 1.10.1",
"getrandom 0.3.3",
"lru-slab",
- "rand 0.9.1",
+ "rand 0.9.2",
"ring 0.17.14",
"rustc-hash 2.1.1",
"rustls 0.23.27",
@@ -6933,9 +6943,9 @@ dependencies = [
[[package]]
name = "rand"
-version = "0.9.1"
+version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
+checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha 0.9.0",
"rand_core 0.9.3",
@@ -9037,7 +9047,7 @@ dependencies = [
"log",
"mini-moka",
"once_cell",
- "rand 0.9.1",
+ "rand 0.9.2",
"reqwest 0.11.27",
"serde",
"serde_json",
@@ -10085,7 +10095,7 @@ dependencies = [
"base32",
"constant_time_eq",
"hmac",
- "rand 0.9.1",
+ "rand 0.9.2",
"sha1",
"sha2",
"url",
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 285c8d5746..b2e0e0e1fc 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -23977,6 +23977,11 @@
"type": "string",
"nullable": true
},
+ "raw_qr_data": {
+ "type": "string",
+ "description": "The raw QR code data (EMV copy and paste) used for Brazilian payment methods like Pix",
+ "nullable": true
+ },
"type": {
"type": "string",
"enum": [
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index f7d5bc1866..02ca594f5a 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -18188,6 +18188,11 @@
"type": "string",
"nullable": true
},
+ "raw_qr_data": {
+ "type": "string",
+ "description": "The raw QR code data (EMV copy and paste) used for Brazilian payment methods like Pix",
+ "nullable": true
+ },
"type": {
"type": "string",
"enum": [
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 9b230213ef..87e97d3f75 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -123,7 +123,9 @@ pub struct BankCodeResponse {
}
/// Passing this object creates a new customer or attaches an existing customer to the payment
-#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema, PartialEq, SmithyModel)]
+#[derive(
+ Debug, Default, serde::Deserialize, serde::Serialize, Clone, ToSchema, PartialEq, SmithyModel,
+)]
#[smithy(namespace = "com.hyperswitch.smithy.types")]
pub struct CustomerDetails {
/// The identifier for the customer.
@@ -6663,6 +6665,10 @@ pub enum NextActionData {
display_text: Option<String>,
#[smithy(value_type = "Option<String>")]
border_color: Option<String>,
+ /// The raw QR code data (EMV copy and paste) used for Brazilian payment methods like Pix
+ #[smithy(value_type = "Option<String>")]
+ #[schema(value_type = Option<String>)]
+ raw_qr_data: Option<String>,
},
/// Contains url to fetch Qr code data
FetchQrCodeInformation {
@@ -6847,6 +6853,7 @@ pub enum QrCodeInformation {
qr_code_url: Url,
display_to_timestamp: Option<i64>,
expiry_type: Option<common_enums::enums::ExpiryType>,
+ raw_qr_data: Option<String>,
},
QrDataUrl {
image_data_url: Url,
@@ -6932,6 +6939,10 @@ pub struct VoucherNextStepData {
#[schema(value_type = Option<String>)]
#[smithy(value_type = "Option<String>")]
pub qr_code_url: Option<Url>,
+ /// The raw QR code data (EMV copy and paste) used for Brazilian payment methods like Pix
+ #[smithy(value_type = "Option<String>")]
+ #[schema(value_type = Option<String>)]
+ pub raw_qr_data: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
diff --git a/crates/common_types/Cargo.toml b/crates/common_types/Cargo.toml
index 7892aa7805..2183518ae4 100644
--- a/crates/common_types/Cargo.toml
+++ b/crates/common_types/Cargo.toml
@@ -19,6 +19,7 @@ serde_json = "1.0.140"
utoipa = { version = "4.2.3", features = ["preserve_order", "preserve_path_order"] }
time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] }
error-stack = "0.4.1"
+cpf_cnpj = "0.3"
common_enums = { version = "0.1.0", path = "../common_enums" }
common_utils = { version = "0.1.0", path = "../common_utils"}
diff --git a/crates/common_types/src/customers.rs b/crates/common_types/src/customers.rs
index caaef7086e..fc1930a537 100644
--- a/crates/common_types/src/customers.rs
+++ b/crates/common_types/src/customers.rs
@@ -1,7 +1,7 @@
//! Customer related types
use common_utils::errors::ValidationError;
-use error_stack::Report;
+use cpf_cnpj::{cnpj, cpf};
use utoipa::ToSchema;
/// HashMap containing MerchantConnectorAccountId and corresponding customer id
#[cfg(feature = "v2")]
@@ -70,32 +70,25 @@ impl DocumentKind {
self,
doc_number: &str,
) -> common_utils::errors::CustomResult<(), ValidationError> {
- (doc_number.len() == common_utils::consts::CPF_LENGTH)
- .then_some(())
- .ok_or_else(|| {
- self.length_error("CPF", common_utils::consts::CPF_LENGTH, doc_number.len())
- })?;
-
- Ok(())
+ if cpf::validate(doc_number) {
+ Ok(())
+ } else {
+ Err(error_stack::Report::new(ValidationError::InvalidValue {
+ message: "Invalid CPF".to_string(),
+ }))
+ }
}
fn validate_cnpj(
self,
doc_number: &str,
) -> common_utils::errors::CustomResult<(), ValidationError> {
- (doc_number.len() == common_utils::consts::CNPJ_LENGTH)
- .then_some(())
- .ok_or_else(|| {
- self.length_error("CNPJ", common_utils::consts::CNPJ_LENGTH, doc_number.len())
- })?;
-
- Ok(())
- }
-
- fn length_error(self, name: &str, expected: usize, actual: usize) -> Report<ValidationError> {
- let message = format!("{name} document_number (expected {expected}, got {actual})");
- Report::new(ValidationError::IncorrectValueProvided {
- field_name: Box::leak(message.into_boxed_str()),
- })
+ if cnpj::validate(doc_number) {
+ Ok(())
+ } else {
+ Err(error_stack::Report::new(ValidationError::InvalidValue {
+ message: "Invalid CNPJ".to_string(),
+ }))
+ }
}
}
diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rs
index 715e18cee7..02a5d68654 100644
--- a/crates/common_utils/src/consts.rs
+++ b/crates/common_utils/src/consts.rs
@@ -229,9 +229,3 @@ pub const DEFAULT_LIST_LIMIT: i64 = 100;
/// Default offset for list operations (can be used across different entities)
pub const DEFAULT_LIST_OFFSET: i64 = 0;
-
-/// Length of CPF document number, used in Brazil commonly
-pub const CPF_LENGTH: usize = 11;
-
-/// Length of CNPJ document number, used in Brazil commonly
-pub const CNPJ_LENGTH: usize = 14;
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
index 69c5298c11..b3f803bc20 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
@@ -5013,6 +5013,7 @@ pub fn get_qr_metadata(
qr_code_url,
display_to_timestamp,
expiry_type: None,
+ raw_qr_data: None,
};
Some(qr_code_info.encode_to_value())
.transpose()
@@ -5154,6 +5155,7 @@ pub fn get_present_to_shopper_metadata(
qr_code_url: None,
barcode: None,
expiry_date: None,
+ raw_qr_data: None,
};
Some(voucher_data.encode_to_value())
diff --git a/crates/hyperswitch_connectors/src/connectors/santander/responses.rs b/crates/hyperswitch_connectors/src/connectors/santander/responses.rs
index d00ea707ee..5e93d9cd42 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander/responses.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander/responses.rs
@@ -160,7 +160,7 @@ pub struct SantanderBoletoPaymentsResponse {
pub key: Option<Key>,
pub tx_id: Option<String>,
pub messages: Option<Vec<String>>,
- pub barcode: Option<Secret<String>>,
+ pub bar_code: Option<Secret<String>>,
pub digitable_line: Option<Secret<String>>,
pub entry_date: Option<String>,
pub qr_code_pix: Option<String>,
diff --git a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
index e75bb8facd..1866c94ea9 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
@@ -943,10 +943,11 @@ impl<F, T> TryFrom<ResponseRouterData<F, SantanderPaymentsResponse, T, PaymentsR
let voucher_data = VoucherNextStepData {
digitable_line: boleto_data.digitable_line.clone(),
- barcode: boleto_data.barcode.clone(),
+ barcode: boleto_data.bar_code.clone(),
expires_at: None,
expiry_date: Some(boleto_data.due_date),
reference: boleto_data.nsu_code.clone(),
+ raw_qr_data: boleto_data.qr_code_pix.clone(),
entry_date: boleto_data.entry_date.clone(),
download_url: None,
instructions_url: None,
@@ -1150,6 +1151,7 @@ fn convert_pix_data_to_value(
qr_code_url: image_data_url,
display_to_timestamp: None,
expiry_type: variant,
+ raw_qr_data: Some(data),
};
Some(qr_code_info.encode_to_value())
diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rs
index 8c0a16e3c0..a69c97700a 100644
--- a/crates/router/src/compatibility/stripe/payment_intents/types.rs
+++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs
@@ -897,6 +897,7 @@ pub(crate) fn into_stripe_next_action(
qr_code_url,
border_color,
display_text,
+ raw_qr_data: _,
} => StripeNextAction::QrCodeInformation {
image_data_url,
display_to_timestamp,
diff --git a/crates/router/src/compatibility/stripe/setup_intents/types.rs b/crates/router/src/compatibility/stripe/setup_intents/types.rs
index c1c7f7790e..cf220bfa04 100644
--- a/crates/router/src/compatibility/stripe/setup_intents/types.rs
+++ b/crates/router/src/compatibility/stripe/setup_intents/types.rs
@@ -446,6 +446,7 @@ pub(crate) fn into_stripe_next_action(
qr_code_url,
display_text,
border_color,
+ raw_qr_data: _,
} => StripeNextAction::QrCodeInformation {
image_data_url,
display_to_timestamp,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index b3b47188bd..72b44e13b8 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -4639,12 +4639,14 @@ impl ForeignFrom<api_models::payments::QrCodeInformation> for api_models::paymen
qr_code_url,
display_to_timestamp,
expiry_type: _,
+ raw_qr_data,
} => Self::QrCodeInformation {
image_data_url: Some(image_data_url),
qr_code_url: Some(qr_code_url),
display_to_timestamp,
border_color: None,
display_text: None,
+ raw_qr_data,
},
api_models::payments::QrCodeInformation::QrDataUrl {
image_data_url,
@@ -4655,6 +4657,7 @@ impl ForeignFrom<api_models::payments::QrCodeInformation> for api_models::paymen
qr_code_url: None,
border_color: None,
display_text: None,
+ raw_qr_data: None,
},
api_models::payments::QrCodeInformation::QrCodeImageUrl {
qr_code_url,
@@ -4665,6 +4668,7 @@ impl ForeignFrom<api_models::payments::QrCodeInformation> for api_models::paymen
display_to_timestamp,
border_color: None,
display_text: None,
+ raw_qr_data: None,
},
api_models::payments::QrCodeInformation::QrColorDataUrl {
color_image_data_url,
@@ -4677,6 +4681,7 @@ impl ForeignFrom<api_models::payments::QrCodeInformation> for api_models::paymen
display_to_timestamp,
border_color,
display_text,
+ raw_qr_data: None,
},
}
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index ef5f88cb14..51d2657b2c 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -1,7 +1,8 @@
use actix_web::http::header::HeaderMap;
use api_models::{
cards_info as card_info_types, enums as api_enums, gsm as gsm_api_types, payment_methods,
- payments, routing::ConnectorSelection,
+ payments::{self, CustomerDetails},
+ routing::ConnectorSelection,
};
use common_utils::{
consts::X_HS_LATENCY,
@@ -1714,6 +1715,17 @@ impl
.or_else(|| {
customer.and_then(|cust| cust.name.as_ref().map(|n| n.clone().into_inner()))
}),
+ customer: Some(CustomerDetails {
+ name: None,
+ email: None,
+ phone: None,
+ id: None,
+ phone_country_code: None,
+ tax_registration_id: None,
+ document_details: customer_details_from_pi
+ .as_ref()
+ .and_then(|doc_details| doc_details.customer_document_details.clone()),
+ }),
..Self::default()
})
}