mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
refactor(connector): add amount framework to payme & Trustpay with googlePay, ApplePay for bluesnap, Noon & Trustpay (#4833)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> Co-authored-by: Narayan Bhat <narayan.bhat@juspay.in>
This commit is contained in:
@ -33,6 +33,7 @@ use crate::{
|
||||
types::{
|
||||
self,
|
||||
api::{self, ConnectorCommon, ConnectorCommonExt},
|
||||
transformers::ForeignTryFrom,
|
||||
ErrorResponse, Response,
|
||||
},
|
||||
utils::BytesExt,
|
||||
@ -603,11 +604,20 @@ impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::Payme
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
|
||||
types::RouterData::try_from(types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
http_code: res.status_code,
|
||||
})
|
||||
let req_amount = data.request.minor_amount;
|
||||
let req_currency = data.request.currency;
|
||||
|
||||
let apple_pay_amount =
|
||||
connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
|
||||
|
||||
types::RouterData::foreign_try_from((
|
||||
types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
http_code: res.status_code,
|
||||
},
|
||||
apple_pay_amount,
|
||||
))
|
||||
}
|
||||
|
||||
fn get_error_response(
|
||||
|
||||
@ -470,12 +470,18 @@ impl TryFrom<&types::PaymentsSessionRouterData> for BluesnapCreateWalletToken {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<types::PaymentsSessionResponseRouterData<BluesnapWalletTokenResponse>>
|
||||
for types::PaymentsSessionRouterData
|
||||
impl
|
||||
ForeignTryFrom<(
|
||||
types::PaymentsSessionResponseRouterData<BluesnapWalletTokenResponse>,
|
||||
StringMajorUnit,
|
||||
)> for types::PaymentsSessionRouterData
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: types::PaymentsSessionResponseRouterData<BluesnapWalletTokenResponse>,
|
||||
fn foreign_try_from(
|
||||
(item, apple_pay_amount): (
|
||||
types::PaymentsSessionResponseRouterData<BluesnapWalletTokenResponse>,
|
||||
StringMajorUnit,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
let response = &item.response;
|
||||
|
||||
@ -532,7 +538,7 @@ impl TryFrom<types::PaymentsSessionResponseRouterData<BluesnapWalletTokenRespons
|
||||
total: payments::AmountInfo {
|
||||
label: payment_request_data.label,
|
||||
total_type: Some("final".to_string()),
|
||||
amount: item.data.request.amount.to_string(),
|
||||
amount: apple_pay_amount,
|
||||
},
|
||||
merchant_capabilities: Some(payment_request_data.merchant_capabilities),
|
||||
supported_networks: Some(payment_request_data.supported_networks),
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
pub mod transformers;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use api_models::enums::AuthenticationType;
|
||||
use common_utils::{crypto, request::RequestContent};
|
||||
use common_utils::{
|
||||
crypto,
|
||||
request::RequestContent,
|
||||
types::{
|
||||
AmountConvertor, MinorUnit, MinorUnitForConnector, StringMajorUnit,
|
||||
StringMajorUnitForConnector,
|
||||
},
|
||||
};
|
||||
use diesel_models::enums;
|
||||
use error_stack::{Report, ResultExt};
|
||||
use masking::ExposeInterface;
|
||||
@ -22,14 +27,30 @@ use crate::{
|
||||
types::{
|
||||
self,
|
||||
api::{self, ConnectorCommon, ConnectorCommonExt},
|
||||
domain, ErrorResponse, Response,
|
||||
domain,
|
||||
transformers::ForeignTryFrom,
|
||||
ErrorResponse, Response,
|
||||
},
|
||||
// transformers::{ForeignFrom, ForeignTryFrom},
|
||||
utils::{handle_json_response_deserialization_failure, BytesExt},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Payme;
|
||||
#[derive(Clone)]
|
||||
pub struct Payme {
|
||||
amount_converter: &'static (dyn AmountConvertor<Output = MinorUnit> + Sync),
|
||||
apple_pay_google_pay_amount_converter:
|
||||
&'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
|
||||
}
|
||||
|
||||
impl Payme {
|
||||
pub const fn new() -> &'static Self {
|
||||
&Self {
|
||||
amount_converter: &MinorUnitForConnector,
|
||||
apple_pay_google_pay_amount_converter: &StringMajorUnitForConnector,
|
||||
}
|
||||
}
|
||||
}
|
||||
// dummy commit
|
||||
impl api::Payment for Payme {}
|
||||
impl api::PaymentSession for Payme {}
|
||||
impl api::PaymentsCompleteAuthorize for Payme {}
|
||||
@ -287,10 +308,11 @@ impl
|
||||
req: &types::PaymentsPreProcessingRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let amount = req.request.get_amount()?;
|
||||
let currency = req.request.get_currency()?;
|
||||
let connector_router_data =
|
||||
payme::PaymeRouterData::try_from((&self.get_currency_unit(), currency, amount, req))?;
|
||||
let req_amount = req.request.get_minor_amount()?;
|
||||
let req_currency = req.request.get_currency()?;
|
||||
let amount =
|
||||
connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
|
||||
let connector_req = payme::GenerateSaleRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
@ -329,14 +351,26 @@ impl
|
||||
.parse_struct("Payme GenerateSaleResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
|
||||
let req_amount = data.request.get_minor_amount()?;
|
||||
let req_currency = data.request.get_currency()?;
|
||||
|
||||
let apple_pay_amount = connector_utils::convert_amount(
|
||||
self.apple_pay_google_pay_amount_converter,
|
||||
req_amount,
|
||||
req_currency,
|
||||
)?;
|
||||
|
||||
event_builder.map(|i| i.set_response_body(&response));
|
||||
router_env::logger::info!(connector_response=?response);
|
||||
|
||||
types::RouterData::try_from(types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
http_code: res.status_code,
|
||||
})
|
||||
types::RouterData::foreign_try_from((
|
||||
types::ResponseRouterData {
|
||||
response,
|
||||
data: data.clone(),
|
||||
http_code: res.status_code,
|
||||
},
|
||||
apple_pay_amount,
|
||||
))
|
||||
}
|
||||
|
||||
fn get_error_response(
|
||||
@ -536,12 +570,12 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
let amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_amount,
|
||||
req.request.currency,
|
||||
req.request.amount,
|
||||
req,
|
||||
))?;
|
||||
)?;
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
|
||||
let connector_req = payme::PaymePaymentRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
@ -724,12 +758,12 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
|
||||
req: &types::PaymentsCaptureRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
let amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_amount_to_capture,
|
||||
req.request.currency,
|
||||
req.request.amount_to_capture,
|
||||
req,
|
||||
))?;
|
||||
)?;
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
|
||||
let connector_req = payme::PaymentCaptureRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
@ -822,20 +856,21 @@ impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsR
|
||||
req: &types::PaymentsCancelRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let amount = req
|
||||
.request
|
||||
.amount
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "amount",
|
||||
})?;
|
||||
let currency =
|
||||
let req_amount =
|
||||
req.request
|
||||
.minor_amount
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "amount",
|
||||
})?;
|
||||
let req_currency =
|
||||
req.request
|
||||
.currency
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "currency",
|
||||
})?;
|
||||
let connector_router_data =
|
||||
payme::PaymeRouterData::try_from((&self.get_currency_unit(), currency, amount, req))?;
|
||||
let amount =
|
||||
connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
|
||||
let connector_req = payme::PaymeVoidRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
@ -922,12 +957,12 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
|
||||
req: &types::RefundsRouterData<api::Execute>,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
let amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_refund_amount,
|
||||
req.request.currency,
|
||||
req.request.refund_amount,
|
||||
req,
|
||||
))?;
|
||||
)?;
|
||||
let connector_router_data = payme::PaymeRouterData::try_from((amount, req))?;
|
||||
let connector_req = payme::PaymeRefundRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::Json(Box::new(connector_req)))
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use api_models::enums::{AuthenticationType, PaymentMethod};
|
||||
use common_utils::pii;
|
||||
use common_utils::{
|
||||
pii,
|
||||
types::{MinorUnit, StringMajorUnit},
|
||||
};
|
||||
use error_stack::ResultExt;
|
||||
use masking::{ExposeInterface, Secret};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -18,7 +21,10 @@ use crate::{
|
||||
core::errors,
|
||||
services,
|
||||
types::{
|
||||
self, api, domain, domain::PaymentMethodData, storage::enums, transformers::ForeignFrom,
|
||||
self, api, domain,
|
||||
domain::PaymentMethodData,
|
||||
storage::enums,
|
||||
transformers::{ForeignFrom, ForeignTryFrom},
|
||||
MandateReference,
|
||||
},
|
||||
unimplemented_payment_method,
|
||||
@ -28,15 +34,13 @@ const LANGUAGE: &str = "en";
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PaymeRouterData<T> {
|
||||
pub amount: i64,
|
||||
pub amount: MinorUnit,
|
||||
pub router_data: T,
|
||||
}
|
||||
|
||||
impl<T> TryFrom<(&api::CurrencyUnit, enums::Currency, i64, T)> for PaymeRouterData<T> {
|
||||
impl<T> TryFrom<(MinorUnit, T)> for PaymeRouterData<T> {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
(_currency_unit, _currency, amount, item): (&api::CurrencyUnit, enums::Currency, i64, T),
|
||||
) -> Result<Self, Self::Error> {
|
||||
fn try_from((amount, item): (MinorUnit, T)) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount,
|
||||
router_data: item,
|
||||
@ -57,7 +61,7 @@ pub struct PayRequest {
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct MandateRequest {
|
||||
currency: enums::Currency,
|
||||
sale_price: i64,
|
||||
sale_price: MinorUnit,
|
||||
transaction_id: String,
|
||||
product_name: String,
|
||||
sale_return_url: String,
|
||||
@ -118,7 +122,7 @@ pub struct CaptureBuyerResponse {
|
||||
pub struct GenerateSaleRequest {
|
||||
currency: enums::Currency,
|
||||
sale_type: SaleType,
|
||||
sale_price: i64,
|
||||
sale_price: MinorUnit,
|
||||
transaction_id: String,
|
||||
product_name: String,
|
||||
sale_return_url: String,
|
||||
@ -473,23 +477,27 @@ impl TryFrom<&types::RefundSyncRouterData> for PaymeQueryTransactionRequest {
|
||||
}
|
||||
|
||||
impl<F>
|
||||
TryFrom<
|
||||
ForeignTryFrom<(
|
||||
types::ResponseRouterData<
|
||||
F,
|
||||
GenerateSaleResponse,
|
||||
types::PaymentsPreProcessingData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
> for types::RouterData<F, types::PaymentsPreProcessingData, types::PaymentsResponseData>
|
||||
StringMajorUnit,
|
||||
)> for types::RouterData<F, types::PaymentsPreProcessingData, types::PaymentsResponseData>
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
item: types::ResponseRouterData<
|
||||
F,
|
||||
GenerateSaleResponse,
|
||||
types::PaymentsPreProcessingData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
fn foreign_try_from(
|
||||
(item, apple_pay_amount): (
|
||||
types::ResponseRouterData<
|
||||
F,
|
||||
GenerateSaleResponse,
|
||||
types::PaymentsPreProcessingData,
|
||||
types::PaymentsResponseData,
|
||||
>,
|
||||
StringMajorUnit,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
match item.data.payment_method {
|
||||
PaymentMethod::Card => {
|
||||
@ -537,8 +545,6 @@ impl<F>
|
||||
}
|
||||
_ => {
|
||||
let currency_code = item.data.request.get_currency()?;
|
||||
let amount = item.data.request.get_amount()?;
|
||||
let amount_in_base_unit = utils::to_currency_base_unit(amount, currency_code)?;
|
||||
let pmd = item.data.request.payment_method_data.to_owned();
|
||||
let payme_auth_type = PaymeAuthType::try_from(&item.data.connector_auth_type)?;
|
||||
|
||||
@ -556,7 +562,7 @@ impl<F>
|
||||
total: api_models::payments::AmountInfo {
|
||||
label: "Apple Pay".to_string(),
|
||||
total_type: None,
|
||||
amount: amount_in_base_unit,
|
||||
amount: apple_pay_amount,
|
||||
},
|
||||
merchant_capabilities: None,
|
||||
supported_networks: None,
|
||||
@ -907,7 +913,7 @@ impl<F, T>
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PaymentCaptureRequest {
|
||||
payme_sale_id: String,
|
||||
sale_price: i64,
|
||||
sale_price: MinorUnit,
|
||||
}
|
||||
|
||||
impl TryFrom<&PaymeRouterData<&types::PaymentsCaptureRouterData>> for PaymentCaptureRequest {
|
||||
@ -915,7 +921,9 @@ impl TryFrom<&PaymeRouterData<&types::PaymentsCaptureRouterData>> for PaymentCap
|
||||
fn try_from(
|
||||
item: &PaymeRouterData<&types::PaymentsCaptureRouterData>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
if item.router_data.request.amount_to_capture != item.router_data.request.payment_amount {
|
||||
if item.router_data.request.minor_amount_to_capture
|
||||
!= item.router_data.request.minor_payment_amount
|
||||
{
|
||||
Err(errors::ConnectorError::NotSupported {
|
||||
message: "Partial Capture".to_string(),
|
||||
connector: "Payme",
|
||||
@ -932,7 +940,7 @@ impl TryFrom<&PaymeRouterData<&types::PaymentsCaptureRouterData>> for PaymentCap
|
||||
// Type definition for RefundRequest
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PaymeRefundRequest {
|
||||
sale_refund_amount: i64,
|
||||
sale_refund_amount: MinorUnit,
|
||||
payme_sale_id: String,
|
||||
seller_payme_id: Secret<String>,
|
||||
language: String,
|
||||
|
||||
@ -1,18 +1,21 @@
|
||||
pub mod transformers;
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use base64::Engine;
|
||||
use common_utils::{
|
||||
crypto, errors::ReportSwitchExt, ext_traits::ByteSliceExt, request::RequestContent,
|
||||
crypto,
|
||||
errors::ReportSwitchExt,
|
||||
ext_traits::ByteSliceExt,
|
||||
request::RequestContent,
|
||||
types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector},
|
||||
};
|
||||
use error_stack::{Report, ResultExt};
|
||||
use masking::PeekInterface;
|
||||
use transformers as trustpay;
|
||||
|
||||
use super::utils::{
|
||||
collect_and_sort_values_by_removing_signature, get_error_code_error_message_based_on_priority,
|
||||
ConnectorErrorType, ConnectorErrorTypeMapping, PaymentsPreProcessingData,
|
||||
self as connector_utils, collect_and_sort_values_by_removing_signature,
|
||||
get_error_code_error_message_based_on_priority, ConnectorErrorType, ConnectorErrorTypeMapping,
|
||||
PaymentsPreProcessingData,
|
||||
};
|
||||
use crate::{
|
||||
configs::settings,
|
||||
@ -36,8 +39,18 @@ use crate::{
|
||||
utils::{self, BytesExt},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Trustpay;
|
||||
#[derive(Clone)]
|
||||
pub struct Trustpay {
|
||||
amount_converter: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync),
|
||||
}
|
||||
|
||||
impl Trustpay {
|
||||
pub fn new() -> &'static Self {
|
||||
&Self {
|
||||
amount_converter: &StringMajorUnitForConnector,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Trustpay
|
||||
where
|
||||
@ -462,14 +475,13 @@ impl
|
||||
req: &types::PaymentsPreProcessingRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let currency = req.request.get_currency()?;
|
||||
let amount = req.request.get_amount()?;
|
||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
currency,
|
||||
amount,
|
||||
req,
|
||||
))?;
|
||||
let req_currency = req.request.get_currency()?;
|
||||
let req_amount = req.request.get_minor_amount()?;
|
||||
|
||||
let amount =
|
||||
connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?;
|
||||
|
||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((amount, req))?;
|
||||
let connector_req =
|
||||
trustpay::TrustpayCreateIntentRequest::try_from(&connector_router_data)?;
|
||||
Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
|
||||
@ -576,13 +588,12 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let amount = req.request.amount;
|
||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
let amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_amount,
|
||||
req.request.currency,
|
||||
amount,
|
||||
req,
|
||||
))?;
|
||||
)?;
|
||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((amount, req))?;
|
||||
let connector_req = trustpay::TrustpayPaymentsRequest::try_from(&connector_router_data)?;
|
||||
match req.payment_method {
|
||||
diesel_models::enums::PaymentMethod::BankRedirect => {
|
||||
@ -686,12 +697,13 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon
|
||||
req: &types::RefundsRouterData<api::Execute>,
|
||||
_connectors: &settings::Connectors,
|
||||
) -> CustomResult<RequestContent, errors::ConnectorError> {
|
||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((
|
||||
&self.get_currency_unit(),
|
||||
let amount = connector_utils::convert_amount(
|
||||
self.amount_converter,
|
||||
req.request.minor_refund_amount,
|
||||
req.request.currency,
|
||||
req.request.refund_amount,
|
||||
req,
|
||||
))?;
|
||||
)?;
|
||||
|
||||
let connector_router_data = trustpay::TrustpayRouterData::try_from((amount, req))?;
|
||||
let connector_req = trustpay::TrustpayRefundRequest::try_from(&connector_router_data)?;
|
||||
match req.payment_method {
|
||||
diesel_models::enums::PaymentMethod::BankRedirect => {
|
||||
|
||||
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
||||
use common_utils::{
|
||||
errors::CustomResult,
|
||||
pii::{self, Email},
|
||||
types::StringMajorUnit,
|
||||
};
|
||||
use error_stack::{report, ResultExt};
|
||||
use masking::{ExposeInterface, PeekInterface, Secret};
|
||||
@ -24,21 +25,13 @@ type Error = error_stack::Report<errors::ConnectorError>;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct TrustpayRouterData<T> {
|
||||
pub amount: String,
|
||||
pub amount: StringMajorUnit,
|
||||
pub router_data: T,
|
||||
}
|
||||
|
||||
impl<T> TryFrom<(&types::api::CurrencyUnit, enums::Currency, i64, T)> for TrustpayRouterData<T> {
|
||||
impl<T> TryFrom<(StringMajorUnit, T)> for TrustpayRouterData<T> {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(
|
||||
(currency_unit, currency, amount, item): (
|
||||
&types::api::CurrencyUnit,
|
||||
enums::Currency,
|
||||
i64,
|
||||
T,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
let amount = utils::get_amount_as_string(currency_unit, amount, currency)?;
|
||||
fn try_from((amount, item): (StringMajorUnit, T)) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
amount,
|
||||
router_data: item,
|
||||
@ -97,7 +90,7 @@ pub struct References {
|
||||
#[derive(Default, Debug, Serialize, Deserialize, Eq, PartialEq, Clone)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct Amount {
|
||||
pub amount: String,
|
||||
pub amount: StringMajorUnit,
|
||||
pub currency: String,
|
||||
}
|
||||
|
||||
@ -147,7 +140,7 @@ pub struct CallbackURLs {
|
||||
|
||||
#[derive(Debug, Serialize, PartialEq)]
|
||||
pub struct PaymentRequestCards {
|
||||
pub amount: String,
|
||||
pub amount: StringMajorUnit,
|
||||
pub currency: String,
|
||||
pub pan: cards::CardNumber,
|
||||
pub cvv: Secret<String>,
|
||||
@ -273,7 +266,7 @@ fn get_card_request_data(
|
||||
item: &types::PaymentsAuthorizeRouterData,
|
||||
browser_info: &BrowserInformation,
|
||||
params: TrustpayMandatoryParams,
|
||||
amount: String,
|
||||
amount: StringMajorUnit,
|
||||
ccard: &domain::payments::Card,
|
||||
return_url: String,
|
||||
) -> Result<TrustpayPaymentsRequest, Error> {
|
||||
@ -353,7 +346,7 @@ fn get_bank_redirection_request_data(
|
||||
item: &types::PaymentsAuthorizeRouterData,
|
||||
bank_redirection_data: &domain::BankRedirectData,
|
||||
params: TrustpayMandatoryParams,
|
||||
amount: String,
|
||||
amount: StringMajorUnit,
|
||||
auth: TrustpayAuthType,
|
||||
) -> Result<TrustpayPaymentsRequest, error_stack::Report<errors::ConnectorError>> {
|
||||
let pm = TrustpayPaymentMethod::try_from(bank_redirection_data)?;
|
||||
@ -1016,7 +1009,7 @@ impl<F, T> TryFrom<types::ResponseRouterData<F, TrustpayAuthUpdateResponse, T, t
|
||||
#[derive(Default, Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TrustpayCreateIntentRequest {
|
||||
pub amount: String,
|
||||
pub amount: StringMajorUnit,
|
||||
pub currency: String,
|
||||
// If true, Apple Pay will be initialized
|
||||
pub init_apple_pay: Option<bool>,
|
||||
@ -1084,7 +1077,7 @@ pub struct GooglePayTransactionInfo {
|
||||
pub country_code: api_models::enums::CountryAlpha2,
|
||||
pub currency_code: api_models::enums::Currency,
|
||||
pub total_price_status: String,
|
||||
pub total_price: String,
|
||||
pub total_price: StringMajorUnit,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
||||
@ -1155,7 +1148,7 @@ pub struct TrustpayApplePayResponse {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ApplePayTotalInfo {
|
||||
pub label: String,
|
||||
pub amount: String,
|
||||
pub amount: StringMajorUnit,
|
||||
}
|
||||
|
||||
impl<F>
|
||||
@ -1392,7 +1385,7 @@ impl From<ApplePayTotalInfo> for api_models::payments::AmountInfo {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TrustpayRefundRequestCards {
|
||||
instance_id: String,
|
||||
amount: String,
|
||||
amount: StringMajorUnit,
|
||||
currency: String,
|
||||
reference: String,
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
use api_models::payments as payment_types;
|
||||
use async_trait::async_trait;
|
||||
use common_utils::{ext_traits::ByteSliceExt, request::RequestContent};
|
||||
use common_utils::{
|
||||
ext_traits::ByteSliceExt,
|
||||
request::RequestContent,
|
||||
types::{AmountConvertor, StringMajorUnitForConnector},
|
||||
};
|
||||
use error_stack::{Report, ResultExt};
|
||||
use masking::ExposeInterface;
|
||||
use router_env::metrics::add_attributes;
|
||||
@ -403,15 +407,16 @@ fn get_apple_pay_amount_info(
|
||||
label: &str,
|
||||
session_data: types::PaymentsSessionData,
|
||||
) -> RouterResult<payment_types::AmountInfo> {
|
||||
let required_amount_type = StringMajorUnitForConnector;
|
||||
let apple_pay_amount = required_amount_type
|
||||
.convert(session_data.minor_amount, session_data.currency)
|
||||
.change_context(errors::ApiErrorResponse::PreconditionFailed {
|
||||
message: "Failed to convert amount to string major unit for applePay".to_string(),
|
||||
})?;
|
||||
let amount_info = payment_types::AmountInfo {
|
||||
label: label.to_string(),
|
||||
total_type: Some("final".to_string()),
|
||||
amount: session_data
|
||||
.currency
|
||||
.to_currency_base_unit(session_data.amount)
|
||||
.change_context(errors::ApiErrorResponse::PreconditionFailed {
|
||||
message: "Failed to convert currency to base unit".to_string(),
|
||||
})?,
|
||||
amount: apple_pay_amount,
|
||||
};
|
||||
|
||||
Ok(amount_info)
|
||||
@ -548,22 +553,21 @@ fn create_gpay_session_token(
|
||||
},
|
||||
)
|
||||
.collect();
|
||||
|
||||
let required_amount_type = StringMajorUnitForConnector;
|
||||
let google_pay_amount = required_amount_type
|
||||
.convert(
|
||||
router_data.request.minor_amount,
|
||||
router_data.request.currency,
|
||||
)
|
||||
.change_context(errors::ApiErrorResponse::PreconditionFailed {
|
||||
message: "Failed to convert amount to string major unit for googlePay".to_string(),
|
||||
})?;
|
||||
let session_data = router_data.request.clone();
|
||||
let transaction_info = payment_types::GpayTransactionInfo {
|
||||
country_code: session_data.country.unwrap_or_default(),
|
||||
currency_code: router_data.request.currency,
|
||||
total_price_status: "Final".to_string(),
|
||||
total_price: router_data
|
||||
.request
|
||||
.currency
|
||||
.to_currency_base_unit(router_data.request.amount)
|
||||
.attach_printable(
|
||||
"Cannot convert given amount to base currency denomination".to_string(),
|
||||
)
|
||||
.change_context(errors::ApiErrorResponse::InvalidDataValue {
|
||||
field_name: "amount",
|
||||
})?,
|
||||
total_price: google_pay_amount,
|
||||
};
|
||||
|
||||
let required_shipping_contact_fields =
|
||||
|
||||
@ -1556,6 +1556,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
|
||||
|
||||
Ok(Self {
|
||||
amount: amount.get_amount_as_i64(), //need to change once we move to connector module
|
||||
minor_amount: amount,
|
||||
currency: payment_data.currency,
|
||||
country: payment_data.address.get_payment_method_billing().and_then(
|
||||
|billing_address| {
|
||||
|
||||
@ -437,7 +437,9 @@ impl ConnectorData {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Opennode)))
|
||||
}
|
||||
// "payeezy" => Ok(ConnectorIntegrationEnum::Old(Box::new(&connector::Payeezy)), As psync and rsync are not supported by this connector, it is added as template code for future usage
|
||||
enums::Connector::Payme => Ok(ConnectorEnum::Old(Box::new(&connector::Payme))),
|
||||
enums::Connector::Payme => {
|
||||
Ok(ConnectorEnum::Old(Box::new(connector::Payme::new())))
|
||||
}
|
||||
enums::Connector::Payone => Ok(ConnectorEnum::Old(Box::new(&connector::Payone))),
|
||||
enums::Connector::Payu => Ok(ConnectorEnum::Old(Box::new(&connector::Payu))),
|
||||
enums::Connector::Placetopay => {
|
||||
@ -477,7 +479,7 @@ impl ConnectorData {
|
||||
}
|
||||
enums::Connector::Paypal => Ok(ConnectorEnum::Old(Box::new(&connector::Paypal))),
|
||||
enums::Connector::Trustpay => {
|
||||
Ok(ConnectorEnum::Old(Box::new(&connector::Trustpay)))
|
||||
Ok(ConnectorEnum::Old(Box::new(connector::Trustpay::new())))
|
||||
}
|
||||
enums::Connector::Tsys => Ok(ConnectorEnum::Old(Box::new(&connector::Tsys))),
|
||||
enums::Connector::Volt => Ok(ConnectorEnum::Old(Box::new(&connector::Volt))),
|
||||
|
||||
@ -17,7 +17,7 @@ impl utils::Connector for PaymeTest {
|
||||
fn get_data(&self) -> types::api::ConnectorData {
|
||||
use router::connector::Payme;
|
||||
utils::construct_connector_data_old(
|
||||
Box::new(&Payme),
|
||||
Box::new(Payme::new()),
|
||||
types::Connector::Payme,
|
||||
types::api::GetToken::Connector,
|
||||
None,
|
||||
|
||||
@ -15,7 +15,7 @@ impl utils::Connector for TrustpayTest {
|
||||
fn get_data(&self) -> api::ConnectorData {
|
||||
use router::connector::Trustpay;
|
||||
utils::construct_connector_data_old(
|
||||
Box::new(&Trustpay),
|
||||
Box::new(Trustpay::new()),
|
||||
types::Connector::Trustpay,
|
||||
api::GetToken::Connector,
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user