Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector): add amount framework to payme & Trustpay with googlePay, ApplePay for bluesnap, Noon & Trustpay #4833

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
9ef9de9
refactor(router): added a new type minor unit to amount
sahkal May 13, 2024
a1bb647
chore: run formatter
hyperswitch-bot[bot] May 13, 2024
f6c4946
refactor(router): fixed clippy issue
sahkal May 13, 2024
937687a
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 13, 2024
61850dc
refactor(router): fixed openapi specs
sahkal May 13, 2024
c840348
Merge branch 'main' into change_core_amount_to_domain_type
sahkal May 13, 2024
6103485
refactor(router): fixed capture amount unequal bug
sahkal May 13, 2024
0c214b7
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 13, 2024
a994132
refactor(router): fixed open-api issue
sahkal May 13, 2024
02a7048
refactor(router): addressed pr comments
sahkal May 14, 2024
fe6dd36
refactor(router): resolved merge conflicts
sahkal May 15, 2024
9852bf4
refactor(router): fixed spell check issue
sahkal May 15, 2024
41af58f
refactor(router): resolved pr comments:
sahkal May 16, 2024
3df68ba
Merge branch 'main' into change_core_amount_to_domain_type
hrithikesh026 May 16, 2024
6e6726f
refactor(router): resolved pr comments
sahkal May 17, 2024
68034cb
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 17, 2024
1b623a8
refactor(router): fixed clippy issue
sahkal May 17, 2024
eff793f
refactor(router): fixed clippy issue
sahkal May 17, 2024
bce3de0
refactor(router): fixed open-api-specs
sahkal May 17, 2024
63ef54c
refactor(router): fixed open-api specs
sahkal May 17, 2024
17c58f4
chore: run formatter
hyperswitch-bot[bot] May 17, 2024
f76ba1d
refactor(router): fixed clippy issue
sahkal May 17, 2024
5b657f9
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 17, 2024
59ffc34
refactor(router): resolved comments
sahkal May 17, 2024
9ba21c4
chore: run formatter
hyperswitch-bot[bot] May 17, 2024
3bce742
refactor(router): resolved comments
sahkal May 17, 2024
5b8cf34
Merge branch 'change_core_amount_to_domain_type' of https://github.co…
sahkal May 17, 2024
23e9158
refactor(router): fixed clippy issue
sahkal May 17, 2024
78d71ba
feat(router
sahkal May 20, 2024
d4c363f
wip: reduce errors
Narayanbhat166 May 20, 2024
ddee2bd
chore: make it finally compile
Narayanbhat166 May 20, 2024
6e0070d
chore: run formatter
hyperswitch-bot[bot] May 20, 2024
44caf0b
feat(router): added conversion trait in core for connector to use
sahkal May 21, 2024
d5f951f
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 21, 2024
c0f549e
chore: run formatter
hyperswitch-bot[bot] May 21, 2024
1a9fe2a
refactor
sahkal May 23, 2024
53f0465
refactor(router): resolved merge conflicts
sahkal May 23, 2024
f30b388
refactor(router): fixed clippy issues
sahkal May 23, 2024
8647c28
refactor(router): resolved merge conflicts
sahkal May 23, 2024
fc05741
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 23, 2024
db98d60
refactor(router):fixed open-api issue
sahkal May 23, 2024
4ddb24c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 23, 2024
d94ef10
refactor(router): removed unnecessary code
sahkal May 23, 2024
4910dec
refactor(router): added unit test case for amount conversions
sahkal May 27, 2024
37f5b1c
refactor(router): added unit case for three_decimal_currency
sahkal May 27, 2024
bc00c63
refactor(router): addressed pr comments
sahkal May 28, 2024
11a6b2c
refactor(router): resolved merge conflicts
sahkal May 28, 2024
3547356
refactor(router): removed test_amount from tests
sahkal May 28, 2024
7a916a5
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 28, 2024
d9b564b
refactor(router): fixed clippy issues
sahkal May 28, 2024
5b9c363
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 28, 2024
6b8c733
refactor(router): fixed open api issue
sahkal May 28, 2024
56ea730
refactor(connector): changed amount to minor Unit for stripe
sahkal May 28, 2024
96f9aa3
chore: run formatter
hyperswitch-bot[bot] May 28, 2024
5be12e1
refactor(router): mapped error to error message
sahkal May 28, 2024
fa440df
chore: run formatter
hyperswitch-bot[bot] May 28, 2024
0ba13c1
refactor(router): resolved merge conflict
sahkal May 29, 2024
34f220c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
6967e5f
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
773b458
refactor(router): addressed pr comments
sahkal May 29, 2024
8d51b46
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
64b8693
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 29, 2024
1939b5f
refactor(router): fixed open-api specs'
sahkal May 29, 2024
1daa5a9
refactor(router): fixed open-api specs'
sahkal May 29, 2024
7edf17b
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] May 29, 2024
8ac5ecc
refactor(router): fixed clippy issue
sahkal May 29, 2024
511322c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
97113c9
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
7fd1af9
refactor(router): fixed open-api specs
sahkal May 29, 2024
f2a70b5
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
9cdea2d
refactor(router): resolved merge conflicts
sahkal May 29, 2024
c4bd128
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
35c47fe
refactor(router): fixed cargo hack issue
sahkal May 29, 2024
d009312
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 29, 2024
3135548
chore: run formatter
hyperswitch-bot[bot] May 29, 2024
d20810c
Merge branch 'move-newType-amount-to-connector-module' of https://git…
sahkal May 30, 2024
4a259a4
refactor(connector): added amount frame work support for stripe
sahkal May 30, 2024
3366b2e
chore: run formatter
hyperswitch-bot[bot] May 30, 2024
88ea441
refactor(connector): added amount frame work to bluesnap
sahkal May 30, 2024
94f6f55
refactor(connector): addressed pr comments
sahkal May 30, 2024
0dceb91
refactor(connector): added captured amount to router data
sahkal May 30, 2024
2867fb6
chore: run formatter
hyperswitch-bot[bot] May 30, 2024
bf9393a
refactor(connector):added amount framework to charged object
sahkal May 30, 2024
80efa5a
Merge branch '5177-amount-conversion-do-amount-conversion-for-stripe'…
sahkal May 30, 2024
8efa34e
refactor(connector): resolved pr comments
sahkal May 30, 2024
4be4348
refactor(connector): resolved merge conflicts
sahkal May 31, 2024
14c6bbc
Merge branch '5177-amount-conversion-do-amount-conversion-for-stripe'…
sahkal May 31, 2024
7c34670
refactor(connector): fixed compile issue
sahkal May 31, 2024
fcccf0b
chore: run formatter
hyperswitch-bot[bot] May 31, 2024
c286940
refactor(connector): added amount framework to payme connector
sahkal May 31, 2024
2a8e628
chore: run formatter
hyperswitch-bot[bot] May 31, 2024
e9b59e7
refactor(connector): fixed clippy issue
sahkal May 31, 2024
0bb7164
Merge branch '5178-amount-conversion-do-amount-conversion-for-bluesna…
sahkal May 31, 2024
b63687d
refactor(connector): added uniformity in stripe for amount framework
sahkal May 31, 2024
c5ff47f
chore: run formatter
hyperswitch-bot[bot] May 31, 2024
66c46e4
Merge branch '5177-amount-conversion-do-amount-conversion-for-stripe'…
sahkal May 31, 2024
0ba9923
Merge branch '5177-amount-conversion-do-amount-conversion-for-stripe'…
sahkal May 31, 2024
3ee29da
refactor(connector): added convertion uniformity to payme for amount …
sahkal May 31, 2024
64b2a40
chore: run formatter
hyperswitch-bot[bot] May 31, 2024
64cdad8
refactor(connector): added amount frame work for noon
sahkal May 31, 2024
5f84aa5
chore: run formatter
hyperswitch-bot[bot] May 31, 2024
3462c59
Refactor(connector): added amount framework for trustpay
sahkal Jun 3, 2024
161a013
refactor(connector): added applepay fix for connectors
sahkal Jun 3, 2024
875071b
chore: run formatter
hyperswitch-bot[bot] Jun 3, 2024
9ba500e
refactor(connector): added amount frame work for google pay apple pay
sahkal Jun 3, 2024
3c5a29f
refactor(connector): resolved merge conflicts
sahkal Jun 3, 2024
66dba1d
refactor(connector): fixed open-api specs
sahkal Jun 3, 2024
699a7a9
Merge branch '5178-amount-conversion-do-amount-conversion-for-bluesna…
sahkal Jun 5, 2024
f0b4593
refactor(router): removed payme from noon
sahkal Jun 5, 2024
e651eca
chore: run formatter
hyperswitch-bot[bot] Jun 5, 2024
4faa30b
refactor(connector): fixed test files
sahkal Jun 5, 2024
b3ad755
Merge branch '5182-amount-conversion-do-amount-conversion-for-noon' o…
sahkal Jun 5, 2024
42a0d89
refactor(router): fix merge issues:
sahkal Jun 7, 2024
b482047
refactor(connector): resolved merge conflicts
sahkal Jun 19, 2024
25ca693
refactor(connector): resolved pr comments:
sahkal Jun 24, 2024
dcbe296
refactor(connector): resolved merge conflicts
sahkal Jun 24, 2024
1041fbf
refactor(connector): fixed ci checks failures
sahkal Jun 24, 2024
d31ce2b
Merge branch 'main' into 5179-amount-conversion-do-amount-conversion-…
sahkal Jun 24, 2024
ccba972
refactor(connector): adderessed pr comments
sahkal Jun 25, 2024
b777a3f
Merge branch '5179-amount-conversion-do-amount-conversion-for-payme' …
sahkal Jun 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5001,7 +5001,8 @@
},
"amount": {
"type": "string",
"description": "The total amount for the payment"
"description": "The total amount for the payment in majot unit string (Ex: 38.02)",
"example": "38.02"
}
}
},
Expand Down Expand Up @@ -10039,7 +10040,8 @@
},
"total_price": {
"type": "string",
"description": "The total price"
"description": "The total price",
"example": "38.02"
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use common_utils::{
ext_traits::{ConfigExt, Encode},
id_type,
pii::{self, Email},
types::MinorUnit,
types::{MinorUnit, StringMajorUnit},
};
use masking::{PeekInterface, Secret};
use router_derive::Setter;
Expand Down Expand Up @@ -4174,7 +4174,8 @@ pub struct GpayTransactionInfo {
/// The total price status (ex: 'FINAL')
pub total_price_status: String,
/// The total price
pub total_price: String,
#[schema(value_type = String, example = "38.02")]
pub total_price: StringMajorUnit,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down Expand Up @@ -4546,8 +4547,9 @@ pub struct AmountInfo {
/// A value that indicates whether the line item(Ex: total, tax, discount, or grand total) is final or pending.
#[serde(rename = "type")]
pub total_type: Option<String>,
/// The total amount for the payment
pub amount: String,
/// The total amount for the payment in majot unit string (Ex: 38.02)
#[schema(value_type = String, example = "38.02")]
pub amount: StringMajorUnit,
}

#[derive(Debug, Clone, serde::Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ pub struct PaymentsSessionData {
pub country: Option<common_enums::CountryAlpha2>,
pub surcharge_details: Option<SurchargeDetails>,
pub order_details: Option<Vec<api_models::payments::OrderDetailsWithAmount>>,

// Minor Unit amount for amount frame work
pub minor_amount: MinorUnit,
}

#[derive(Debug, Clone)]
Expand Down
20 changes: 15 additions & 5 deletions crates/router/src/connector/bluesnap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
transformers::ForeignTryFrom,
ErrorResponse, Response,
},
utils::BytesExt,
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 11 additions & 5 deletions crates/router/src/connector/bluesnap/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down
113 changes: 74 additions & 39 deletions crates/router/src/connector/payme.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {}
Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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)))
}
Expand Down
Loading
Loading