-
Notifications
You must be signed in to change notification settings - Fork 4.6k
refactor(connector): added amount conversion framework for powertranz #6239
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
Changes from all commits
033033f
fb447d4
9ee90a1
577b78d
b5f182a
ce12339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| pub mod transformers; | ||
|
|
||
| use std::fmt::Debug; | ||
|
|
||
| use api_models::enums::AuthenticationType; | ||
| use common_enums::enums; | ||
| use common_utils::{ | ||
| errors::CustomResult, | ||
| ext_traits::{BytesExt, ValueExt}, | ||
| request::{Method, Request, RequestBuilder, RequestContent}, | ||
| types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector}, | ||
| }; | ||
| use error_stack::{report, ResultExt}; | ||
| use hyperswitch_domain_models::{ | ||
|
|
@@ -49,8 +48,18 @@ use crate::{ | |
| utils::{self, PaymentsAuthorizeRequestData as _, PaymentsCompleteAuthorizeRequestData as _}, | ||
| }; | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct Powertranz; | ||
| #[derive(Clone)] | ||
| pub struct Powertranz { | ||
| amount_converter: &'static (dyn AmountConvertor<Output = StringMajorUnit> + Sync), | ||
| } | ||
|
|
||
| impl Powertranz { | ||
| pub fn new() -> &'static Self { | ||
| &Self { | ||
| amount_converter: &StringMajorUnitForConnector, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| } | ||
| } | ||
| } | ||
|
|
||
| impl api::Payment for Powertranz {} | ||
| impl api::PaymentSession for Powertranz {} | ||
|
|
@@ -214,7 +223,13 @@ impl ConnectorIntegration<Authorize, PaymentsAuthorizeData, PaymentsResponseData | |
| req: &PaymentsAuthorizeRouterData, | ||
| _connectors: &Connectors, | ||
| ) -> CustomResult<RequestContent, errors::ConnectorError> { | ||
| let connector_req = powertranz::PowertranzPaymentsRequest::try_from(req)?; | ||
| let amount_to_capture = utils::convert_amount( | ||
| self.amount_converter, | ||
| req.request.minor_amount, | ||
| req.request.currency, | ||
| )?; | ||
| let connector_router_data = powertranz::PowertranzRouterData::from((amount_to_capture, req)); | ||
| let connector_req = powertranz::PowertranzPaymentsRequest::try_from(&connector_router_data)?; | ||
| Ok(RequestContent::Json(Box::new(connector_req))) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| use common_enums::enums::{self, AuthenticationType, Currency}; | ||
| use common_utils::pii::IpAddress; | ||
| use common_utils::{pii::IpAddress, types::{StringMajorUnit}}; | ||
| use hyperswitch_domain_models::{ | ||
| payment_method_data::{Card, PaymentMethodData}, | ||
| router_data::{ConnectorAuthType, ErrorResponse, RouterData}, | ||
|
|
@@ -20,6 +20,20 @@ use crate::{ | |
| utils::{self, CardData, PaymentsAuthorizeRequestData, RouterData as _}, | ||
| }; | ||
|
|
||
| pub struct PowertranzRouterData<T> { | ||
| pub amount: StringMajorUnit, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
| pub router_data: T, | ||
| } | ||
|
|
||
| impl<T> From<(StringMajorUnit, T)> for PowertranzRouterData<T> { | ||
| fn from((amount, item): (StringMajorUnit, T)) -> Self { | ||
| Self { | ||
| amount, | ||
| router_data: item, | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+28
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
|
|
||
| const ISO_SUCCESS_CODES: [&str; 7] = ["00", "3D0", "3D1", "HP0", "TK0", "SP4", "FC0"]; | ||
|
|
||
| #[derive(Debug, Serialize)] | ||
|
|
@@ -103,12 +117,12 @@ pub struct RedirectResponsePayload { | |
| pub spi_token: Secret<String>, | ||
| } | ||
|
|
||
| impl TryFrom<&PaymentsAuthorizeRouterData> for PowertranzPaymentsRequest { | ||
| impl TryFrom<&PowertranzRouterData<&PaymentsAuthorizeRouterData>> for PowertranzPaymentsRequest { | ||
| type Error = error_stack::Report<errors::ConnectorError>; | ||
| fn try_from(item: &PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> { | ||
| let source = match item.request.payment_method_data.clone() { | ||
| fn try_from(item: &PowertranzRouterData<&PaymentsAuthorizeRouterData>) -> Result<Self, Self::Error> { | ||
| let source = match item.router_data.request.payment_method_data.clone() { | ||
| PaymentMethodData::Card(card) => { | ||
| let card_holder_name = item.get_optional_billing_full_name(); | ||
| let card_holder_name = item.router_data.get_optional_billing_full_name(); | ||
| Source::try_from((&card, card_holder_name)) | ||
| } | ||
| PaymentMethodData::Wallet(_) | ||
|
|
@@ -137,20 +151,20 @@ impl TryFrom<&PaymentsAuthorizeRouterData> for PowertranzPaymentsRequest { | |
| }?; | ||
| // let billing_address = get_address_details(&item.address.billing, &item.request.email); | ||
| // let shipping_address = get_address_details(&item.address.shipping, &item.request.email); | ||
| let (three_d_secure, extended_data) = match item.auth_type { | ||
| AuthenticationType::ThreeDs => (true, Some(ExtendedData::try_from(item)?)), | ||
| let (three_d_secure, extended_data) = match item.router_data.auth_type { | ||
| AuthenticationType::ThreeDs => (true, Some(ExtendedData::try_from(item.router_data)?)), | ||
| AuthenticationType::NoThreeDs => (false, None), | ||
| }; | ||
| Ok(Self { | ||
| transaction_identifier: Uuid::new_v4().to_string(), | ||
| total_amount: utils::to_currency_base_unit_asf64( | ||
| item.request.amount, | ||
| item.request.currency, | ||
| item.router_data.request.amount, | ||
| item.router_data.request.currency, | ||
| )?, | ||
|
Comment on lines
160
to
163
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the amount from PowertranzRouterData instead on converting at place |
||
| currency_code: Currency::iso_4217(&item.request.currency).to_string(), | ||
| currency_code: Currency::iso_4217(&item.router_data.request.currency).to_string(), | ||
| three_d_secure, | ||
| source, | ||
| order_identifier: item.connector_request_reference_id.clone(), | ||
| order_identifier: item.router_data.connector_request_reference_id.clone(), | ||
| // billing_address, | ||
| // shipping_address, | ||
| extended_data, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
FloatMajorUnitfor conversion