diff --git a/crates/router/src/connector/dlocal.rs b/crates/router/src/connector/dlocal.rs index 90be2399ba0e..b706d694a3d5 100644 --- a/crates/router/src/connector/dlocal.rs +++ b/crates/router/src/connector/dlocal.rs @@ -109,6 +109,10 @@ impl ConnectorCommon for Dlocal { "dlocal" } + fn get_currency_unit(&self) -> api::CurrencyUnit { + api::CurrencyUnit::Minor + } + fn common_get_content_type(&self) -> &'static str { "application/json" } @@ -207,7 +211,13 @@ impl ConnectorIntegration CustomResult, errors::ConnectorError> { - let connector_request = dlocal::DlocalPaymentsRequest::try_from(req)?; + let connector_router_data = dlocal::DlocalRouterData::try_from(( + &self.get_currency_unit(), + req.request.currency, + req.request.amount, + req, + ))?; + let connector_request = dlocal::DlocalPaymentsRequest::try_from(&connector_router_data)?; let dlocal_payments_request = types::RequestBody::log_and_get_request_body( &connector_request, utils::Encode::::encode_to_string_of_json, @@ -508,10 +518,16 @@ impl ConnectorIntegration, ) -> CustomResult, errors::ConnectorError> { - let connector_request = dlocal::RefundRequest::try_from(req)?; + let connector_router_data = dlocal::DlocalRouterData::try_from(( + &self.get_currency_unit(), + req.request.currency, + req.request.refund_amount, + req, + ))?; + let connector_request = dlocal::DlocalRefundRequest::try_from(&connector_router_data)?; let dlocal_refund_request = types::RequestBody::log_and_get_request_body( &connector_request, - utils::Encode::::encode_to_string_of_json, + utils::Encode::::encode_to_string_of_json, ) .change_context(errors::ConnectorError::RequestEncodingFailed)?; Ok(Some(dlocal_refund_request)) diff --git a/crates/router/src/connector/dlocal/transformers.rs b/crates/router/src/connector/dlocal/transformers.rs index 8558836372ec..87562fa33448 100644 --- a/crates/router/src/connector/dlocal/transformers.rs +++ b/crates/router/src/connector/dlocal/transformers.rs @@ -51,6 +51,37 @@ pub enum PaymentMethodFlow { ReDirect, } +#[derive(Debug, Serialize)] +pub struct DlocalRouterData { + pub amount: i64, + pub router_data: T, +} + +impl + TryFrom<( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + )> for DlocalRouterData +{ + type Error = error_stack::Report; + + fn try_from( + (_currency_unit, _currency, amount, router_data): ( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + ), + ) -> Result { + Ok(Self { + amount, + router_data, + }) + } +} + #[derive(Default, Debug, Serialize, Eq, PartialEq)] pub struct DlocalPaymentsRequest { pub amount: i64, @@ -66,22 +97,24 @@ pub struct DlocalPaymentsRequest { pub description: Option, } -impl TryFrom<&types::PaymentsAuthorizeRouterData> for DlocalPaymentsRequest { +impl TryFrom<&DlocalRouterData<&types::PaymentsAuthorizeRouterData>> for DlocalPaymentsRequest { type Error = error_stack::Report; - fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { - let email = item.request.email.clone(); - let address = item.get_billing_address()?; + fn try_from( + item: &DlocalRouterData<&types::PaymentsAuthorizeRouterData>, + ) -> Result { + let email = item.router_data.request.email.clone(); + let address = item.router_data.get_billing_address()?; let country = address.get_country()?; let name = get_payer_name(address); - match item.request.payment_method_data { + match item.router_data.request.payment_method_data { api::PaymentMethodData::Card(ref ccard) => { let should_capture = matches!( - item.request.capture_method, + item.router_data.request.capture_method, Some(enums::CaptureMethod::Automatic) ); let payment_request = Self { - amount: item.request.amount, - currency: item.request.currency, + amount: item.amount, + currency: item.router_data.request.currency, payment_method_id: PaymentMethodId::Card, payment_method_flow: PaymentMethodFlow::Direct, country: country.to_string(), @@ -99,22 +132,28 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for DlocalPaymentsRequest { expiration_year: ccard.card_exp_year.clone(), capture: should_capture.to_string(), installments_id: item + .router_data .request .mandate_id .as_ref() .map(|ids| ids.mandate_id.clone()), // [#595[FEATURE] Pass Mandate history information in payment flows/request] - installments: item.request.mandate_id.clone().map(|_| "1".to_string()), + installments: item + .router_data + .request + .mandate_id + .clone() + .map(|_| "1".to_string()), }), - order_id: item.payment_id.clone(), - three_dsecure: match item.auth_type { + order_id: item.router_data.payment_id.clone(), + three_dsecure: match item.router_data.auth_type { diesel_models::enums::AuthenticationType::ThreeDs => { Some(ThreeDSecureReqData { force: true }) } diesel_models::enums::AuthenticationType::NoThreeDs => None, }, - callback_url: Some(item.request.get_router_return_url()?), - description: item.description.clone(), + callback_url: Some(item.router_data.request.get_router_return_url()?), + description: item.router_data.description.clone(), }; Ok(payment_request) } @@ -399,22 +438,24 @@ impl // REFUND : #[derive(Default, Debug, Serialize)] -pub struct RefundRequest { +pub struct DlocalRefundRequest { pub amount: String, pub payment_id: String, pub currency: enums::Currency, pub id: String, } -impl TryFrom<&types::RefundsRouterData> for RefundRequest { +impl TryFrom<&DlocalRouterData<&types::RefundsRouterData>> for DlocalRefundRequest { type Error = error_stack::Report; - fn try_from(item: &types::RefundsRouterData) -> Result { - let amount_to_refund = item.request.refund_amount.to_string(); + fn try_from( + item: &DlocalRouterData<&types::RefundsRouterData>, + ) -> Result { + let amount_to_refund = item.router_data.request.refund_amount.to_string(); Ok(Self { amount: amount_to_refund, - payment_id: item.request.connector_transaction_id.clone(), - currency: item.request.currency, - id: item.request.refund_id.clone(), + payment_id: item.router_data.request.connector_transaction_id.clone(), + currency: item.router_data.request.currency, + id: item.router_data.request.refund_id.clone(), }) } }