mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
refactor(connector): [Rapyd] add and implement the get_currency_unit function (#2664)
Co-authored-by: Shivansh Bhatnagar <shivansh.bhatnagar.mat22@iitbhu.ac.in>
This commit is contained in:
committed by
GitHub
parent
af90089010
commit
78e5cd00b5
@ -64,6 +64,10 @@ impl ConnectorCommon for Rapyd {
|
|||||||
"rapyd"
|
"rapyd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
}
|
}
|
||||||
@ -179,7 +183,13 @@ impl
|
|||||||
&self,
|
&self,
|
||||||
req: &types::PaymentsAuthorizeRouterData,
|
req: &types::PaymentsAuthorizeRouterData,
|
||||||
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
||||||
let req_obj = rapyd::RapydPaymentsRequest::try_from(req)?;
|
let connector_router_data = rapyd::RapydRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.amount,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = rapyd::RapydPaymentsRequest::try_from(&connector_router_data)?;
|
||||||
let rapyd_req = types::RequestBody::log_and_get_request_body(
|
let rapyd_req = types::RequestBody::log_and_get_request_body(
|
||||||
&req_obj,
|
&req_obj,
|
||||||
utils::Encode::<rapyd::RapydPaymentsRequest>::encode_to_string_of_json,
|
utils::Encode::<rapyd::RapydPaymentsRequest>::encode_to_string_of_json,
|
||||||
@ -483,7 +493,13 @@ impl
|
|||||||
&self,
|
&self,
|
||||||
req: &types::PaymentsCaptureRouterData,
|
req: &types::PaymentsCaptureRouterData,
|
||||||
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {
|
||||||
let req_obj = rapyd::CaptureRequest::try_from(req)?;
|
let connector_router_data = rapyd::RapydRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.amount_to_capture,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = rapyd::CaptureRequest::try_from(&connector_router_data)?;
|
||||||
let rapyd_req = types::RequestBody::log_and_get_request_body(
|
let rapyd_req = types::RequestBody::log_and_get_request_body(
|
||||||
&req_obj,
|
&req_obj,
|
||||||
utils::Encode::<rapyd::CaptureRequest>::encode_to_string_of_json,
|
utils::Encode::<rapyd::CaptureRequest>::encode_to_string_of_json,
|
||||||
@ -615,7 +631,13 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
|
|||||||
&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 = rapyd::RapydRefundRequest::try_from(req)?;
|
let connector_router_data = rapyd::RapydRouterData::try_from((
|
||||||
|
&self.get_currency_unit(),
|
||||||
|
req.request.currency,
|
||||||
|
req.request.refund_amount,
|
||||||
|
req,
|
||||||
|
))?;
|
||||||
|
let req_obj = rapyd::RapydRefundRequest::try_from(&connector_router_data)?;
|
||||||
let rapyd_req = types::RequestBody::log_and_get_request_body(
|
let rapyd_req = types::RequestBody::log_and_get_request_body(
|
||||||
&req_obj,
|
&req_obj,
|
||||||
utils::Encode::<rapyd::RapydRefundRequest>::encode_to_string_of_json,
|
utils::Encode::<rapyd::RapydRefundRequest>::encode_to_string_of_json,
|
||||||
|
|||||||
@ -13,6 +13,36 @@ use crate::{
|
|||||||
utils::OptionExt,
|
utils::OptionExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct RapydRouterData<T> {
|
||||||
|
pub amount: i64,
|
||||||
|
pub router_data: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T>
|
||||||
|
TryFrom<(
|
||||||
|
&types::api::CurrencyUnit,
|
||||||
|
types::storage::enums::Currency,
|
||||||
|
i64,
|
||||||
|
T,
|
||||||
|
)> for RapydRouterData<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(Default, Debug, Serialize)]
|
#[derive(Default, Debug, Serialize)]
|
||||||
pub struct RapydPaymentsRequest {
|
pub struct RapydPaymentsRequest {
|
||||||
pub amount: i64,
|
pub amount: i64,
|
||||||
@ -69,18 +99,23 @@ pub struct RapydWallet {
|
|||||||
token: Option<String>,
|
token: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&types::PaymentsAuthorizeRouterData> for RapydPaymentsRequest {
|
impl TryFrom<&RapydRouterData<&types::PaymentsAuthorizeRouterData>> for RapydPaymentsRequest {
|
||||||
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 (capture, payment_method_options) = match item.payment_method {
|
item: &RapydRouterData<&types::PaymentsAuthorizeRouterData>,
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
|
let (capture, payment_method_options) = match item.router_data.payment_method {
|
||||||
diesel_models::enums::PaymentMethod::Card => {
|
diesel_models::enums::PaymentMethod::Card => {
|
||||||
let three_ds_enabled = matches!(item.auth_type, enums::AuthenticationType::ThreeDs);
|
let three_ds_enabled = matches!(
|
||||||
|
item.router_data.auth_type,
|
||||||
|
enums::AuthenticationType::ThreeDs
|
||||||
|
);
|
||||||
let payment_method_options = PaymentMethodOptions {
|
let payment_method_options = PaymentMethodOptions {
|
||||||
three_ds: three_ds_enabled,
|
three_ds: three_ds_enabled,
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
Some(matches!(
|
Some(matches!(
|
||||||
item.request.capture_method,
|
item.router_data.request.capture_method,
|
||||||
Some(enums::CaptureMethod::Automatic) | None
|
Some(enums::CaptureMethod::Automatic) | None
|
||||||
)),
|
)),
|
||||||
Some(payment_method_options),
|
Some(payment_method_options),
|
||||||
@ -88,7 +123,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for RapydPaymentsRequest {
|
|||||||
}
|
}
|
||||||
_ => (None, None),
|
_ => (None, None),
|
||||||
};
|
};
|
||||||
let payment_method = match item.request.payment_method_data {
|
let payment_method = match item.router_data.request.payment_method_data {
|
||||||
api_models::payments::PaymentMethodData::Card(ref ccard) => {
|
api_models::payments::PaymentMethodData::Card(ref ccard) => {
|
||||||
Some(PaymentMethod {
|
Some(PaymentMethod {
|
||||||
pm_type: "in_amex_card".to_owned(), //[#369] Map payment method type based on country
|
pm_type: "in_amex_card".to_owned(), //[#369] Map payment method type based on country
|
||||||
@ -128,10 +163,10 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for RapydPaymentsRequest {
|
|||||||
.change_context(errors::ConnectorError::NotImplemented(
|
.change_context(errors::ConnectorError::NotImplemented(
|
||||||
"payment_method".to_owned(),
|
"payment_method".to_owned(),
|
||||||
))?;
|
))?;
|
||||||
let return_url = item.request.get_return_url()?;
|
let return_url = item.router_data.request.get_return_url()?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
amount: item.request.amount,
|
amount: item.amount,
|
||||||
currency: item.request.currency,
|
currency: item.router_data.request.currency,
|
||||||
payment_method,
|
payment_method,
|
||||||
capture,
|
capture,
|
||||||
payment_method_options,
|
payment_method_options,
|
||||||
@ -276,13 +311,17 @@ pub struct RapydRefundRequest {
|
|||||||
pub currency: Option<enums::Currency>,
|
pub currency: Option<enums::Currency>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> TryFrom<&types::RefundsRouterData<F>> for RapydRefundRequest {
|
impl<F> TryFrom<&RapydRouterData<&types::RefundsRouterData<F>>> for RapydRefundRequest {
|
||||||
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: &RapydRouterData<&types::RefundsRouterData<F>>) -> Result<Self, Self::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
payment: item.request.connector_transaction_id.to_string(),
|
payment: item
|
||||||
amount: Some(item.request.refund_amount),
|
.router_data
|
||||||
currency: Some(item.request.currency),
|
.request
|
||||||
|
.connector_transaction_id
|
||||||
|
.to_string(),
|
||||||
|
amount: Some(item.amount),
|
||||||
|
currency: Some(item.router_data.request.currency),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,11 +419,13 @@ pub struct CaptureRequest {
|
|||||||
statement_descriptor: Option<String>,
|
statement_descriptor: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&types::PaymentsCaptureRouterData> for CaptureRequest {
|
impl TryFrom<&RapydRouterData<&types::PaymentsCaptureRouterData>> for CaptureRequest {
|
||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
fn try_from(item: &types::PaymentsCaptureRouterData) -> Result<Self, Self::Error> {
|
fn try_from(
|
||||||
|
item: &RapydRouterData<&types::PaymentsCaptureRouterData>,
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
amount: Some(item.request.amount_to_capture),
|
amount: Some(item.amount),
|
||||||
receipt_email: None,
|
receipt_email: None,
|
||||||
statement_descriptor: None,
|
statement_descriptor: None,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user