mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 21:37:41 +08:00
feat(connector): [Multisafepay] Currency Unit Conversion (#2679)
This commit is contained in:
@ -45,6 +45,10 @@ impl ConnectorCommon for Multisafepay {
|
|||||||
"multisafepay"
|
"multisafepay"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_currency_unit(&self) -> api::CurrencyUnit {
|
||||||
|
api::CurrencyUnit::Minor
|
||||||
|
}
|
||||||
|
|
||||||
fn common_get_content_type(&self) -> &'static str {
|
fn common_get_content_type(&self) -> &'static str {
|
||||||
"application/json"
|
"application/json"
|
||||||
}
|
}
|
||||||
@ -257,7 +261,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 = multisafepay::MultisafepayPaymentsRequest::try_from(req)?;
|
let connector_router_data = multisafepay::MultisafepayRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.amount,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = multisafepay::MultisafepayPaymentsRequest::try_from(&connector_router_data)?;
|
||||||
let multisafepay_req = types::RequestBody::log_and_get_request_body(
|
let multisafepay_req = types::RequestBody::log_and_get_request_body(
|
||||||
&req_obj,
|
&req_obj,
|
||||||
utils::Encode::<multisafepay::MultisafepayPaymentsRequest>::encode_to_string_of_json,
|
utils::Encode::<multisafepay::MultisafepayPaymentsRequest>::encode_to_string_of_json,
|
||||||
@ -351,9 +361,16 @@ 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 connector_req = multisafepay::MultisafepayRefundRequest::try_from(req)?;
|
let connector_req = multisafepay::MultisafepayRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.refund_amount,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = multisafepay::MultisafepayRefundRequest::try_from(&connector_req)?;
|
||||||
|
|
||||||
let multisafepay_req = types::RequestBody::log_and_get_request_body(
|
let multisafepay_req = types::RequestBody::log_and_get_request_body(
|
||||||
&connector_req,
|
&req_obj,
|
||||||
utils::Encode::<multisafepay::MultisafepayPaymentsRequest>::encode_to_string_of_json,
|
utils::Encode::<multisafepay::MultisafepayPaymentsRequest>::encode_to_string_of_json,
|
||||||
)
|
)
|
||||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
|
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
|
||||||
|
|||||||
@ -13,6 +13,37 @@ use crate::{
|
|||||||
types::{self, api, storage::enums},
|
types::{self, api, storage::enums},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct MultisafepayRouterData<T> {
|
||||||
|
amount: i64,
|
||||||
|
router_data: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T>
|
||||||
|
TryFrom<(
|
||||||
|
&types::api::CurrencyUnit,
|
||||||
|
types::storage::enums::Currency,
|
||||||
|
i64,
|
||||||
|
T,
|
||||||
|
)> for MultisafepayRouterData<T>
|
||||||
|
{
|
||||||
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
|
|
||||||
|
fn try_from(
|
||||||
|
(_currency_unit, _currency, amount, item): (
|
||||||
|
&types::api::CurrencyUnit,
|
||||||
|
types::storage::enums::Currency,
|
||||||
|
i64,
|
||||||
|
T,
|
||||||
|
),
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
|
Ok(Self {
|
||||||
|
amount,
|
||||||
|
router_data: item,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
@ -240,10 +271,14 @@ impl TryFrom<utils::CardIssuer> for Gateway {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsRequest {
|
impl TryFrom<&MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>>
|
||||||
|
for MultisafepayPaymentsRequest
|
||||||
|
{
|
||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
|
fn try_from(
|
||||||
let payment_type = match item.request.payment_method_data {
|
item: &MultisafepayRouterData<&types::PaymentsAuthorizeRouterData>,
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
|
let payment_type = match item.router_data.request.payment_method_data {
|
||||||
api::PaymentMethodData::Card(ref _ccard) => Type::Direct,
|
api::PaymentMethodData::Card(ref _ccard) => Type::Direct,
|
||||||
api::PaymentMethodData::MandatePayment => Type::Direct,
|
api::PaymentMethodData::MandatePayment => Type::Direct,
|
||||||
api::PaymentMethodData::Wallet(ref wallet_data) => match wallet_data {
|
api::PaymentMethodData::Wallet(ref wallet_data) => match wallet_data {
|
||||||
@ -280,7 +315,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsReques
|
|||||||
_ => Type::Redirect,
|
_ => Type::Redirect,
|
||||||
};
|
};
|
||||||
|
|
||||||
let gateway = match item.request.payment_method_data {
|
let gateway = match item.router_data.request.payment_method_data {
|
||||||
api::PaymentMethodData::Card(ref ccard) => {
|
api::PaymentMethodData::Card(ref ccard) => {
|
||||||
Some(Gateway::try_from(ccard.get_card_issuer()?)?)
|
Some(Gateway::try_from(ccard.get_card_issuer()?)?)
|
||||||
}
|
}
|
||||||
@ -334,11 +369,11 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsReques
|
|||||||
utils::get_unimplemented_payment_method_error_message("multisafepay"),
|
utils::get_unimplemented_payment_method_error_message("multisafepay"),
|
||||||
))?,
|
))?,
|
||||||
};
|
};
|
||||||
let description = item.get_description()?;
|
let description = item.router_data.get_description()?;
|
||||||
let payment_options = PaymentOptions {
|
let payment_options = PaymentOptions {
|
||||||
notification_url: None,
|
notification_url: None,
|
||||||
redirect_url: item.request.get_router_return_url()?,
|
redirect_url: item.router_data.request.get_router_return_url()?,
|
||||||
cancel_url: item.request.get_router_return_url()?,
|
cancel_url: item.router_data.request.get_router_return_url()?,
|
||||||
close_window: None,
|
close_window: None,
|
||||||
notification_method: None,
|
notification_method: None,
|
||||||
settings: None,
|
settings: None,
|
||||||
@ -363,13 +398,14 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsReques
|
|||||||
state: None,
|
state: None,
|
||||||
country: None,
|
country: None,
|
||||||
phone: None,
|
phone: None,
|
||||||
email: item.request.email.clone(),
|
email: item.router_data.request.email.clone(),
|
||||||
user_agent: None,
|
user_agent: None,
|
||||||
referrer: None,
|
referrer: None,
|
||||||
reference: Some(item.connector_request_reference_id.clone()),
|
reference: Some(item.router_data.connector_request_reference_id.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let billing_address = item
|
let billing_address = item
|
||||||
|
.router_data
|
||||||
.get_billing()?
|
.get_billing()?
|
||||||
.address
|
.address
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -384,7 +420,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsReques
|
|||||||
country: billing_address.get_country()?.to_owned(),
|
country: billing_address.get_country()?.to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let gateway_info = match item.request.payment_method_data {
|
let gateway_info = match item.router_data.request.payment_method_data {
|
||||||
api::PaymentMethodData::Card(ref ccard) => Some(GatewayInfo::Card(CardInfo {
|
api::PaymentMethodData::Card(ref ccard) => Some(GatewayInfo::Card(CardInfo {
|
||||||
card_number: Some(ccard.card_number.clone()),
|
card_number: Some(ccard.card_number.clone()),
|
||||||
card_expiry_date: Some(
|
card_expiry_date: Some(
|
||||||
@ -481,9 +517,9 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsReques
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
payment_type,
|
payment_type,
|
||||||
gateway,
|
gateway,
|
||||||
order_id: item.connector_request_reference_id.to_string(),
|
order_id: item.router_data.connector_request_reference_id.to_string(),
|
||||||
currency: item.request.currency.to_string(),
|
currency: item.router_data.request.currency.to_string(),
|
||||||
amount: item.request.amount,
|
amount: item.amount,
|
||||||
description,
|
description,
|
||||||
payment_options: Some(payment_options),
|
payment_options: Some(payment_options),
|
||||||
customer: Some(customer),
|
customer: Some(customer),
|
||||||
@ -493,12 +529,13 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for MultisafepayPaymentsReques
|
|||||||
shopping_cart: None,
|
shopping_cart: None,
|
||||||
capture: None,
|
capture: None,
|
||||||
items: None,
|
items: None,
|
||||||
recurring_model: if item.request.is_mandate_payment() {
|
recurring_model: if item.router_data.request.is_mandate_payment() {
|
||||||
Some(MandateType::Unscheduled)
|
Some(MandateType::Unscheduled)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
recurring_id: item
|
recurring_id: item
|
||||||
|
.router_data
|
||||||
.request
|
.request
|
||||||
.mandate_id
|
.mandate_id
|
||||||
.clone()
|
.clone()
|
||||||
@ -664,14 +701,18 @@ pub struct MultisafepayRefundRequest {
|
|||||||
pub checkout_data: Option<ShoppingCart>,
|
pub checkout_data: Option<ShoppingCart>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> TryFrom<&types::RefundsRouterData<F>> for MultisafepayRefundRequest {
|
impl<F> TryFrom<&MultisafepayRouterData<&types::RefundsRouterData<F>>>
|
||||||
|
for MultisafepayRefundRequest
|
||||||
|
{
|
||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> {
|
fn try_from(
|
||||||
|
item: &MultisafepayRouterData<&types::RefundsRouterData<F>>,
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
currency: item.request.currency,
|
currency: item.router_data.request.currency,
|
||||||
amount: item.request.refund_amount,
|
amount: item.amount,
|
||||||
description: item.description.clone(),
|
description: item.router_data.description.clone(),
|
||||||
refund_order_id: Some(item.request.refund_id.clone()),
|
refund_order_id: Some(item.router_data.request.refund_id.clone()),
|
||||||
checkout_data: None,
|
checkout_data: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user