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): [SANTANDER] Added Authorize, PSync, Void, Refund & RSync Flows for Pix QR Code Bank Transfer (#8463)

Sayak Bhattacharya28d63575e63d
diff --git a/Cargo.lock b/Cargo.lock
index fdfa2f8770..287ed77150 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3945,9 +3945,11 @@ dependencies = [
"base64 0.22.1",
"bytes 1.10.1",
"cards",
+ "chrono",
"common_enums",
"common_types",
"common_utils",
+ "crc",
"encoding_rs",
"error-stack",
"hex",
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 85223163b2..d9dace6d19 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -10999,6 +10999,7 @@
"razorpay",
"recurly",
"redsys",
+ "santander",
"shift4",
"square",
"stax",
@@ -28001,6 +28002,7 @@
"recurly",
"redsys",
"riskified",
+ "santander",
"shift4",
"signifyd",
"square",
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 0bd642c8be..8da8f56f70 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -8206,6 +8206,7 @@
"razorpay",
"recurly",
"redsys",
+ "santander",
"shift4",
"square",
"stax",
@@ -22738,6 +22739,7 @@
"recurly",
"redsys",
"riskified",
+ "santander",
"shift4",
"signifyd",
"square",
diff --git a/config/config.example.toml b/config/config.example.toml
index b6037d4e19..c781ec3705 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -828,6 +828,9 @@ apple_pay = { country = "AD,AE,AG,AL,AM,AO,AR,AT,AU,AZ,BA,BB,BD,BE,BG,BH,BI,BJ,B
credit = {country = "AU,NZ,CN,HK,IN,LK,KR,MY,SG,GB,BE,FR,DE,IT,ME,NL,PL,ES,ZA,AR,BR,CO,MX,PA,UY,US,CA", currency = "AFN,ALL,DZD,AOA,ARS,AMD,AWG,AUD,AZN,BSD,BHD,BDT,BBD,BYN,BZD,BMD,BTN,BOB,VES,BAM,BWP,BRL,BND,BGN,BIF,KHR,CAD,CVE,KYD,XAF,CLP,CNY,COP,KMF,CDF,CRC,HRK,CUP,CZK,DKK,DJF,DOP,XCD,EGP,ERN,ETB,EUR,FKP,FJD,XPF,GMD,GEL,GHS,GIP,GTQ,GNF,GYD,HTG,HNL,HKD,HUF,ISK,INR,IDR,IRR,IQD,ILS,JMD,JPY,JOD,KZT,KES,KGS,KWD,LAK,LBP,LSL,LRD,LYD,MOP,MKD,MGA,MWK,MYR,MVR,MRU,MUR,MXN,MDL,MNT,MAD,MZN,MMK,NAD,NPR,ANG,NZD,NIO,NGN,VUV,KPW,NOK,OMR,PKR,PAB,PGK,PYG,PEN,PHP,PLN,GBP,QAR,RON,RUB,RWF,SHP,SVC,WST,STN,SAR,RSD,SCR,SLL,SGD,SBD,SOS,ZAR,KRW,SSP,LKR,SDG,SRD,SZL,SEK,CHF,SYP,TWD,TJS,TZS,THB,TOP,TTD,TND,TRY,TMT,UGX,UAH,AED,USD,UYU,UZS,VND,XOF,YER,ZMW,ZWL"}
debit = {country = "AU,NZ,CN,HK,IN,LK,KR,MY,SG,GB,BE,FR,DE,IT,ME,NL,PL,ES,ZA,AR,BR,CO,MX,PA,UY,US,CA", currency = "AFN,ALL,DZD,AOA,ARS,AMD,AWG,AUD,AZN,BSD,BHD,BDT,BBD,BYN,BZD,BMD,BTN,BOB,VES,BAM,BWP,BRL,BND,BGN,BIF,KHR,CAD,CVE,KYD,XAF,CLP,CNY,COP,KMF,CDF,CRC,HRK,CUP,CZK,DKK,DJF,DOP,XCD,EGP,ERN,ETB,EUR,FKP,FJD,XPF,GMD,GEL,GHS,GIP,GTQ,GNF,GYD,HTG,HNL,HKD,HUF,ISK,INR,IDR,IRR,IQD,ILS,JMD,JPY,JOD,KZT,KES,KGS,KWD,LAK,LBP,LSL,LRD,LYD,MOP,MKD,MGA,MWK,MYR,MVR,MRU,MUR,MXN,MDL,MNT,MAD,MZN,MMK,NAD,NPR,ANG,NZD,NIO,NGN,VUV,KPW,NOK,OMR,PKR,PAB,PGK,PYG,PEN,PHP,PLN,GBP,QAR,RON,RUB,RWF,SHP,SVC,WST,STN,SAR,RSD,SCR,SLL,SGD,SBD,SOS,ZAR,KRW,SSP,LKR,SDG,SRD,SZL,SEK,CHF,SYP,TWD,TJS,TZS,THB,TOP,TTD,TND,TRY,TMT,UGX,UAH,AED,USD,UYU,UZS,VND,XOF,YER,ZMW,ZWL"}
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
[connector_customer]
connector_list = "adyen,facilitapay,gocardless,hyperswitch_vault,stax,stripe"
payout_connector_list = "nomupay,stripe,wise"
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.toml
index 7a164d5713..898a84e7db 100644
--- a/config/deployments/integration_test.toml
+++ b/config/deployments/integration_test.toml
@@ -689,6 +689,9 @@ crypto_currency = { country = "AL, AD, AT, BE, BA, BG, HR, CZ, DK, EE, FI, FR, D
[pm_filters.paystack]
eft = { country = "NG, ZA, GH, KE, CI", currency = "NGN, GHS, ZAR, KES, USD" }
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
[temp_locker_enable_config]
bluesnap.payment_method = "card"
nuvei.payment_method = "card"
diff --git a/config/deployments/production.toml b/config/deployments/production.toml
index 7c1c9960ad..f08bb64136 100644
--- a/config/deployments/production.toml
+++ b/config/deployments/production.toml
@@ -693,6 +693,9 @@ crypto_currency = { country = "AL, AD, AT, BE, BA, BG, HR, CZ, DK, EE, FI, FR, D
[pm_filters.paystack]
eft = { country = "NG, ZA, GH, KE, CI", currency = "NGN, GHS, ZAR, KES, USD" }
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
[payout_method_filters.adyenplatform]
sepa = { country = "ES,SK,AT,NL,DE,BE,FR,FI,PT,IE,EE,LT,LV,IT,CZ,DE,HU,NO,PL,SE,GB,CH" , currency = "EUR,CZK,DKK,HUF,NOK,PLN,SEK,GBP,CHF" }
diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.toml
index ea6a37308a..e48ddf3ff0 100644
--- a/config/deployments/sandbox.toml
+++ b/config/deployments/sandbox.toml
@@ -702,6 +702,9 @@ crypto_currency = { country = "AL, AD, AT, BE, BA, BG, HR, CZ, DK, EE, FI, FR, D
[pm_filters.paystack]
eft = { country = "NG, ZA, GH, KE, CI", currency = "NGN, GHS, ZAR, KES, USD" }
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
[payout_method_filters.stripe]
ach = { country = "US", currency = "USD" }
diff --git a/config/development.toml b/config/development.toml
index f9ba0a5164..d340abae6e 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -848,6 +848,9 @@ crypto_currency = { country = "AL, AD, AT, BE, BA, BG, HR, CZ, DK, EE, FI, FR, D
[pm_filters.paystack]
eft = { country = "NG, ZA, GH, KE, CI", currency = "NGN, GHS, ZAR, KES, USD" }
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
[tokenization]
stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { type = "disable_only", list = "google_pay" } }
checkout = { long_lived_token = false, payment_method = "wallet", apple_pay_pre_decrypt_flow = "network_tokenization" }
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 817d19f2ab..31ecb58bb6 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -828,6 +828,9 @@ crypto_currency = { country = "AL, AD, AT, BE, BA, BG, HR, CZ, DK, EE, FI, FR, D
[pm_filters.paystack]
eft = { country = "NG, ZA, GH, KE, CI", currency = "NGN, GHS, ZAR, KES, USD" }
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
[bank_config.online_banking_fpx]
adyen.banks = "affin_bank,agro_bank,alliance_bank,am_bank,bank_islam,bank_muamalat,bank_rakyat,bank_simpanan_nasional,cimb_bank,hong_leong_bank,hsbc_bank,kuwait_finance_house,maybank,ocbc_bank,public_bank,rhb_bank,standard_chartered_bank,uob_bank"
fiuu.banks = "affin_bank,agro_bank,alliance_bank,am_bank,bank_of_china,bank_islam,bank_muamalat,bank_rakyat,bank_simpanan_nasional,cimb_bank,hong_leong_bank,hsbc_bank,kuwait_finance_house,maybank,ocbc_bank,public_bank,rhb_bank,standard_chartered_bank,uob_bank"
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index ac0c20e6b8..2ff07472a0 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -6870,7 +6870,6 @@ pub struct AirwallexData {
/// payload required by airwallex
payload: Option<String>,
}
-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct NoonData {
/// Information about the order category that merchant wants to specify at connector level. (e.g. In Noon Payments it can take values like "pay", "food", or any other custom string set by the merchant in Noon's Dashboard)
diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs
index 51c7e82b65..58c627cca8 100644
--- a/crates/common_enums/src/connector_enums.rs
+++ b/crates/common_enums/src/connector_enums.rs
@@ -132,7 +132,7 @@ pub enum RoutableConnectors {
Recurly,
Redsys,
Riskified,
- // Santander,
+ Santander,
Shift4,
Signifyd,
Square,
@@ -293,7 +293,7 @@ pub enum Connector {
Razorpay,
Recurly,
Redsys,
- // Santander,
+ Santander,
Shift4,
Square,
Stax,
@@ -465,7 +465,7 @@ impl Connector {
| Self::Rapyd
| Self::Recurly
| Self::Redsys
- // | Self::Santander
+ | Self::Santander
| Self::Shift4
| Self::Square
| Self::Stax
@@ -627,7 +627,7 @@ impl From<RoutableConnectors> for Connector {
RoutableConnectors::Recurly => Self::Recurly,
RoutableConnectors::Redsys => Self::Redsys,
RoutableConnectors::Riskified => Self::Riskified,
- // RoutableConnectors::Santander => Self::Santander,
+ RoutableConnectors::Santander => Self::Santander,
RoutableConnectors::Shift4 => Self::Shift4,
RoutableConnectors::Signifyd => Self::Signifyd,
RoutableConnectors::Square => Self::Square,
@@ -744,7 +744,7 @@ impl TryFrom<Connector> for RoutableConnectors {
Connector::Rapyd => Ok(Self::Rapyd),
Connector::Razorpay => Ok(Self::Razorpay),
Connector::Riskified => Ok(Self::Riskified),
- // Connector::Santander => Ok(Self::Santander),
+ Connector::Santander => Ok(Self::Santander),
Connector::Shift4 => Ok(Self::Shift4),
Connector::Signifyd => Ok(Self::Signifyd),
Connector::Square => Ok(Self::Square),
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index 8784f27e66..62ad0993f0 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -441,6 +441,7 @@ impl ConnectorConfig {
Connector::Recurly => Ok(connector_data.recurly),
Connector::Redsys => Ok(connector_data.redsys),
Connector::Riskified => Ok(connector_data.riskified),
+ Connector::Santander => Ok(connector_data.santander),
Connector::Shift4 => Ok(connector_data.shift4),
Connector::Signifyd => Ok(connector_data.signifyd),
Connector::Square => Ok(connector_data.square),
diff --git a/crates/connector_configs/toml/development.toml b/crates/connector_configs/toml/development.toml
index 0ab7d9894f..7d304066f9 100644
--- a/crates/connector_configs/toml/development.toml
+++ b/crates/connector_configs/toml/development.toml
@@ -6246,4 +6246,43 @@ label="Currency"
placeholder="Enter Currency"
required=true
type="Select"
-options=[]
\ No newline at end of file
+options=[]
+
+[santander.connector_auth.BodyKey]
+api_key="Client ID"
+key1="Client Secret"
+
+[santander.metadata.pix_key]
+name="pix_key"
+label="Chave Key"
+placeholder="Enter your Chave/Pix Key"
+required=true
+type="Text"
+
+[santander.metadata.expiration_time]
+name="expiration_time"
+label="Expiration Time"
+placeholder="Enter your Pix QR Code Expiration Time"
+required=true
+type="Number"
+
+[santander.metadata.cpf]
+name="cpf"
+label="Cpf"
+placeholder="Enter your cpf number"
+required=true
+type="Text"
+
+[santander.metadata.merchant_city]
+name="merchant_city"
+label="Merchant City"
+placeholder="Enter the city the merchant is based in"
+required=true
+type="Text"
+
+[santander.metadata.merchant_name]
+name="merchant_name"
+label="Merchant Name"
+placeholder="Enter the merchant name"
+required=true
+type="Text"
\ No newline at end of file
diff --git a/crates/connector_configs/toml/production.toml b/crates/connector_configs/toml/production.toml
index d7b00a5988..aba744d778 100644
--- a/crates/connector_configs/toml/production.toml
+++ b/crates/connector_configs/toml/production.toml
@@ -4851,4 +4851,43 @@ name="acquirer_country_code"
label="Acquirer Country Code"
placeholder="Enter Acquirer Country Code"
required=false
+type="Text"
+
+[santander.connector_auth.BodyKey]
+api_key="Client ID"
+key1="Client Secret"
+
+[santander.metadata.pix_key]
+name="pix_key"
+label="Chave Key"
+placeholder="Enter your Chave/Pix Key"
+required=true
+type="Text"
+
+[santander.metadata.expiration_time]
+name="expiration_time"
+label="Expiration Time"
+placeholder="Enter your Pix QR Code Expiration Time"
+required=true
+type="Number"
+
+[santander.metadata.cpf]
+name="cpf"
+label="Cpf"
+placeholder="Enter your cpf number"
+required=true
+type="Text"
+
+[santander.metadata.merchant_city]
+name="merchant_city"
+label="Merchant City"
+placeholder="Enter the city the merchant is based in"
+required=true
+type="Text"
+
+[santander.metadata.merchant_name]
+name="merchant_name"
+label="Merchant Name"
+placeholder="Enter the merchant name"
+required=true
type="Text"
\ No newline at end of file
diff --git a/crates/connector_configs/toml/sandbox.toml b/crates/connector_configs/toml/sandbox.toml
index 49d926e859..b027876614 100644
--- a/crates/connector_configs/toml/sandbox.toml
+++ b/crates/connector_configs/toml/sandbox.toml
@@ -6220,4 +6220,43 @@ label="Currency"
placeholder="Enter Currency"
required=true
type="Select"
-options=[]
\ No newline at end of file
+options=[]
+
+[santander.connector_auth.BodyKey]
+api_key="Client ID"
+key1="Client Secret"
+
+[santander.metadata.pix_key]
+name="pix_key"
+label="Chave Key"
+placeholder="Enter your Chave/Pix Key"
+required=true
+type="Text"
+
+[santander.metadata.expiration_time]
+name="expiration_time"
+label="Expiration Time"
+placeholder="Enter your Pix QR Code Expiration Time"
+required=true
+type="Number"
+
+[santander.metadata.cpf]
+name="cpf"
+label="Cpf"
+placeholder="Enter your cpf number"
+required=true
+type="Text"
+
+[santander.metadata.merchant_city]
+name="merchant_city"
+label="Merchant City"
+placeholder="Enter the city the merchant is based in"
+required=true
+type="Text"
+
+[santander.metadata.merchant_name]
+name="merchant_name"
+label="Merchant Name"
+placeholder="Enter the merchant name"
+required=true
+type="Text"
\ No newline at end of file
diff --git a/crates/hyperswitch_connectors/Cargo.toml b/crates/hyperswitch_connectors/Cargo.toml
index 9e4996d14c..63e98299c3 100644
--- a/crates/hyperswitch_connectors/Cargo.toml
+++ b/crates/hyperswitch_connectors/Cargo.toml
@@ -18,6 +18,8 @@ dummy_connector = [
]
[dependencies]
+chrono = "0.4"
+crc = "3"
actix-web = "4.11.0"
async-trait = "0.1.88"
base64 = "0.22.1"
diff --git a/crates/hyperswitch_connectors/src/connectors/santander.rs b/crates/hyperswitch_connectors/src/connectors/santander.rs
index 6320d1ae9b..22858f75db 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander.rs
@@ -1,5 +1,9 @@
pub mod transformers;
+use std::sync::LazyLock;
+
+use base64::Engine;
+use common_enums::enums;
use common_utils::{
errors::CustomResult,
ext_traits::BytesExt,
@@ -8,7 +12,7 @@ use common_utils::{
};
use error_stack::{report, ResultExt};
use hyperswitch_domain_models::{
- router_data::{AccessToken, ConnectorAuthType, ErrorResponse, RouterData},
+ router_data::{AccessToken, ErrorResponse, RouterData},
router_flow_types::{
access_token_auth::AccessTokenAuth,
payments::{Authorize, Capture, PSync, PaymentMethodToken, Session, SetupMandate, Void},
@@ -19,10 +23,13 @@ use hyperswitch_domain_models::{
PaymentsCancelData, PaymentsCaptureData, PaymentsSessionData, PaymentsSyncData,
RefundsData, SetupMandateRequestData,
},
- router_response_types::{PaymentsResponseData, RefundsResponseData},
+ router_response_types::{
+ ConnectorInfo, PaymentMethodDetails, PaymentsResponseData, RefundsResponseData,
+ SupportedPaymentMethods, SupportedPaymentMethodsExt,
+ },
types::{
- PaymentsAuthorizeRouterData, PaymentsCaptureRouterData, PaymentsSyncRouterData,
- RefundSyncRouterData, RefundsRouterData,
+ PaymentsAuthorizeRouterData, PaymentsCancelRouterData, PaymentsCaptureRouterData,
+ PaymentsSyncRouterData, RefundSyncRouterData, RefundsRouterData,
},
};
use hyperswitch_interfaces::{
@@ -31,15 +38,20 @@ use hyperswitch_interfaces::{
ConnectorValidation,
},
configs::Connectors,
+ consts::NO_ERROR_MESSAGE,
errors,
events::connector_api_logs::ConnectorEvent,
- types::{self, Response},
+ types::{self, RefreshTokenType, Response},
webhooks,
};
-use masking::{ExposeInterface, Mask};
+use masking::{Mask, Maskable, PeekInterface};
use transformers as santander;
-use crate::{constants::headers, types::ResponseRouterData, utils};
+use crate::{
+ constants::headers,
+ types::{RefreshTokenRouterData, ResponseRouterData},
+ utils::{self as connector_utils, convert_amount, RefundsRequestData},
+};
#[derive(Clone)]
pub struct Santander {
@@ -81,7 +93,7 @@ where
&self,
req: &RouterData<Flow, Request, Response>,
_connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
let mut header = vec![(
headers::CONTENT_TYPE.to_string(),
self.get_content_type().to_string().into(),
@@ -99,9 +111,6 @@ impl ConnectorCommon for Santander {
fn get_currency_unit(&self) -> api::CurrencyUnit {
api::CurrencyUnit::Minor
- // TODO! Check connector documentation, on which unit they are processing the currency.
- // If the connector accepts amount in lower unit ( i.e cents for USD) then return api::CurrencyUnit::Minor,
- // if connector accepts amount in base unit (i.e dollars for USD) then return api::CurrencyUnit::Base
}
fn common_get_content_type(&self) -> &'static str {
@@ -112,18 +121,6 @@ impl ConnectorCommon for Santander {
connectors.santander.base_url.as_ref()
}
- fn get_auth_header(
- &self,
- auth_type: &ConnectorAuthType,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
- let auth = santander::SantanderAuthType::try_from(auth_type)
- .change_context(errors::ConnectorError::FailedToObtainAuthType)?;
- Ok(vec![(
- headers::AUTHORIZATION.to_string(),
- auth.api_key.expose().into_masked(),
- )])
- }
-
fn build_error_response(
&self,
res: Response,
@@ -137,11 +134,17 @@ impl ConnectorCommon for Santander {
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
+ let message = response
+ .detail
+ .as_ref()
+ .cloned()
+ .unwrap_or_else(|| NO_ERROR_MESSAGE.to_string());
+
Ok(ErrorResponse {
status_code: res.status_code,
- code: response.code,
- message: response.message,
- reason: response.reason,
+ code: response.status.to_string(),
+ message,
+ reason: response.detail.clone(),
attempt_status: None,
connector_transaction_id: None,
network_advice_code: None,
@@ -159,11 +162,102 @@ impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> fo
//TODO: implement sessions flow
}
-impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Santander {}
+impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Santander {
+ fn get_headers(
+ &self,
+ req: &RefreshTokenRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
+ let client_id = req.request.app_id.clone();
+
+ let client_secret = req.request.id.clone();
+
+ let creds = format!(
+ "{}:{}",
+ client_id.peek(),
+ client_secret.unwrap_or_default().peek()
+ );
+ let encoded_creds = common_utils::consts::BASE64_ENGINE.encode(creds);
+
+ let auth_string = format!("Basic {}", encoded_creds);
+ Ok(vec![
+ (
+ headers::CONTENT_TYPE.to_string(),
+ RefreshTokenType::get_content_type(self).to_string().into(),
+ ),
+ (
+ headers::AUTHORIZATION.to_string(),
+ auth_string.into_masked(),
+ ),
+ ])
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ "application/x-www-form-urlencoded"
+ }
+
+ fn get_url(
+ &self,
+ _req: &RefreshTokenRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Ok(format!(
+ "{}/oauth/token?grant_type=client_credentials",
+ connectors.santander.base_url
+ ))
+ }
+
+ fn build_request(
+ &self,
+ req: &RefreshTokenRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ let req = Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .attach_default_headers()
+ .headers(RefreshTokenType::get_headers(self, req, connectors)?)
+ .url(&RefreshTokenType::get_url(self, req, connectors)?)
+ .build(),
+ );
+ Ok(req)
+ }
+
+ fn handle_response(
+ &self,
+ data: &RefreshTokenRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<RefreshTokenRouterData, errors::ConnectorError> {
+ let response: santander::SantanderAuthUpdateResponse = res
+ .response
+ .parse_struct("santander SantanderAuthUpdateResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)
+ }
+}
impl ConnectorIntegration<SetupMandate, SetupMandateRequestData, PaymentsResponseData>
for Santander
{
+ fn build_request(
+ &self,
+ _req: &RouterData<SetupMandate, SetupMandateRequestData, PaymentsResponseData>,
+ _connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Err(
+ errors::ConnectorError::NotImplemented("Setup Mandate flow for Santander".to_string())
+ .into(),
+ )
+ }
}
impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData> for Santander {
@@ -171,7 +265,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
&self,
req: &PaymentsAuthorizeRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}
@@ -181,10 +275,14 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
fn get_url(
&self,
- _req: &PaymentsAuthorizeRouterData,
- _connectors: &Connectors,
+ req: &PaymentsAuthorizeRouterData,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Ok(format!(
+ "{}cob/{}",
+ self.base_url(connectors),
+ req.payment_id
+ ))
}
fn get_request_body(
@@ -192,14 +290,14 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
req: &PaymentsAuthorizeRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let amount = utils::convert_amount(
+ let amount = convert_amount(
self.amount_converter,
req.request.minor_amount,
req.request.currency,
)?;
let connector_router_data = santander::SantanderRouterData::from((amount, req));
- let connector_req = santander::SantanderPaymentsRequest::try_from(&connector_router_data)?;
+ let connector_req = santander::SantanderPaymentRequest::try_from(&connector_router_data)?;
Ok(RequestContent::Json(Box::new(connector_req)))
}
@@ -210,7 +308,7 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
) -> CustomResult<Option<Request>, errors::ConnectorError> {
Ok(Some(
RequestBuilder::new()
- .method(Method::Post)
+ .method(Method::Put)
.url(&types::PaymentsAuthorizeType::get_url(
self, req, connectors,
)?)
@@ -235,13 +333,30 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData
.response
.parse_struct("Santander PaymentsAuthorizeResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ let original_amount = response.value.original.clone();
+
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- RouterData::try_from(ResponseRouterData {
+
+ let response_integrity_object = connector_utils::get_authorise_integrity_object(
+ self.amount_converter,
+ original_amount,
+ enums::Currency::BRL.to_string(),
+ )?;
+
+ let new_router_data = RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
- })
+ });
+
+ new_router_data
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)
+ .map(|mut router_data| {
+ router_data.request.integrity_object = Some(response_integrity_object);
+ router_data
+ })
}
fn get_error_response(
@@ -258,7 +373,7 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for San
&self,
req: &PaymentsSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}
@@ -268,10 +383,21 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for San
fn get_url(
&self,
- _req: &PaymentsSyncRouterData,
- _connectors: &Connectors,
+ req: &PaymentsSyncRouterData,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ let connector_payment_id = req
+ .request
+ .connector_transaction_id
+ .get_connector_transaction_id()
+ .change_context(errors::ConnectorError::MissingConnectorTransactionID)?;
+
+ Ok(format!(
+ "{}{}{}",
+ self.base_url(connectors),
+ "cob/",
+ connector_payment_id
+ ))
}
fn build_request(
@@ -295,17 +421,33 @@ impl ConnectorIntegration<PSync, PaymentsSyncData, PaymentsResponseData> for San
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<PaymentsSyncRouterData, errors::ConnectorError> {
- let response: santander::SantanderPaymentsResponse = res
+ let response: santander::SantanderPaymentsSyncResponse = res
.response
- .parse_struct("santander PaymentsSyncResponse")
+ .parse_struct("santander SantanderPaymentsSyncResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ let original_amount = response.value.original.clone();
+
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- RouterData::try_from(ResponseRouterData {
+
+ let response_integrity_object = connector_utils::get_sync_integrity_object(
+ self.amount_converter,
+ original_amount,
+ enums::Currency::BRL.to_string(),
+ )?;
+
+ let new_router_data = RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
- })
+ });
+
+ new_router_data
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)
+ .map(|mut router_data| {
+ router_data.request.integrity_object = Some(response_integrity_object);
+ router_data
+ })
}
fn get_error_response(
@@ -322,7 +464,7 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
&self,
req: &PaymentsCaptureRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}
@@ -335,7 +477,11 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
_req: &PaymentsCaptureRouterData,
_connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ Err(errors::ConnectorError::FlowNotSupported {
+ flow: "Capture".to_string(),
+ connector: "Santander".to_string(),
+ }
+ .into())
}
fn get_request_body(
@@ -343,7 +489,11 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
_req: &PaymentsCaptureRouterData,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into())
+ Err(errors::ConnectorError::FlowNotSupported {
+ flow: "Capture".to_string(),
+ connector: "Santander".to_string(),
+ }
+ .into())
}
fn build_request(
@@ -394,14 +544,93 @@ impl ConnectorIntegration<Capture, PaymentsCaptureData, PaymentsResponseData> fo
}
}
-impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Santander {}
+impl ConnectorIntegration<Void, PaymentsCancelData, PaymentsResponseData> for Santander {
+ fn get_headers(
+ &self,
+ req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
+ self.build_headers(req, connectors)
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ self.common_get_content_type()
+ }
+
+ fn get_url(
+ &self,
+ req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ let connector_payment_id = req.request.connector_transaction_id.clone();
+ Ok(format!(
+ "{}cob/{}",
+ self.base_url(connectors),
+ connector_payment_id
+ ))
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PaymentsCancelRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = santander::SantanderPaymentsCancelRequest::try_from(req)?;
+ Ok(RequestContent::Json(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &PaymentsCancelRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ Ok(Some(
+ RequestBuilder::new()
+ .method(Method::Patch)
+ .url(&types::PaymentsVoidType::get_url(self, req, connectors)?)
+ .attach_default_headers()
+ .headers(types::PaymentsVoidType::get_headers(self, req, connectors)?)
+ .set_body(types::PaymentsVoidType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ ))
+ }
+
+ fn handle_response(
+ &self,
+ data: &PaymentsCancelRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsCancelRouterData, errors::ConnectorError> {
+ let response: santander::SantanderVoidResponse = res
+ .response
+ .parse_struct("Santander PaymentsResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+ RouterData::try_from(ResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ })
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ self.build_error_response(res, event_builder)
+ }
+}
impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Santander {
fn get_headers(
&self,
req: &RefundsRouterData<Execute>,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}
@@ -411,10 +640,28 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Santand
fn get_url(
&self,
- _req: &RefundsRouterData<Execute>,
- _connectors: &Connectors,
+ req: &RefundsRouterData<Execute>,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ let end_to_end_id = req
+ .request
+ .connector_metadata
+ .as_ref()
+ .and_then(|metadata| metadata.get("end_to_end_id"))
+ .and_then(|val| val.as_str().map(|id| id.to_string()))
+ .ok_or_else(|| errors::ConnectorError::MissingRequiredField {
+ field_name: "end_to_end_id",
+ })?;
+
+ let refund_id = req.request.connector_refund_id.clone();
+ Ok(format!(
+ "{}{}{}{}{:?}",
+ self.base_url(connectors),
+ "pix/",
+ end_to_end_id,
+ "/refund/",
+ refund_id
+ ))
}
fn get_request_body(
@@ -422,7 +669,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Santand
req: &RefundsRouterData<Execute>,
_connectors: &Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let refund_amount = utils::convert_amount(
+ let refund_amount = convert_amount(
self.amount_converter,
req.request.minor_refund_amount,
req.request.currency,
@@ -439,7 +686,7 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Santand
connectors: &Connectors,
) -> CustomResult<Option<Request>, errors::ConnectorError> {
let request = RequestBuilder::new()
- .method(Method::Post)
+ .method(Method::Put)
.url(&types::RefundExecuteType::get_url(self, req, connectors)?)
.attach_default_headers()
.headers(types::RefundExecuteType::get_headers(
@@ -458,17 +705,34 @@ impl ConnectorIntegration<Execute, RefundsData, RefundsResponseData> for Santand
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<RefundsRouterData<Execute>, errors::ConnectorError> {
- let response: santander::RefundResponse = res
+ let response: santander::SantanderRefundResponse = res
.response
.parse_struct("santander RefundResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ let original_amount = response.value.clone();
+
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- RouterData::try_from(ResponseRouterData {
+
+ let response_integrity_object = connector_utils::get_refund_integrity_object(
+ self.amount_converter,
+ original_amount,
+ enums::Currency::BRL.to_string(),
+ )?;
+
+ let new_router_data = RouterData::try_from(ResponseRouterData {
response,
data: data.clone(),
http_code: res.status_code,
- })
+ });
+
+ new_router_data
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)
+ .map(|mut router_data| {
+ router_data.request.integrity_object = Some(response_integrity_object);
+ router_data
+ })
}
fn get_error_response(
@@ -485,7 +749,7 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Santander
&self,
req: &RefundSyncRouterData,
connectors: &Connectors,
- ) -> CustomResult<Vec<(String, masking::Maskable<String>)>, errors::ConnectorError> {
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
self.build_headers(req, connectors)
}
@@ -495,10 +759,28 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Santander
fn get_url(
&self,
- _req: &RefundSyncRouterData,
- _connectors: &Connectors,
+ req: &RefundSyncRouterData,
+ connectors: &Connectors,
) -> CustomResult<String, errors::ConnectorError> {
- Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into())
+ let connector_metadata = req.request.connector_metadata.clone();
+ let end_to_end_id = match &connector_metadata {
+ Some(metadata) => match metadata.get("end_to_end_id") {
+ Some(val) => val.as_str().map(|id| id.to_string()),
+ None => None,
+ },
+ None => None,
+ }
+ .ok_or_else(|| errors::ConnectorError::MissingRequiredField {
+ field_name: "end_to_end_id",
+ })?;
+ Ok(format!(
+ "{}{}{}{}{}",
+ self.base_url(connectors),
+ "pix/",
+ end_to_end_id,
+ "/return/",
+ req.request.get_connector_refund_id()?
+ ))
}
fn build_request(
@@ -525,7 +807,7 @@ impl ConnectorIntegration<RSync, RefundsData, RefundsResponseData> for Santander
event_builder: Option<&mut ConnectorEvent>,
res: Response,
) -> CustomResult<RefundSyncRouterData, errors::ConnectorError> {
- let response: santander::RefundResponse = res
+ let response: santander::SantanderRefundResponse = res
.response
.parse_struct("santander RefundSyncResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
@@ -571,4 +853,45 @@ impl webhooks::IncomingWebhook for Santander {
}
}
-impl ConnectorSpecifications for Santander {}
+static SANTANDER_SUPPORTED_PAYMENT_METHODS: LazyLock<SupportedPaymentMethods> =
+ LazyLock::new(|| {
+ let supported_capture_methods = vec![enums::CaptureMethod::Automatic];
+
+ let mut santander_supported_payment_methods = SupportedPaymentMethods::new();
+
+ santander_supported_payment_methods.add(
+ enums::PaymentMethod::BankTransfer,
+ enums::PaymentMethodType::Pix,
+ PaymentMethodDetails {
+ mandates: enums::FeatureStatus::NotSupported,
+ refunds: enums::FeatureStatus::Supported,
+ supported_capture_methods,
+ specific_features: None,
+ },
+ );
+
+ santander_supported_payment_methods
+ });
+
+static SANTANDER_CONNECTOR_INFO: ConnectorInfo = ConnectorInfo {
+ display_name: "Santander",
+ description:
+ "Santander is a leading private bank in Brazil, offering a wide range of financial services across retail and corporate segments. It is part of the global Santander Group, one of Europe’s largest financial institutions.",
+ connector_type: enums::PaymentConnectorCategory::PaymentGateway,
+};
+
+static SANTANDER_SUPPORTED_WEBHOOK_FLOWS: [enums::EventClass; 0] = [];
+
+impl ConnectorSpecifications for Santander {
+ fn get_connector_about(&self) -> Option<&'static ConnectorInfo> {
+ Some(&SANTANDER_CONNECTOR_INFO)
+ }
+
+ fn get_supported_payment_methods(&self) -> Option<&'static SupportedPaymentMethods> {
+ Some(&*SANTANDER_SUPPORTED_PAYMENT_METHODS)
+ }
+
+ fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
+ Some(&SANTANDER_SUPPORTED_WEBHOOK_FLOWS)
+ }
+}
diff --git a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
index 2a8831625b..d5df661a30 100644
--- a/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/santander/transformers.rs
@@ -1,31 +1,51 @@
+use api_models::payments::QrCodeInformation;
+use chrono::Utc;
use common_enums::enums;
-use common_utils::types::StringMajorUnit;
+use common_utils::{
+ errors::CustomResult,
+ ext_traits::Encode,
+ types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
+};
+use crc::{Algorithm, Crc};
+use error_stack::ResultExt;
use hyperswitch_domain_models::{
- payment_method_data::PaymentMethodData,
- router_data::{ConnectorAuthType, RouterData},
- router_flow_types::refunds::{Execute, RSync},
+ payment_method_data::{BankTransferData, PaymentMethodData},
+ router_data::{AccessToken, ConnectorAuthType, RouterData},
router_request_types::ResponseId,
router_response_types::{PaymentsResponseData, RefundsResponseData},
- types::{PaymentsAuthorizeRouterData, RefundsRouterData},
+ types::{PaymentsAuthorizeRouterData, PaymentsCancelRouterData, RefundsRouterData},
};
use hyperswitch_interfaces::errors;
-use masking::Secret;
+use masking::{ExposeInterface, Secret};
use serde::{Deserialize, Serialize};
+use serde_json::Value;
+use time::OffsetDateTime;
+use url::Url;
use crate::{
types::{RefundsResponseRouterData, ResponseRouterData},
- utils::PaymentsAuthorizeRequestData,
+ utils::{self as connector_utils, QrImage, RouterData as _},
+};
+const CRC_16_CCITT_FALSE: Algorithm<u16> = Algorithm {
+ width: 16,
+ poly: 0x1021,
+ init: 0xFFFF,
+ refin: false,
+ refout: false,
+ xorout: 0x0000,
+ check: 0x29B1,
+ residue: 0x0000,
};
-//TODO: Fill the struct with respective fields
+type Error = error_stack::Report<errors::ConnectorError>;
+
pub struct SantanderRouterData<T> {
- pub amount: StringMajorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc.
+ pub amount: StringMajorUnit,
pub router_data: T,
}
impl<T> From<(StringMajorUnit, T)> for SantanderRouterData<T> {
fn from((amount, item): (StringMajorUnit, T)) -> Self {
- //Todo : use utils to convert the amount to the type of amount that a connector accepts
Self {
amount,
router_data: item,
@@ -33,11 +53,95 @@ impl<T> From<(StringMajorUnit, T)> for SantanderRouterData<T> {
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Serialize, PartialEq)]
-pub struct SantanderPaymentsRequest {
- amount: StringMajorUnit,
- card: SantanderCard,
+#[derive(Debug, Default, Serialize, Deserialize)]
+pub struct SantanderMetadataObject {
+ pub pix_key: Secret<String>,
+ pub expiration_time: i32,
+ pub cpf: Secret<String>,
+ pub merchant_city: String,
+ pub merchant_name: String,
+}
+
+impl TryFrom<&Option<common_utils::pii::SecretSerdeValue>> for SantanderMetadataObject {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ meta_data: &Option<common_utils::pii::SecretSerdeValue>,
+ ) -> Result<Self, Self::Error> {
+ let metadata = connector_utils::to_connector_meta_from_secret::<Self>(meta_data.clone())
+ .change_context(errors::ConnectorError::InvalidConnectorConfig {
+ config: "metadata",
+ })?;
+ Ok(metadata)
+ }
+}
+
+pub fn format_emv_field(id: &str, value: &str) -> String {
+ format!("{id}{:02}{value}", value.len())
+}
+
+pub fn generate_emv_string(
+ payload_url: &str,
+ merchant_name: &str,
+ merchant_city: &str,
+ amount: Option<&str>,
+ txid: Option<&str>,
+) -> String {
+ let mut emv = String::new();
+
+ // 00: Payload Format Indicator
+ emv += &format_emv_field("00", "01");
+ // 01: Point of Initiation Method (dynamic)
+ emv += &format_emv_field("01", "12");
+
+ // 26: Merchant Account Info
+ let gui = format_emv_field("00", "br.gov.bcb.pix");
+ let url = format_emv_field("25", payload_url);
+ let merchant_account_info = format_emv_field("26", &(gui + &url));
+ emv += &merchant_account_info;
+
+ // 52: Merchant Category Code (0000)
+ emv += &format_emv_field("52", "0000");
+ // 53: Currency Code (986 for BRL)
+ emv += &format_emv_field("53", "986");
+
+ // 54: Amount (optional)
+ if let Some(amount) = amount {
+ emv += &format_emv_field("54", amount);
+ }
+
+ // 58: Country Code (BR)
+ emv += &format_emv_field("58", "BR");
+ // 59: Merchant Name
+ emv += &format_emv_field("59", merchant_name);
+ // 60: Merchant City
+ emv += &format_emv_field("60", merchant_city);
+
+ // 62: Additional Data Field Template (optional TXID)
+ if let Some(txid) = txid {
+ let reference = format_emv_field("05", txid);
+ emv += &format_emv_field("62", &reference);
+ }
+
+ // Placeholder for CRC (we need to calculate this last)
+ emv += "6304";
+
+ // Compute CRC16-CCITT (False) checksum
+ let crc = Crc::<u16>::new(&CRC_16_CCITT_FALSE);
+ let checksum = crc.checksum(emv.as_bytes());
+ emv += &format!("{:04X}", checksum);
+
+ emv
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct SantanderAuthUpdateResponse {
+ #[serde(rename = "camelCase")]
+ pub refresh_url: String,
+ pub token_type: String,
+ pub client_id: String,
+ pub access_token: Secret<String>,
+ pub scopes: String,
+ pub expires_in: i64,
}
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
@@ -49,73 +153,308 @@ pub struct SantanderCard {
complete: bool,
}
-impl TryFrom<&SantanderRouterData<&PaymentsAuthorizeRouterData>> for SantanderPaymentsRequest {
+pub struct SantanderAuthType {
+ pub(super) _api_key: Secret<String>,
+ pub(super) _key1: Secret<String>,
+}
+
+impl TryFrom<&ConnectorAuthType> for SantanderAuthType {
type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
+ match auth_type {
+ ConnectorAuthType::BodyKey { api_key, key1 } => Ok(Self {
+ _api_key: api_key.to_owned(),
+ _key1: key1.to_owned(),
+ }),
+ _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
+ }
+ }
+}
+
+impl<F, T> TryFrom<ResponseRouterData<F, SantanderAuthUpdateResponse, T, AccessToken>>
+ for RouterData<F, T, AccessToken>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<F, SantanderAuthUpdateResponse, T, AccessToken>,
+ ) -> Result<Self, Self::Error> {
+ Ok(Self {
+ response: Ok(AccessToken {
+ token: item.response.access_token,
+ expires: item.response.expires_in,
+ }),
+ ..item.data
+ })
+ }
+}
+
+impl TryFrom<&SantanderRouterData<&PaymentsAuthorizeRouterData>> for SantanderPaymentRequest {
+ type Error = Error;
fn try_from(
item: &SantanderRouterData<&PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
+ if item.router_data.request.capture_method != Some(enums::CaptureMethod::Automatic) {
+ return Err(errors::ConnectorError::FlowNotSupported {
+ flow: format!("{:?}", item.router_data.request.capture_method),
+ connector: "Santander".to_string(),
+ }
+ .into());
+ }
match item.router_data.request.payment_method_data.clone() {
- PaymentMethodData::Card(req_card) => {
- let card = SantanderCard {
- number: req_card.card_number,
- expiry_month: req_card.card_exp_month,
- expiry_year: req_card.card_exp_year,
- cvc: req_card.card_cvc,
- complete: item.router_data.request.is_auto_capture()?,
- };
- Ok(Self {
- amount: item.amount.clone(),
- card,
- })
+ PaymentMethodData::BankTransfer(ref bank_transfer_data) => {
+ Self::try_from((item, bank_transfer_data.as_ref()))
}
- _ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()),
+ _ => Err(errors::ConnectorError::NotImplemented(
+ crate::utils::get_unimplemented_payment_method_error_message("Santander"),
+ ))?,
}
}
}
-//TODO: Fill the struct with respective fields
-// Auth Struct
-pub struct SantanderAuthType {
- pub(super) api_key: Secret<String>,
-}
+impl
+ TryFrom<(
+ &SantanderRouterData<&PaymentsAuthorizeRouterData>,
+ &BankTransferData,
+ )> for SantanderPaymentRequest
+{
+ type Error = Error;
+ fn try_from(
+ value: (
+ &SantanderRouterData<&PaymentsAuthorizeRouterData>,
+ &BankTransferData,
+ ),
+ ) -> Result<Self, Self::Error> {
+ let santander_mca_metadata =
+ SantanderMetadataObject::try_from(&value.0.router_data.connector_meta_data)?;
-impl TryFrom<&ConnectorAuthType> for SantanderAuthType {
- type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(auth_type: &ConnectorAuthType) -> Result<Self, Self::Error> {
- match auth_type {
- ConnectorAuthType::HeaderKey { api_key } => Ok(Self {
- api_key: api_key.to_owned(),
- }),
- _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()),
- }
+ let debtor = SantanderDebtor {
+ cpf: santander_mca_metadata.cpf.clone(),
+ name: value.0.router_data.get_billing_full_name()?,
+ };
+
+ Ok(Self {
+ calender: SantanderCalendar {
+ creation: Utc::now().to_rfc3339(),
+ expiration: santander_mca_metadata.expiration_time,
+ },
+ debtor,
+ value: SantanderValue {
+ original: value.0.amount.to_owned(),
+ },
+ key: santander_mca_metadata.pix_key.clone(),
+ request_payer: value.0.router_data.request.statement_descriptor.clone(),
+ additional_info: None,
+ })
}
}
-// PaymentsResponse
-//TODO: Append the remaining status flags
-#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
-#[serde(rename_all = "lowercase")]
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderPaymentRequest {
+ #[serde(rename = "calendario")]
+ pub calender: SantanderCalendar,
+ #[serde(rename = "devedor")]
+ pub debtor: SantanderDebtor,
+ #[serde(rename = "valor")]
+ pub value: SantanderValue,
+ #[serde(rename = "chave")]
+ pub key: Secret<String>,
+ #[serde(rename = "solicitacaoPagador")]
+ pub request_payer: Option<String>,
+ #[serde(rename = "infoAdicionais")]
+ pub additional_info: Option<Vec<SantanderAdditionalInfo>>,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderPixQRPaymentRequest {
+ #[serde(rename = "calendario")]
+ pub calender: SantanderCalendar,
+ #[serde(rename = "devedor")]
+ pub debtor: Option<SantanderDebtor>,
+ #[serde(rename = "valor")]
+ pub value: SantanderValue,
+ #[serde(rename = "chave")]
+ pub key: Secret<String>,
+ #[serde(rename = "solicitacaoPagador")]
+ pub request_payer: Option<String>,
+ #[serde(rename = "infoAdicionais")]
+ pub additional_info: Option<Vec<SantanderAdditionalInfo>>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderDebtor {
+ pub cpf: Secret<String>,
+ #[serde(rename = "nome")]
+ pub name: Secret<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderValue {
+ pub original: StringMajorUnit,
+}
+
+#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderAdditionalInfo {
+ #[serde(rename = "nome")]
+ pub name: String,
+ #[serde(rename = "valor")]
+ pub value: String,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum SantanderPaymentStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
+ Active,
+ Completed,
+ RemovedByReceivingUser,
+ RemovedByPSP,
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
+pub enum SantanderVoidStatus {
+ RemovedByReceivingUser,
}
impl From<SantanderPaymentStatus> for common_enums::AttemptStatus {
fn from(item: SantanderPaymentStatus) -> Self {
match item {
- SantanderPaymentStatus::Succeeded => Self::Charged,
- SantanderPaymentStatus::Failed => Self::Failure,
- SantanderPaymentStatus::Processing => Self::Authorizing,
+ SantanderPaymentStatus::Active => Self::Authorizing,
+ SantanderPaymentStatus::Completed => Self::Charged,
+ SantanderPaymentStatus::RemovedByReceivingUser
+ | SantanderPaymentStatus::RemovedByPSP => Self::Failure,
}
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SantanderPaymentsResponse {
- status: SantanderPaymentStatus,
- id: String,
+ #[serde(rename = "calendario")]
+ pub calendar: SantanderCalendar,
+ #[serde(rename = "txid")]
+ pub transaction_id: String,
+ #[serde(rename = "revisao")]
+ pub revision: i32,
+ #[serde(rename = "devedor")]
+ pub debtor: Option<SantanderDebtor>,
+ pub location: Option<String>,
+ pub status: SantanderPaymentStatus,
+ #[serde(rename = "valor")]
+ pub value: SantanderValue,
+ #[serde(rename = "chave")]
+ pub key: Secret<String>,
+ #[serde(rename = "solicitacaoPagador")]
+ pub request_payer: Option<String>,
+ #[serde(rename = "infoAdicionais")]
+ pub additional_info: Option<Vec<SantanderAdditionalInfo>>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderVoidResponse {
+ #[serde(rename = "calendario")]
+ pub calendar: SantanderCalendar,
+ #[serde(rename = "txid")]
+ pub transaction_id: String,
+ #[serde(rename = "revisao")]
+ pub revision: i32,
+ #[serde(rename = "devedor")]
+ pub debtor: Option<SantanderDebtor>,
+ pub location: Option<String>,
+ pub status: SantanderPaymentStatus,
+ #[serde(rename = "valor")]
+ pub value: SantanderValue,
+ #[serde(rename = "chave")]
+ pub key: Secret<String>,
+ #[serde(rename = "solicitacaoPagador")]
+ pub request_payer: Option<String>,
+ #[serde(rename = "infoAdicionais")]
+ pub additional_info: Option<Vec<SantanderAdditionalInfo>>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub struct SantanderCalendar {
+ #[serde(rename = "calendario")]
+ pub creation: String,
+ #[serde(rename = "expiracao")]
+ pub expiration: i32,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub struct SantanderPaymentsSyncResponse {
+ pub status: SantanderPaymentStatus,
+ pub pix: Vec<SantanderPix>,
+ #[serde(rename = "calendario")]
+ pub calendar: SantanderCalendar,
+ #[serde(rename = "devedor")]
+ pub debtor: Option<SantanderDebtor>,
+ #[serde(rename = "valor")]
+ pub value: SantanderValue,
+ #[serde(rename = "chave")]
+ pub key: Secret<String>,
+ #[serde(rename = "solicitacaoPagador")]
+ pub request_payer: Option<String>,
+ #[serde(rename = "infoAdicionais")]
+ pub additional_info: Option<Vec<SantanderAdditionalInfo>>,
+ #[serde(rename = "txid")]
+ pub transaction_id: String,
+ #[serde(rename = "revisao")]
+ pub revision: i32,
+ pub location: Option<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderPix {
+ pub end_to_end_id: Secret<String>,
+ #[serde(rename = "txid")]
+ pub transaction_id: Secret<String>,
+ #[serde(rename = "valor")]
+ pub value: String,
+ #[serde(rename = "horario")]
+ pub time: String,
+ #[serde(rename = "infoPagador")]
+ pub info_payer: Option<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderPaymentsCancelRequest {
+ pub status: Option<SantanderVoidStatus>,
+}
+
+impl<F, T> TryFrom<ResponseRouterData<F, SantanderPaymentsSyncResponse, T, PaymentsResponseData>>
+ for RouterData<F, T, PaymentsResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<F, SantanderPaymentsSyncResponse, T, PaymentsResponseData>,
+ ) -> Result<Self, Self::Error> {
+ let response = item.response.clone();
+ let connector_metadata = response.pix.first().map(|pix| {
+ serde_json::json!({
+ "end_to_end_id": pix.end_to_end_id.clone().expose()
+ })
+ });
+ Ok(Self {
+ status: common_enums::AttemptStatus::from(item.response.status),
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(response.transaction_id.clone()),
+ redirection_data: Box::new(None),
+ mandate_reference: Box::new(None),
+ connector_metadata,
+ network_txn_id: None,
+ connector_response_reference_id: None,
+ incremental_authorization_allowed: None,
+ charges: None,
+ }),
+ ..item.data
+ })
+ }
}
impl<F, T> TryFrom<ResponseRouterData<F, SantanderPaymentsResponse, T, PaymentsResponseData>>
@@ -125,13 +464,39 @@ impl<F, T> TryFrom<ResponseRouterData<F, SantanderPaymentsResponse, T, PaymentsR
fn try_from(
item: ResponseRouterData<F, SantanderPaymentsResponse, T, PaymentsResponseData>,
) -> Result<Self, Self::Error> {
+ let response = item.response.clone();
+ Ok(Self {
+ status: common_enums::AttemptStatus::from(item.response.status.clone()),
+ response: Ok(PaymentsResponseData::TransactionResponse {
+ resource_id: ResponseId::ConnectorTransactionId(response.transaction_id.clone()),
+ redirection_data: Box::new(None),
+ mandate_reference: Box::new(None),
+ connector_metadata: get_qr_code_data(&item)?,
+ network_txn_id: None,
+ connector_response_reference_id: None,
+ incremental_authorization_allowed: None,
+ charges: None,
+ }),
+ ..item.data
+ })
+ }
+}
+
+impl<F, T> TryFrom<ResponseRouterData<F, SantanderVoidResponse, T, PaymentsResponseData>>
+ for RouterData<F, T, PaymentsResponseData>
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(
+ item: ResponseRouterData<F, SantanderVoidResponse, T, PaymentsResponseData>,
+ ) -> Result<Self, Self::Error> {
+ let response = item.response.clone();
Ok(Self {
status: common_enums::AttemptStatus::from(item.response.status),
response: Ok(PaymentsResponseData::TransactionResponse {
- resource_id: ResponseId::ConnectorTransactionId(item.response.id),
+ resource_id: ResponseId::ConnectorTransactionId(response.transaction_id.clone()),
redirection_data: Box::new(None),
mandate_reference: Box::new(None),
- connector_metadata: None,
+ connector_metadata: *Box::new(None),
network_txn_id: None,
connector_response_reference_id: None,
incremental_authorization_allowed: None,
@@ -142,75 +507,143 @@ impl<F, T> TryFrom<ResponseRouterData<F, SantanderPaymentsResponse, T, PaymentsR
}
}
-//TODO: Fill the struct with respective fields
-// REFUND :
-// Type definition for RefundRequest
+impl TryFrom<&PaymentsCancelRouterData> for SantanderPaymentsCancelRequest {
+ type Error = Error;
+ fn try_from(_item: &PaymentsCancelRouterData) -> Result<Self, Self::Error> {
+ Ok(Self {
+ status: Some(SantanderVoidStatus::RemovedByReceivingUser),
+ })
+ }
+}
+
+fn get_qr_code_data<F, T>(
+ item: &ResponseRouterData<F, SantanderPaymentsResponse, T, PaymentsResponseData>,
+) -> CustomResult<Option<Value>, errors::ConnectorError> {
+ let santander_mca_metadata = SantanderMetadataObject::try_from(&item.data.connector_meta_data)?;
+
+ let response = item.response.clone();
+ let expiration_time = item.response.calendar.expiration;
+
+ let expiration_i64 = i64::from(expiration_time);
+
+ let rfc3339_expiry = (OffsetDateTime::now_utc() + time::Duration::seconds(expiration_i64))
+ .format(&time::format_description::well_known::Rfc3339)
+ .map_err(|_| errors::ConnectorError::ResponseHandlingFailed)?;
+
+ let qr_expiration_duration = OffsetDateTime::parse(
+ rfc3339_expiry.as_str(),
+ &time::format_description::well_known::Rfc3339,
+ )
+ .map_err(|_| errors::ConnectorError::ResponseHandlingFailed)?
+ .unix_timestamp()
+ * 1000;
+
+ let merchant_city = santander_mca_metadata.merchant_city.as_str();
+
+ let merchant_name = santander_mca_metadata.merchant_name.as_str();
+
+ let payload_url = if let Some(location) = response.location {
+ location
+ } else {
+ return Err(errors::ConnectorError::ResponseHandlingFailed)?;
+ };
+
+ let amount_i64 = StringMajorUnitForConnector
+ .convert_back(response.value.original, enums::Currency::BRL)
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)?
+ .get_amount_as_i64();
+
+ let amount_string = amount_i64.to_string();
+ let amount = amount_string.as_str();
+
+ let dynamic_pix_code = generate_emv_string(
+ payload_url.as_str(),
+ merchant_name,
+ merchant_city,
+ Some(amount),
+ Some(response.transaction_id.as_str()),
+ );
+
+ let image_data = QrImage::new_from_data(dynamic_pix_code.clone())
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)?;
+
+ let image_data_url = Url::parse(image_data.data.clone().as_str())
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)?;
+
+ let qr_code_info = QrCodeInformation::QrDataUrl {
+ image_data_url,
+ display_to_timestamp: Some(qr_expiration_duration),
+ };
+
+ Some(qr_code_info.encode_to_value())
+ .transpose()
+ .change_context(errors::ConnectorError::ResponseHandlingFailed)
+}
+
#[derive(Default, Debug, Serialize)]
pub struct SantanderRefundRequest {
- pub amount: StringMajorUnit,
+ #[serde(rename = "valor")]
+ pub value: StringMajorUnit,
}
impl<F> TryFrom<&SantanderRouterData<&RefundsRouterData<F>>> for SantanderRefundRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &SantanderRouterData<&RefundsRouterData<F>>) -> Result<Self, Self::Error> {
Ok(Self {
- amount: item.amount.to_owned(),
+ value: item.amount.to_owned(),
})
}
}
-// Type definition for Refund Response
-
-#[allow(dead_code)]
-#[derive(Debug, Serialize, Default, Deserialize, Clone)]
-pub enum RefundStatus {
- Succeeded,
- Failed,
- #[default]
- Processing,
+#[derive(Debug, Serialize, Deserialize, Clone)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
+pub enum SantanderRefundStatus {
+ InProcessing,
+ Returned,
+ NotDone,
}
-impl From<RefundStatus> for enums::RefundStatus {
- fn from(item: RefundStatus) -> Self {
+impl From<SantanderRefundStatus> for enums::RefundStatus {
+ fn from(item: SantanderRefundStatus) -> Self {
match item {
- RefundStatus::Succeeded => Self::Success,
- RefundStatus::Failed => Self::Failure,
- RefundStatus::Processing => Self::Pending,
- //TODO: Review mapping
+ SantanderRefundStatus::Returned => Self::Success,
+ SantanderRefundStatus::NotDone => Self::Failure,
+ SantanderRefundStatus::InProcessing => Self::Pending,
}
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Clone, Serialize, Deserialize)]
-pub struct RefundResponse {
- id: String,
- status: RefundStatus,
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderRefundResponse {
+ pub id: Secret<String>,
+ pub rtr_id: Secret<String>,
+ #[serde(rename = "valor")]
+ pub value: StringMajorUnit,
+ #[serde(rename = "horario")]
+ pub time: SantanderTime,
+ pub status: SantanderRefundStatus,
+ #[serde(rename = "motivo")]
+ pub reason: String,
}
-impl TryFrom<RefundsResponseRouterData<Execute, RefundResponse>> for RefundsRouterData<Execute> {
- type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(
- item: RefundsResponseRouterData<Execute, RefundResponse>,
- ) -> Result<Self, Self::Error> {
- Ok(Self {
- response: Ok(RefundsResponseData {
- connector_refund_id: item.response.id.to_string(),
- refund_status: enums::RefundStatus::from(item.response.status),
- }),
- ..item.data
- })
- }
+#[derive(Default, Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct SantanderTime {
+ #[serde(rename = "solicitacao")]
+ pub request: Option<String>,
+ #[serde(rename = "liquidacao")]
+ pub liquidation: Option<String>,
}
-impl TryFrom<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouterData<RSync> {
+impl<F> TryFrom<RefundsResponseRouterData<F, SantanderRefundResponse>> for RefundsRouterData<F> {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
- item: RefundsResponseRouterData<RSync, RefundResponse>,
+ item: RefundsResponseRouterData<F, SantanderRefundResponse>,
) -> Result<Self, Self::Error> {
Ok(Self {
response: Ok(RefundsResponseData {
- connector_refund_id: item.response.id.to_string(),
+ connector_refund_id: item.response.rtr_id.clone().expose(),
refund_status: enums::RefundStatus::from(item.response.status),
}),
..item.data
@@ -218,11 +651,25 @@ impl TryFrom<RefundsResponseRouterData<RSync, RefundResponse>> for RefundsRouter
}
}
-//TODO: Fill the struct with respective fields
-#[derive(Default, Debug, Serialize, Deserialize, PartialEq)]
+#[derive(Debug, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
pub struct SantanderErrorResponse {
- pub status_code: u16,
- pub code: String,
- pub message: String,
+ #[serde(rename = "type")]
+ pub field_type: Secret<String>,
+ pub title: String,
+ pub status: i64,
+ pub detail: Option<String>,
+ pub correlation_id: Option<String>,
+ #[serde(rename = "violacoes")]
+ pub violations: Option<Vec<SantanderViolations>>,
+}
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct SantanderViolations {
+ #[serde(rename = "razao")]
pub reason: Option<String>,
+ #[serde(rename = "propriedade")]
+ pub property: Option<String>,
+ #[serde(rename = "valor")]
+ pub value: Option<String>,
}
diff --git a/crates/payment_methods/src/configs/payment_connector_required_fields.rs b/crates/payment_methods/src/configs/payment_connector_required_fields.rs
index 4788c638c8..188b55ca53 100644
--- a/crates/payment_methods/src/configs/payment_connector_required_fields.rs
+++ b/crates/payment_methods/src/configs/payment_connector_required_fields.rs
@@ -3117,6 +3117,17 @@ fn get_bank_transfer_required_fields() -> HashMap<enums::PaymentMethodType, Conn
},
),
(Connector::Adyen, fields(vec![], vec![], vec![])),
+ (
+ Connector::Santander,
+ RequiredFieldFinal {
+ mandate: HashMap::new(),
+ non_mandate: HashMap::new(),
+ common: HashMap::from([
+ RequiredField::BillingUserFirstName.to_tuple(),
+ RequiredField::BillingUserLastName.to_tuple(),
+ ]),
+ },
+ ),
(
Connector::Facilitapay,
RequiredFieldFinal {
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 4a9cc008b6..eeb4557daf 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1706,10 +1706,13 @@ impl ConnectorAuthTypeAndMetadataValidation<'_> {
redsys::transformers::RedsysAuthType::try_from(self.auth_type)?;
Ok(())
}
- // api_enums::Connector::Santander => {
- // santander::transformers::SantanderAuthType::try_from(self.auth_type)?;
- // Ok(())
- // },
+ api_enums::Connector::Santander => {
+ santander::transformers::SantanderAuthType::try_from(self.auth_type)?;
+ santander::transformers::SantanderMetadataObject::try_from(
+ self.connector_meta_data,
+ )?;
+ Ok(())
+ }
api_enums::Connector::Shift4 => {
shift4::transformers::Shift4AuthType::try_from(self.auth_type)?;
Ok(())
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index f5c06afe17..636b1da0bb 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -3487,6 +3487,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
.as_ref()
.and_then(|noon| noon.order_category.clone())
});
+
let braintree_metadata = connector_metadata
.as_ref()
.and_then(|cm| cm.braintree.clone());
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index d2d18716ee..e189a0f1a4 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -557,9 +557,9 @@ impl ConnectorData {
enums::Connector::Redsys => {
Ok(ConnectorEnum::Old(Box::new(connector::Redsys::new())))
}
- // enums::Connector::Santander => {
- // Ok(ConnectorEnum::Old(Box::new(connector::Santander)))
- // }
+ enums::Connector::Santander => {
+ Ok(ConnectorEnum::Old(Box::new(connector::Santander::new())))
+ }
enums::Connector::Shift4 => {
Ok(ConnectorEnum::Old(Box::new(connector::Shift4::new())))
}
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index d5c17794b3..ad3d4de7f9 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -309,7 +309,7 @@ impl ForeignTryFrom<api_enums::Connector> for common_enums::RoutableConnectors {
api_enums::Connector::Razorpay => Self::Razorpay,
api_enums::Connector::Recurly => Self::Recurly,
api_enums::Connector::Redsys => Self::Redsys,
- // api_enums::Connector::Santander => Self::Santander,
+ api_enums::Connector::Santander => Self::Santander,
api_enums::Connector::Shift4 => Self::Shift4,
api_enums::Connector::Signifyd => {
Err(common_utils::errors::ValidationError::InvalidValue {
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 3c37f31556..4fade35122 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -547,6 +547,9 @@ crypto_currency = { country = "AL, AD, AT, BE, BA, BG, HR, CZ, DK, EE, FI, FR, D
[pm_filters.paystack]
eft = { country = "NG, ZA, GH, KE, CI", currency = "NGN, GHS, ZAR, KES, USD" }
+[pm_filters.santander]
+pix = { country = "BR", currency = "BRL" }
+
#tokenization configuration which describe token lifetime and payment method for specific connector
[tokenization]
stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { type = "disable_only", list = "google_pay" } }