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): [Dlocal] Implement oxxo voucher (#10450)

Swangi Kumari50d303cb5583
diff --git a/crates/hyperswitch_connectors/src/connectors/dlocal.rs b/crates/hyperswitch_connectors/src/connectors/dlocal.rs
index 653fe7397b..b72db759b8 100644
--- a/crates/hyperswitch_connectors/src/connectors/dlocal.rs
+++ b/crates/hyperswitch_connectors/src/connectors/dlocal.rs
@@ -720,6 +720,10 @@ lazy_static! {
enums::CaptureMethod::SequentialAutomatic,
];
+ let supported_capture_methods2 = vec![
+ enums::CaptureMethod::Automatic,
+ ];
+
let supported_card_network = vec![
common_enums::CardNetwork::Visa,
common_enums::CardNetwork::Mastercard,
@@ -772,6 +776,17 @@ lazy_static! {
},
);
+ dlocal_supported_payment_methods.add(
+ enums::PaymentMethod::Voucher,
+ enums::PaymentMethodType::Oxxo,
+ PaymentMethodDetails {
+ mandates: common_enums::FeatureStatus::NotSupported,
+ refunds: common_enums::FeatureStatus::Supported,
+ supported_capture_methods: supported_capture_methods2.clone(),
+ specific_features: None,
+ },
+ );
+
dlocal_supported_payment_methods
};
diff --git a/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs
index 2f833354bb..fb8e1ac31c 100644
--- a/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs
@@ -1,7 +1,7 @@
use common_enums::enums;
use common_utils::{pii::Email, request::Method, types::FloatMajorUnit};
use hyperswitch_domain_models::{
- payment_method_data::PaymentMethodData,
+ payment_method_data::{PaymentMethodData, VoucherData},
router_data::{ConnectorAuthType, RouterData},
router_flow_types::{refunds::Execute, RSync},
router_request_types::ResponseId,
@@ -45,6 +45,8 @@ pub struct ThreeDSecureReqData {
pub enum PaymentMethodId {
#[default]
Card,
+ #[serde(rename = "OX")]
+ Oxxo,
}
#[derive(Debug, Serialize, Default, Deserialize, Clone, Eq, PartialEq)]
@@ -80,6 +82,7 @@ pub struct DlocalPaymentsRequest {
pub payment_method_id: PaymentMethodId,
pub payment_method_flow: PaymentMethodFlow,
pub payer: Payer,
+ #[serde(skip_serializing_if = "Option::is_none")]
pub card: Option<Card>,
pub order_id: String,
pub three_dsecure: Option<ThreeDSecureReqData>,
@@ -96,7 +99,17 @@ impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalP
let address = item.router_data.get_billing_address()?;
let country = *address.get_country()?;
let name = address.get_full_name()?;
- match item.router_data.request.payment_method_data {
+ let amount = item.amount;
+ let payer = Payer {
+ name,
+ email,
+ // [#589]: Allow securely collecting PII from customer in payments request
+ document: get_doc_from_currency(country.to_string()),
+ };
+ let order_id = item.router_data.connector_request_reference_id.clone();
+ let callback_url = item.router_data.request.get_router_return_url()?;
+ let description = item.router_data.description.clone();
+ match item.router_data.request.payment_method_data.clone() {
PaymentMethodData::Card(ref ccard) => {
let should_capture = matches!(
item.router_data.request.capture_method,
@@ -104,17 +117,12 @@ impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalP
| Some(enums::CaptureMethod::SequentialAutomatic)
);
let payment_request = Self {
- amount: item.amount,
+ amount,
currency: item.router_data.request.currency,
payment_method_id: PaymentMethodId::Card,
payment_method_flow: PaymentMethodFlow::Direct,
country,
- payer: Payer {
- name,
- email,
- // [#589]: Allow securely collecting PII from customer in payments request
- document: get_doc_from_currency(country.to_string()),
- },
+ payer,
card: Some(Card {
holder_name: ccard.card_holder_name.clone(),
number: ccard.card_number.clone(),
@@ -123,18 +131,39 @@ impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalP
expiration_year: ccard.card_exp_year.clone(),
capture: should_capture.to_string(),
}),
- order_id: item.router_data.connector_request_reference_id.clone(),
+ order_id,
three_dsecure: match item.router_data.auth_type {
enums::AuthenticationType::ThreeDs => {
Some(ThreeDSecureReqData { force: true })
}
enums::AuthenticationType::NoThreeDs => None,
},
- callback_url: Some(item.router_data.request.get_router_return_url()?),
- description: item.router_data.description.clone(),
+ callback_url: Some(callback_url),
+ description,
};
Ok(payment_request)
}
+ PaymentMethodData::Voucher(voucher_data) => match voucher_data {
+ VoucherData::Oxxo => {
+ let payment_request = Self {
+ amount: item.amount,
+ currency: item.router_data.request.currency,
+ payment_method_id: PaymentMethodId::Oxxo,
+ payment_method_flow: PaymentMethodFlow::Direct,
+ country,
+ payer,
+ card: None,
+ order_id,
+ three_dsecure: None,
+ callback_url: Some(callback_url),
+ description,
+ };
+ Ok(payment_request)
+ }
+ _ => Err(errors::ConnectorError::NotImplemented(
+ crate::utils::get_unimplemented_payment_method_error_message("Dlocal"),
+ ))?,
+ },
PaymentMethodData::CardRedirect(_)
| PaymentMethodData::Wallet(_)
| PaymentMethodData::PayLater(_)
@@ -147,7 +176,6 @@ impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalP
| PaymentMethodData::RealTimePayment(_)
| PaymentMethodData::MobilePayment(_)
| PaymentMethodData::Upi(_)
- | PaymentMethodData::Voucher(_)
| PaymentMethodData::GiftCard(_)
| PaymentMethodData::OpenBanking(_)
| PaymentMethodData::CardToken(_)
@@ -233,6 +261,26 @@ impl From<DlocalPaymentStatus> for enums::AttemptStatus {
}
}
+fn map_dlocal_status_to_attempt_status(
+ status: DlocalPaymentStatus,
+ has_redirect: bool,
+) -> enums::AttemptStatus {
+ match status {
+ DlocalPaymentStatus::Authorized => enums::AttemptStatus::Authorized,
+ DlocalPaymentStatus::Paid => enums::AttemptStatus::Charged,
+ DlocalPaymentStatus::Cancelled => enums::AttemptStatus::Voided,
+ DlocalPaymentStatus::Rejected => enums::AttemptStatus::Failure,
+
+ DlocalPaymentStatus::Pending => {
+ if has_redirect {
+ enums::AttemptStatus::AuthenticationPending
+ } else {
+ enums::AttemptStatus::Pending
+ }
+ }
+ }
+}
+
#[derive(Eq, Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ThreeDSecureResData {
pub redirect_url: Option<Url>,
@@ -244,6 +292,12 @@ pub struct DlocalPaymentsResponse {
id: String,
three_dsecure: Option<ThreeDSecureResData>,
order_id: Option<String>,
+ ticket: Option<TicketData>,
+}
+
+#[derive(Eq, Debug, Clone, Serialize, Deserialize, PartialEq)]
+pub struct TicketData {
+ pub image_url: Option<Url>,
}
impl<F, T> TryFrom<ResponseRouterData<F, DlocalPaymentsResponse, T, PaymentsResponseData>>
@@ -253,15 +307,24 @@ impl<F, T> TryFrom<ResponseRouterData<F, DlocalPaymentsResponse, T, PaymentsResp
fn try_from(
item: ResponseRouterData<F, DlocalPaymentsResponse, T, PaymentsResponseData>,
) -> Result<Self, Self::Error> {
- let redirection_data = item
- .response
- .three_dsecure
- .and_then(|three_secure_data| three_secure_data.redirect_url)
- .map(|redirect_url| RedirectForm::from((redirect_url, Method::Get)));
+ let payment_method = item.data.payment_method;
+ let redirection_data = match payment_method {
+ enums::PaymentMethod::Card => item
+ .response
+ .three_dsecure
+ .and_then(|three_secure_data| three_secure_data.redirect_url)
+ .map(|redirect_url| RedirectForm::from((redirect_url, Method::Get))),
+ enums::PaymentMethod::Voucher => item
+ .response
+ .ticket
+ .and_then(|ticket_data| ticket_data.image_url)
+ .map(|image_url| RedirectForm::from((image_url, Method::Get))),
+ _ => None,
+ };
let response = PaymentsResponseData::TransactionResponse {
resource_id: ResponseId::ConnectorTransactionId(item.response.id.clone()),
- redirection_data: Box::new(redirection_data),
+ redirection_data: Box::new(redirection_data.clone()),
mandate_reference: Box::new(None),
connector_metadata: None,
network_txn_id: None,
@@ -269,8 +332,10 @@ impl<F, T> TryFrom<ResponseRouterData<F, DlocalPaymentsResponse, T, PaymentsResp
incremental_authorization_allowed: None,
charges: None,
};
+ let status =
+ map_dlocal_status_to_attempt_status(item.response.status, redirection_data.is_some());
Ok(Self {
- status: enums::AttemptStatus::from(item.response.status),
+ status,
response: Ok(response),
..item.data
})
@@ -473,6 +538,7 @@ fn get_doc_from_currency(country: String) -> Secret<String> {
"JP" | "MY" | "PH" => "123456789012",
"NI" => "1234567890111A",
"TZ" => "12345678912345678900",
+ "MX" => "1234567890",
_ => "12345678",
};
Secret::new(doc.to_string())