Skip to content

Commit 8971b17

Browse files
feat(connector): [Airwallex] Currency Unit Conversion (#2571)
1 parent 1f48860 commit 8971b17

File tree

2 files changed

+67
-15
lines changed

2 files changed

+67
-15
lines changed

crates/router/src/connector/airwallex.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ impl ConnectorCommon for Airwallex {
6666
"airwallex"
6767
}
6868

69+
fn get_currency_unit(&self) -> api::CurrencyUnit {
70+
api::CurrencyUnit::Base
71+
}
72+
6973
fn common_get_content_type(&self) -> &'static str {
7074
"application/json"
7175
}
@@ -369,7 +373,13 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
369373
&self,
370374
req: &types::PaymentsAuthorizeRouterData,
371375
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
372-
let connector_req = airwallex::AirwallexPaymentsRequest::try_from(req)?;
376+
let connector_router_data = airwallex::AirwallexRouterData::try_from((
377+
&self.get_currency_unit(),
378+
req.request.currency,
379+
req.request.amount,
380+
req,
381+
))?;
382+
let connector_req = airwallex::AirwallexPaymentsRequest::try_from(&connector_router_data)?;
373383
let airwallex_req = types::RequestBody::log_and_get_request_body(
374384
&connector_req,
375385
utils::Encode::<airwallex::AirwallexPaymentsRequest>::encode_to_string_of_json,
@@ -810,7 +820,13 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
810820
&self,
811821
req: &types::RefundsRouterData<api::Execute>,
812822
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
813-
let connector_req = airwallex::AirwallexRefundRequest::try_from(req)?;
823+
let connector_router_data = airwallex::AirwallexRouterData::try_from((
824+
&self.get_currency_unit(),
825+
req.request.currency,
826+
req.request.refund_amount,
827+
req,
828+
))?;
829+
let connector_req = airwallex::AirwallexRefundRequest::try_from(&connector_router_data)?;
814830
let airwallex_req = types::RequestBody::log_and_get_request_body(
815831
&connector_req,
816832
utils::Encode::<airwallex::AirwallexRefundRequest>::encode_to_string_of_json,

crates/router/src/connector/airwallex/transformers.rs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,38 @@ impl TryFrom<&types::PaymentsInitRouterData> for AirwallexIntentRequest {
5353
}
5454
}
5555

56+
#[derive(Debug, Serialize)]
57+
pub struct AirwallexRouterData<T> {
58+
pub amount: String,
59+
pub router_data: T,
60+
}
61+
62+
impl<T>
63+
TryFrom<(
64+
&types::api::CurrencyUnit,
65+
types::storage::enums::Currency,
66+
i64,
67+
T,
68+
)> for AirwallexRouterData<T>
69+
{
70+
type Error = error_stack::Report<errors::ConnectorError>;
71+
72+
fn try_from(
73+
(currency_unit, currency, amount, router_data): (
74+
&types::api::CurrencyUnit,
75+
types::storage::enums::Currency,
76+
i64,
77+
T,
78+
),
79+
) -> Result<Self, Self::Error> {
80+
let amount = utils::get_amount_as_string(currency_unit, amount, currency)?;
81+
Ok(Self {
82+
amount,
83+
router_data,
84+
})
85+
}
86+
}
87+
5688
#[derive(Debug, Serialize)]
5789
pub struct AirwallexPaymentsRequest {
5890
// Unique ID to be sent for each transaction/operation request to the connector
@@ -125,16 +157,21 @@ pub struct AirwallexCardPaymentOptions {
125157
auto_capture: bool,
126158
}
127159

128-
impl TryFrom<&types::PaymentsAuthorizeRouterData> for AirwallexPaymentsRequest {
160+
impl TryFrom<&AirwallexRouterData<&types::PaymentsAuthorizeRouterData>>
161+
for AirwallexPaymentsRequest
162+
{
129163
type Error = error_stack::Report<errors::ConnectorError>;
130-
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
164+
fn try_from(
165+
item: &AirwallexRouterData<&types::PaymentsAuthorizeRouterData>,
166+
) -> Result<Self, Self::Error> {
131167
let mut payment_method_options = None;
132-
let payment_method = match item.request.payment_method_data.clone() {
168+
let request = &item.router_data.request;
169+
let payment_method = match request.payment_method_data.clone() {
133170
api::PaymentMethodData::Card(ccard) => {
134171
payment_method_options =
135172
Some(AirwallexPaymentOptions::Card(AirwallexCardPaymentOptions {
136173
auto_capture: matches!(
137-
item.request.capture_method,
174+
request.capture_method,
138175
Some(enums::CaptureMethod::Automatic) | None
139176
),
140177
}));
@@ -158,7 +195,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AirwallexPaymentsRequest {
158195
request_id: Uuid::new_v4().to_string(),
159196
payment_method,
160197
payment_method_options,
161-
return_url: item.request.complete_authorize_url.clone(),
198+
return_url: request.complete_authorize_url.clone(),
162199
})
163200
}
164201
}
@@ -538,17 +575,16 @@ pub struct AirwallexRefundRequest {
538575
payment_intent_id: String,
539576
}
540577

541-
impl<F> TryFrom<&types::RefundsRouterData<F>> for AirwallexRefundRequest {
578+
impl<F> TryFrom<&AirwallexRouterData<&types::RefundsRouterData<F>>> for AirwallexRefundRequest {
542579
type Error = error_stack::Report<errors::ConnectorError>;
543-
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
580+
fn try_from(
581+
item: &AirwallexRouterData<&types::RefundsRouterData<F>>,
582+
) -> Result<Self, Self::Error> {
544583
Ok(Self {
545584
request_id: Uuid::new_v4().to_string(),
546-
amount: Some(utils::to_currency_base_unit(
547-
item.request.refund_amount,
548-
item.request.currency,
549-
)?),
550-
reason: item.request.reason.clone(),
551-
payment_intent_id: item.request.connector_transaction_id.clone(),
585+
amount: Some(item.amount.to_owned()),
586+
reason: item.router_data.request.reason.clone(),
587+
payment_intent_id: item.router_data.request.connector_transaction_id.clone(),
552588
})
553589
}
554590
}

0 commit comments

Comments
 (0)