mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat(connector): [Mollie] Currency Unit Conversion (#2671)
Co-authored-by: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com>
This commit is contained in:
@ -62,6 +62,10 @@ impl ConnectorCommon for Mollie {
|
|||||||
"mollie"
|
"mollie"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_currency_unit(&self) -> api::CurrencyUnit {
|
||||||
|
api::CurrencyUnit::Base
|
||||||
|
}
|
||||||
|
|
||||||
fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
|
fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str {
|
||||||
connectors.mollie.base_url.as_ref()
|
connectors.mollie.base_url.as_ref()
|
||||||
}
|
}
|
||||||
@ -229,7 +233,13 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
|||||||
&self,
|
&self,
|
||||||
req: &types::PaymentsAuthorizeRouterData,
|
req: &types::PaymentsAuthorizeRouterData,
|
||||||
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
||||||
let req_obj = mollie::MolliePaymentsRequest::try_from(req)?;
|
let router_obj = mollie::MollieRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.amount,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = mollie::MolliePaymentsRequest::try_from(&router_obj)?;
|
||||||
let mollie_req = types::RequestBody::log_and_get_request_body(
|
let mollie_req = types::RequestBody::log_and_get_request_body(
|
||||||
&req_obj,
|
&req_obj,
|
||||||
utils::Encode::<mollie::MolliePaymentsRequest>::encode_to_string_of_json,
|
utils::Encode::<mollie::MolliePaymentsRequest>::encode_to_string_of_json,
|
||||||
@ -417,7 +427,13 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
|
|||||||
&self,
|
&self,
|
||||||
req: &types::RefundsRouterData<api::Execute>,
|
req: &types::RefundsRouterData<api::Execute>,
|
||||||
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
||||||
let req_obj = mollie::MollieRefundRequest::try_from(req)?;
|
let router_obj = mollie::MollieRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.refund_amount,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = mollie::MollieRefundRequest::try_from(&router_obj)?;
|
||||||
let mollie_req = types::RequestBody::log_and_get_request_body(
|
let mollie_req = types::RequestBody::log_and_get_request_body(
|
||||||
&req_obj,
|
&req_obj,
|
||||||
utils::Encode::<mollie::MollieRefundRequest>::encode_to_string_of_json,
|
utils::Encode::<mollie::MollieRefundRequest>::encode_to_string_of_json,
|
||||||
|
|||||||
@ -19,6 +19,38 @@ use crate::{
|
|||||||
|
|
||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct MollieRouterData<T> {
|
||||||
|
pub amount: String,
|
||||||
|
pub router_data: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T>
|
||||||
|
TryFrom<(
|
||||||
|
&types::api::CurrencyUnit,
|
||||||
|
types::storage::enums::Currency,
|
||||||
|
i64,
|
||||||
|
T,
|
||||||
|
)> for MollieRouterData<T>
|
||||||
|
{
|
||||||
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
|
|
||||||
|
fn try_from(
|
||||||
|
(currency_unit, currency, amount, router_data): (
|
||||||
|
&types::api::CurrencyUnit,
|
||||||
|
types::storage::enums::Currency,
|
||||||
|
i64,
|
||||||
|
T,
|
||||||
|
),
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
|
let amount = utils::get_amount_as_string(currency_unit, amount, currency)?;
|
||||||
|
Ok(Self {
|
||||||
|
amount,
|
||||||
|
router_data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct MolliePaymentsRequest {
|
pub struct MolliePaymentsRequest {
|
||||||
@ -120,50 +152,55 @@ pub struct MollieBrowserInfo {
|
|||||||
language: String,
|
language: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&types::PaymentsAuthorizeRouterData> for MolliePaymentsRequest {
|
impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MolliePaymentsRequest {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
|
fn try_from(
|
||||||
|
item: &MollieRouterData<&types::PaymentsAuthorizeRouterData>,
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
let amount = Amount {
|
let amount = Amount {
|
||||||
currency: item.request.currency,
|
currency: item.router_data.request.currency,
|
||||||
value: utils::to_currency_base_unit(item.request.amount, item.request.currency)?,
|
value: item.amount.clone(),
|
||||||
};
|
};
|
||||||
let description = item.get_description()?;
|
let description = item.router_data.get_description()?;
|
||||||
let redirect_url = item.request.get_return_url()?;
|
let redirect_url = item.router_data.request.get_return_url()?;
|
||||||
let payment_method_data = match item.request.capture_method.unwrap_or_default() {
|
let payment_method_data = match item.router_data.request.capture_method.unwrap_or_default()
|
||||||
enums::CaptureMethod::Automatic => match &item.request.payment_method_data {
|
{
|
||||||
api_models::payments::PaymentMethodData::Card(_) => {
|
enums::CaptureMethod::Automatic => {
|
||||||
let pm_token = item.get_payment_method_token()?;
|
match &item.router_data.request.payment_method_data {
|
||||||
Ok(PaymentMethodData::CreditCard(Box::new(
|
api_models::payments::PaymentMethodData::Card(_) => {
|
||||||
CreditCardMethodData {
|
let pm_token = item.router_data.get_payment_method_token()?;
|
||||||
billing_address: get_billing_details(item)?,
|
Ok(PaymentMethodData::CreditCard(Box::new(
|
||||||
shipping_address: get_shipping_details(item)?,
|
CreditCardMethodData {
|
||||||
card_token: Some(Secret::new(match pm_token {
|
billing_address: get_billing_details(item.router_data)?,
|
||||||
types::PaymentMethodToken::Token(token) => token,
|
shipping_address: get_shipping_details(item.router_data)?,
|
||||||
types::PaymentMethodToken::ApplePayDecrypt(_) => {
|
card_token: Some(Secret::new(match pm_token {
|
||||||
Err(errors::ConnectorError::InvalidWalletToken)?
|
types::PaymentMethodToken::Token(token) => token,
|
||||||
}
|
types::PaymentMethodToken::ApplePayDecrypt(_) => {
|
||||||
})),
|
Err(errors::ConnectorError::InvalidWalletToken)?
|
||||||
},
|
}
|
||||||
)))
|
})),
|
||||||
|
},
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
api_models::payments::PaymentMethodData::BankRedirect(ref redirect_data) => {
|
||||||
|
PaymentMethodData::try_from(redirect_data)
|
||||||
|
}
|
||||||
|
api_models::payments::PaymentMethodData::Wallet(ref wallet_data) => {
|
||||||
|
get_payment_method_for_wallet(item.router_data, wallet_data)
|
||||||
|
}
|
||||||
|
api_models::payments::PaymentMethodData::BankDebit(ref directdebit_data) => {
|
||||||
|
PaymentMethodData::try_from(directdebit_data)
|
||||||
|
}
|
||||||
|
_ => Err(errors::ConnectorError::NotImplemented(
|
||||||
|
"Payment Method".to_string(),
|
||||||
|
))
|
||||||
|
.into_report(),
|
||||||
}
|
}
|
||||||
api_models::payments::PaymentMethodData::BankRedirect(ref redirect_data) => {
|
}
|
||||||
PaymentMethodData::try_from(redirect_data)
|
|
||||||
}
|
|
||||||
api_models::payments::PaymentMethodData::Wallet(ref wallet_data) => {
|
|
||||||
get_payment_method_for_wallet(item, wallet_data)
|
|
||||||
}
|
|
||||||
api_models::payments::PaymentMethodData::BankDebit(ref directdebit_data) => {
|
|
||||||
PaymentMethodData::try_from(directdebit_data)
|
|
||||||
}
|
|
||||||
_ => Err(errors::ConnectorError::NotImplemented(
|
|
||||||
"Payment Method".to_string(),
|
|
||||||
))
|
|
||||||
.into_report(),
|
|
||||||
},
|
|
||||||
_ => Err(errors::ConnectorError::FlowNotSupported {
|
_ => Err(errors::ConnectorError::FlowNotSupported {
|
||||||
flow: format!(
|
flow: format!(
|
||||||
"{} capture",
|
"{} capture",
|
||||||
item.request.capture_method.unwrap_or_default()
|
item.router_data.request.capture_method.unwrap_or_default()
|
||||||
),
|
),
|
||||||
connector: "Mollie".to_string(),
|
connector: "Mollie".to_string(),
|
||||||
})
|
})
|
||||||
@ -526,16 +563,18 @@ pub struct MollieRefundRequest {
|
|||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> TryFrom<&types::RefundsRouterData<F>> for MollieRefundRequest {
|
impl<F> TryFrom<&MollieRouterData<&types::RefundsRouterData<F>>> for MollieRefundRequest {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
|
fn try_from(
|
||||||
|
item: &MollieRouterData<&types::RefundsRouterData<F>>,
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
let amount = Amount {
|
let amount = Amount {
|
||||||
currency: item.request.currency,
|
currency: item.router_data.request.currency,
|
||||||
value: utils::to_currency_base_unit(item.request.refund_amount, item.request.currency)?,
|
value: item.amount.clone(),
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
amount,
|
amount,
|
||||||
description: item.request.reason.to_owned(),
|
description: item.router_data.request.reason.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user