mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(connector): Add amount conversion framework to iatapay along with amount conversion code to connector template (#4866)
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:
		| @ -1,9 +1,12 @@ | |||||||
| pub mod transformers; | pub mod transformers; | ||||||
|  |  | ||||||
| use std::fmt::Debug; |  | ||||||
| use error_stack::{report, ResultExt}; | use error_stack::{report, ResultExt}; | ||||||
| use masking::ExposeInterface; | use masking::ExposeInterface; | ||||||
|  |  | ||||||
|  | use common_utils::{ | ||||||
|  |     types::{AmountConvertor, StringMinorUnit, StringMinorUnitForConnector} | ||||||
|  | }; | ||||||
|  | use super::utils::{self as connector_utils}; | ||||||
| use crate::{ | use crate::{ | ||||||
|     events::connector_api_logs::ConnectorEvent, |     events::connector_api_logs::ConnectorEvent, | ||||||
|     configs::settings, |     configs::settings, | ||||||
| @ -22,8 +25,18 @@ use crate::{ | |||||||
|  |  | ||||||
| use transformers as {{project-name | downcase}}; | use transformers as {{project-name | downcase}}; | ||||||
|  |  | ||||||
| #[derive(Debug, Clone)] | #[derive(Clone)] | ||||||
| pub struct {{project-name | downcase | pascal_case}}; | pub struct {{project-name | downcase | pascal_case}} { | ||||||
|  |     amount_converter: &'static (dyn AmountConvertor<Output = StringMinorUnit> + Sync) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl {{project-name | downcase | pascal_case}} { | ||||||
|  |     pub fn new() -> &'static Self { | ||||||
|  |         &Self { | ||||||
|  |             amount_converter: &StringMinorUnitForConnector | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| impl api::Payment for {{project-name | downcase | pascal_case}} {} | impl api::Payment for {{project-name | downcase | pascal_case}} {} | ||||||
| impl api::PaymentSession for {{project-name | downcase | pascal_case}} {} | impl api::PaymentSession for {{project-name | downcase | pascal_case}} {} | ||||||
| @ -164,13 +177,17 @@ impl | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn get_request_body(&self, req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> { |     fn get_request_body(&self, req: &types::PaymentsAuthorizeRouterData, _connectors: &settings::Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> { | ||||||
|         let connector_router_data = |         let amount = connector_utils::convert_amount( | ||||||
|             {{project-name | downcase}}::{{project-name | downcase | pascal_case}}RouterData::try_from(( |             self.amount_converter, | ||||||
|                 &self.get_currency_unit(), |             req.request.minor_amount, | ||||||
|             req.request.currency, |             req.request.currency, | ||||||
|                 req.request.amount, |         )?; | ||||||
|  |  | ||||||
|  |         let connector_router_data = | ||||||
|  |             {{project-name | downcase}}::{{project-name | downcase | pascal_case}}RouterData::from(( | ||||||
|  |                 amount, | ||||||
|                 req, |                 req, | ||||||
|             ))?; |             )); | ||||||
|         let connector_req = {{project-name | downcase}}::{{project-name | downcase | pascal_case}}PaymentsRequest::try_from(&connector_router_data)?; |         let connector_req = {{project-name | downcase}}::{{project-name | downcase | pascal_case}}PaymentsRequest::try_from(&connector_router_data)?; | ||||||
|         Ok(RequestContent::Json(Box::new(connector_req))) |         Ok(RequestContent::Json(Box::new(connector_req))) | ||||||
|     } |     } | ||||||
| @ -391,13 +408,17 @@ impl | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn get_request_body(&self, req: &types::RefundsRouterData<api::Execute>, _connectors: &settings::Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> { |     fn get_request_body(&self, req: &types::RefundsRouterData<api::Execute>, _connectors: &settings::Connectors,) -> CustomResult<RequestContent, errors::ConnectorError> { | ||||||
|         let connector_router_data = |         let refund_amount = connector_utils::convert_amount( | ||||||
|             {{project-name | downcase}}::{{project-name | downcase | pascal_case}}RouterData::try_from(( |             self.amount_converter, | ||||||
|                 &self.get_currency_unit(), |             req.request.minor_refund_amount, | ||||||
|             req.request.currency, |             req.request.currency, | ||||||
|                 req.request.refund_amount, |         )?; | ||||||
|  |  | ||||||
|  |         let connector_router_data = | ||||||
|  |             {{project-name | downcase}}::{{project-name | downcase | pascal_case}}RouterData::from(( | ||||||
|  |                 refund_amount, | ||||||
|                 req, |                 req, | ||||||
|             ))?; |             )); | ||||||
|         let connector_req = {{project-name | downcase}}::{{project-name | downcase | pascal_case}}RefundRequest::try_from(&connector_router_data)?; |         let connector_req = {{project-name | downcase}}::{{project-name | downcase | pascal_case}}RefundRequest::try_from(&connector_router_data)?; | ||||||
|         Ok(RequestContent::Json(Box::new(connector_req))) |         Ok(RequestContent::Json(Box::new(connector_req))) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,6 +1,5 @@ | |||||||
| use masking::Secret; | use masking::Secret; | ||||||
| use router::{ | use router::{ | ||||||
|     core::utils as core_utils, |  | ||||||
|     types::{self, api, storage::enums, |     types::{self, api, storage::enums, | ||||||
| }}; | }}; | ||||||
|  |  | ||||||
| @ -11,10 +10,10 @@ use test_utils::connector_auth; | |||||||
| struct {{project-name | downcase | pascal_case}}Test; | struct {{project-name | downcase | pascal_case}}Test; | ||||||
| impl ConnectorActions for {{project-name | downcase | pascal_case}}Test {} | impl ConnectorActions for {{project-name | downcase | pascal_case}}Test {} | ||||||
| impl utils::Connector for {{project-name | downcase | pascal_case}}Test { | impl utils::Connector for {{project-name | downcase | pascal_case}}Test { | ||||||
|     fn get_data(&self) -> types::api::ConnectorData { |     fn get_data(&self) -> api::ConnectorData { | ||||||
|         use router::connector::{{project-name | downcase | pascal_case}}; |         use router::connector::{{project-name | downcase | pascal_case}}; | ||||||
|         types::api::ConnectorData { |         api::ConnectorData { | ||||||
|             connector: Box::new(&{{project-name | downcase | pascal_case}}), |             connector: Box::new({{project-name | downcase | pascal_case}}::new()), | ||||||
|             connector_name: types::Connector::{{project-name | downcase | pascal_case}}, |             connector_name: types::Connector::{{project-name | downcase | pascal_case}}, | ||||||
|             get_token: types::api::GetToken::Connector, |             get_token: types::api::GetToken::Connector, | ||||||
|             merchant_connector_id: None, |             merchant_connector_id: None, | ||||||
| @ -94,7 +93,7 @@ async fn should_sync_authorized_payment() { | |||||||
|         .psync_retry_till_status_matches( |         .psync_retry_till_status_matches( | ||||||
|             enums::AttemptStatus::Authorized, |             enums::AttemptStatus::Authorized, | ||||||
|             Some(types::PaymentsSyncData { |             Some(types::PaymentsSyncData { | ||||||
|                 connector_transaction_id: router::types::ResponseId::ConnectorTransactionId( |                 connector_transaction_id: types::ResponseId::ConnectorTransactionId( | ||||||
|                     txn_id.unwrap(), |                     txn_id.unwrap(), | ||||||
|                 ), |                 ), | ||||||
|                 ..Default::default() |                 ..Default::default() | ||||||
| @ -198,7 +197,7 @@ async fn should_sync_auto_captured_payment() { | |||||||
|         .psync_retry_till_status_matches( |         .psync_retry_till_status_matches( | ||||||
|             enums::AttemptStatus::Charged, |             enums::AttemptStatus::Charged, | ||||||
|             Some(types::PaymentsSyncData { |             Some(types::PaymentsSyncData { | ||||||
|                 connector_transaction_id: router::types::ResponseId::ConnectorTransactionId( |                 connector_transaction_id: types::ResponseId::ConnectorTransactionId( | ||||||
|                     txn_id.unwrap(), |                     txn_id.unwrap(), | ||||||
|                 ), |                 ), | ||||||
|                 capture_method: Some(enums::CaptureMethod::Automatic), |                 capture_method: Some(enums::CaptureMethod::Automatic), | ||||||
| @ -310,7 +309,7 @@ async fn should_fail_payment_for_invalid_exp_month() { | |||||||
|     let response = CONNECTOR |     let response = CONNECTOR | ||||||
|         .make_payment( |         .make_payment( | ||||||
|             Some(types::PaymentsAuthorizeData { |             Some(types::PaymentsAuthorizeData { | ||||||
|                 payment_method_data: types::api::PaymentMethodData::Card(api::Card { |                 payment_method_data: api::PaymentMethodData::Card(api::Card { | ||||||
|                     card_exp_month: Secret::new("20".to_string()), |                     card_exp_month: Secret::new("20".to_string()), | ||||||
|                     ..utils::CCardType::default().0 |                     ..utils::CCardType::default().0 | ||||||
|                 }), |                 }), | ||||||
| @ -332,7 +331,7 @@ async fn should_fail_payment_for_incorrect_expiry_year() { | |||||||
|     let response = CONNECTOR |     let response = CONNECTOR | ||||||
|         .make_payment( |         .make_payment( | ||||||
|             Some(types::PaymentsAuthorizeData { |             Some(types::PaymentsAuthorizeData { | ||||||
|                 payment_method_data: types::api::PaymentMethodData::Card(api::Card { |                 payment_method_data: api::PaymentMethodData::Card(api::Card { | ||||||
|                     card_exp_year: Secret::new("2000".to_string()), |                     card_exp_year: Secret::new("2000".to_string()), | ||||||
|                     ..utils::CCardType::default().0 |                     ..utils::CCardType::default().0 | ||||||
|                 }), |                 }), | ||||||
|  | |||||||
| @ -1,42 +1,38 @@ | |||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use masking::Secret; | use masking::Secret; | ||||||
|  | use common_utils::types::{StringMinorUnit}; | ||||||
| use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self, domain, api, storage::enums}}; | use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self, domain, api, storage::enums}}; | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields | //TODO: Fill the struct with respective fields | ||||||
| pub struct {{project-name | downcase | pascal_case}}RouterData<T> { | pub struct {{project-name | downcase | pascal_case}}RouterData<T> { | ||||||
|     pub amount: MinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc. |     pub amount: StringMinorUnit, // The type of amount that a connector accepts, for example, String, i64, f64, etc. | ||||||
|     pub router_data: T, |     pub router_data: T, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<T> | impl<T> | ||||||
|     TryFrom<( |     From<( | ||||||
|         &types::api::CurrencyUnit, |         StringMinorUnit, | ||||||
|         types::storage::enums::Currency, |  | ||||||
|         i64, |  | ||||||
|         T, |         T, | ||||||
|     )> for {{project-name | downcase | pascal_case}}RouterData<T> |     )> for {{project-name | downcase | pascal_case}}RouterData<T> | ||||||
| { | { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     fn from( | ||||||
|     fn try_from( |         (amount, item): ( | ||||||
|         (_currency_unit, _currency, amount, item): ( |             StringMinorUnit, | ||||||
|             &types::api::CurrencyUnit, |  | ||||||
|             types::storage::enums::Currency, |  | ||||||
|             i64, |  | ||||||
|             T, |             T, | ||||||
|         ), |         ), | ||||||
|     ) -> Result<Self, Self::Error> { |     ) -> Self { | ||||||
|          //Todo :  use utils to convert the amount to the type of amount that a connector accepts |          //Todo :  use utils to convert the amount to the type of amount that a connector accepts | ||||||
|         Ok(Self { |         Self { | ||||||
|             amount, |             amount, | ||||||
|             router_data: item, |             router_data: item, | ||||||
|         }) |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields | //TODO: Fill the struct with respective fields | ||||||
| #[derive(Default, Debug, Serialize, Eq, PartialEq)] | #[derive(Default, Debug, Serialize, PartialEq)] | ||||||
| pub struct {{project-name | downcase | pascal_case}}PaymentsRequest { | pub struct {{project-name | downcase | pascal_case}}PaymentsRequest { | ||||||
|     amount: i64, |     amount: StringMinorUnit, | ||||||
|     card: {{project-name | downcase | pascal_case}}Card |     card: {{project-name | downcase | pascal_case}}Card | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -62,7 +58,7 @@ impl TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::Paymen | |||||||
|                     complete: item.router_data.request.is_auto_capture()?, |                     complete: item.router_data.request.is_auto_capture()?, | ||||||
|                 }; |                 }; | ||||||
|                 Ok(Self { |                 Ok(Self { | ||||||
|                     amount: item.amount.to_owned(), |                     amount: item.amount.clone(), | ||||||
|                     card, |                     card, | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
| @ -141,7 +137,7 @@ impl<F,T> TryFrom<types::ResponseRouterData<F, {{project-name | downcase | pasca | |||||||
| // Type definition for RefundRequest | // Type definition for RefundRequest | ||||||
| #[derive(Default, Debug, Serialize)] | #[derive(Default, Debug, Serialize)] | ||||||
| pub struct {{project-name | downcase | pascal_case}}RefundRequest { | pub struct {{project-name | downcase | pascal_case}}RefundRequest { | ||||||
|     pub amount: MinorUnit |     pub amount: StringMinorUnit | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<F> TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::RefundsRouterData<F>>> for {{project-name | downcase | pascal_case}}RefundRequest { | impl<F> TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::RefundsRouterData<F>>> for {{project-name | downcase | pascal_case}}RefundRequest { | ||||||
|  | |||||||
| @ -199,6 +199,7 @@ impl Connector { | |||||||
|             | Self::DummyConnector6 |             | Self::DummyConnector6 | ||||||
|             | Self::DummyConnector7 => false, |             | Self::DummyConnector7 => false, | ||||||
|             Self::Aci |             Self::Aci | ||||||
|  |             // Add Separate authentication support for connectors | ||||||
|             | Self::Adyen |             | Self::Adyen | ||||||
|             | Self::Adyenplatform |             | Self::Adyenplatform | ||||||
|             | Self::Airwallex |             | Self::Airwallex | ||||||
|  | |||||||
| @ -1,9 +1,12 @@ | |||||||
| pub mod transformers; | pub mod transformers; | ||||||
|  |  | ||||||
| use std::fmt::Debug; |  | ||||||
|  |  | ||||||
| use base64::Engine; | use base64::Engine; | ||||||
| use common_utils::{crypto, ext_traits::ByteSliceExt, request::RequestContent}; | use common_utils::{ | ||||||
|  |     crypto, | ||||||
|  |     ext_traits::ByteSliceExt, | ||||||
|  |     request::RequestContent, | ||||||
|  |     types::{AmountConvertor, FloatMajorUnit, FloatMajorUnitForConnector}, | ||||||
|  | }; | ||||||
| use error_stack::ResultExt; | use error_stack::ResultExt; | ||||||
| use masking::PeekInterface; | use masking::PeekInterface; | ||||||
| use transformers as iatapay; | use transformers as iatapay; | ||||||
| @ -29,8 +32,18 @@ use crate::{ | |||||||
|     utils::BytesExt, |     utils::BytesExt, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #[derive(Debug, Clone)] | #[derive(Clone)] | ||||||
| pub struct Iatapay; | pub struct Iatapay { | ||||||
|  |     amount_converter: &'static (dyn AmountConvertor<Output = FloatMajorUnit> + Sync), | ||||||
|  | } | ||||||
|  |  | ||||||
|  | impl Iatapay { | ||||||
|  |     pub fn new() -> &'static Self { | ||||||
|  |         &Self { | ||||||
|  |             amount_converter: &FloatMajorUnitForConnector, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| impl api::Payment for Iatapay {} | impl api::Payment for Iatapay {} | ||||||
| impl api::PaymentSession for Iatapay {} | impl api::PaymentSession for Iatapay {} | ||||||
| @ -316,12 +329,13 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P | |||||||
|         req: &types::PaymentsAuthorizeRouterData, |         req: &types::PaymentsAuthorizeRouterData, | ||||||
|         _connectors: &settings::Connectors, |         _connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<RequestContent, errors::ConnectorError> { |     ) -> CustomResult<RequestContent, errors::ConnectorError> { | ||||||
|         let connector_router_data = iatapay::IatapayRouterData::try_from(( |         let amount = connector_utils::convert_amount( | ||||||
|             &self.get_currency_unit(), |             self.amount_converter, | ||||||
|  |             req.request.minor_amount, | ||||||
|             req.request.currency, |             req.request.currency, | ||||||
|             req.request.amount, |         )?; | ||||||
|             req, |  | ||||||
|         ))?; |         let connector_router_data = iatapay::IatapayRouterData::try_from((amount, req))?; | ||||||
|         let connector_req = iatapay::IatapayPaymentsRequest::try_from(&connector_router_data)?; |         let connector_req = iatapay::IatapayPaymentsRequest::try_from(&connector_router_data)?; | ||||||
|         Ok(RequestContent::Json(Box::new(connector_req))) |         Ok(RequestContent::Json(Box::new(connector_req))) | ||||||
|     } |     } | ||||||
| @ -506,12 +520,13 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon | |||||||
|         req: &types::RefundsRouterData<api::Execute>, |         req: &types::RefundsRouterData<api::Execute>, | ||||||
|         _connectors: &settings::Connectors, |         _connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<RequestContent, errors::ConnectorError> { |     ) -> CustomResult<RequestContent, errors::ConnectorError> { | ||||||
|         let connector_router_data = iatapay::IatapayRouterData::try_from(( |         let refund_amount = connector_utils::convert_amount( | ||||||
|             &self.get_currency_unit(), |             self.amount_converter, | ||||||
|  |             req.request.minor_refund_amount, | ||||||
|             req.request.currency, |             req.request.currency, | ||||||
|             req.request.refund_amount, |         )?; | ||||||
|             req, |  | ||||||
|         ))?; |         let connector_router_data = iatapay::IatapayRouterData::try_from((refund_amount, req))?; | ||||||
|         let connector_req = iatapay::IatapayRefundRequest::try_from(&connector_router_data)?; |         let connector_req = iatapay::IatapayRefundRequest::try_from(&connector_router_data)?; | ||||||
|         Ok(RequestContent::Json(Box::new(connector_req))) |         Ok(RequestContent::Json(Box::new(connector_req))) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
|  |  | ||||||
| use common_utils::{errors::CustomResult, ext_traits::Encode}; | use common_utils::{errors::CustomResult, ext_traits::Encode, types::FloatMajorUnit}; | ||||||
| use error_stack::ResultExt; | use error_stack::ResultExt; | ||||||
| use masking::{Secret, SwitchStrategy}; | use masking::{Secret, SwitchStrategy}; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| @ -34,16 +34,14 @@ impl TryFrom<&types::RefreshTokenRouterData> for IatapayAuthUpdateRequest { | |||||||
| } | } | ||||||
| #[derive(Debug, Serialize)] | #[derive(Debug, Serialize)] | ||||||
| pub struct IatapayRouterData<T> { | pub struct IatapayRouterData<T> { | ||||||
|     amount: f64, |     amount: FloatMajorUnit, | ||||||
|     router_data: T, |     router_data: T, | ||||||
| } | } | ||||||
| impl<T> TryFrom<(&api::CurrencyUnit, enums::Currency, i64, T)> for IatapayRouterData<T> { | impl<T> TryFrom<(FloatMajorUnit, T)> for IatapayRouterData<T> { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from( |     fn try_from((amount, item): (FloatMajorUnit, T)) -> Result<Self, Self::Error> { | ||||||
|         (currency_unit, currency, amount, item): (&api::CurrencyUnit, enums::Currency, i64, T), |  | ||||||
|     ) -> Result<Self, Self::Error> { |  | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             amount: connector_util::get_amount_as_f64(currency_unit, amount, currency)?, |             amount, | ||||||
|             router_data: item, |             router_data: item, | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| @ -96,7 +94,7 @@ pub enum PreferredCheckoutMethod { | |||||||
| pub struct IatapayPaymentsRequest { | pub struct IatapayPaymentsRequest { | ||||||
|     merchant_id: Secret<String>, |     merchant_id: Secret<String>, | ||||||
|     merchant_payment_id: Option<String>, |     merchant_payment_id: Option<String>, | ||||||
|     amount: f64, |     amount: FloatMajorUnit, | ||||||
|     currency: common_enums::Currency, |     currency: common_enums::Currency, | ||||||
|     country: common_enums::CountryAlpha2, |     country: common_enums::CountryAlpha2, | ||||||
|     locale: String, |     locale: String, | ||||||
| @ -307,7 +305,7 @@ pub struct IatapayPaymentsResponse { | |||||||
|     pub iata_refund_id: Option<String>, |     pub iata_refund_id: Option<String>, | ||||||
|     pub merchant_id: Option<Secret<String>>, |     pub merchant_id: Option<Secret<String>>, | ||||||
|     pub merchant_payment_id: Option<String>, |     pub merchant_payment_id: Option<String>, | ||||||
|     pub amount: f64, |     pub amount: FloatMajorUnit, | ||||||
|     pub currency: String, |     pub currency: String, | ||||||
|     pub checkout_methods: Option<CheckoutMethod>, |     pub checkout_methods: Option<CheckoutMethod>, | ||||||
|     pub failure_code: Option<String>, |     pub failure_code: Option<String>, | ||||||
| @ -429,7 +427,7 @@ impl<F, T> | |||||||
| pub struct IatapayRefundRequest { | pub struct IatapayRefundRequest { | ||||||
|     pub merchant_id: Secret<String>, |     pub merchant_id: Secret<String>, | ||||||
|     pub merchant_refund_id: Option<String>, |     pub merchant_refund_id: Option<String>, | ||||||
|     pub amount: f64, |     pub amount: FloatMajorUnit, | ||||||
|     pub currency: String, |     pub currency: String, | ||||||
|     pub bank_transfer_description: Option<String>, |     pub bank_transfer_description: Option<String>, | ||||||
|     pub notification_url: String, |     pub notification_url: String, | ||||||
| @ -486,7 +484,7 @@ pub struct RefundResponse { | |||||||
|     iata_refund_id: String, |     iata_refund_id: String, | ||||||
|     status: RefundStatus, |     status: RefundStatus, | ||||||
|     merchant_refund_id: String, |     merchant_refund_id: String, | ||||||
|     amount: f64, |     amount: FloatMajorUnit, | ||||||
|     currency: String, |     currency: String, | ||||||
|     bank_transfer_description: Option<String>, |     bank_transfer_description: Option<String>, | ||||||
|     failure_code: Option<String>, |     failure_code: Option<String>, | ||||||
| @ -498,7 +496,7 @@ pub struct RefundResponse { | |||||||
|     clearance_date_time: Option<String>, |     clearance_date_time: Option<String>, | ||||||
|     iata_payment_id: Option<String>, |     iata_payment_id: Option<String>, | ||||||
|     merchant_payment_id: Option<String>, |     merchant_payment_id: Option<String>, | ||||||
|     payment_amount: Option<f64>, |     payment_amount: Option<FloatMajorUnit>, | ||||||
|     merchant_id: Option<Secret<String>>, |     merchant_id: Option<Secret<String>>, | ||||||
|     account_country: Option<String>, |     account_country: Option<String>, | ||||||
| } | } | ||||||
| @ -600,7 +598,7 @@ pub struct IatapayPaymentWebhookBody { | |||||||
|     pub merchant_payment_id: Option<String>, |     pub merchant_payment_id: Option<String>, | ||||||
|     pub failure_code: Option<String>, |     pub failure_code: Option<String>, | ||||||
|     pub failure_details: Option<String>, |     pub failure_details: Option<String>, | ||||||
|     pub amount: f64, |     pub amount: FloatMajorUnit, | ||||||
|     pub currency: String, |     pub currency: String, | ||||||
|     pub checkout_methods: Option<CheckoutMethod>, |     pub checkout_methods: Option<CheckoutMethod>, | ||||||
| } | } | ||||||
| @ -613,7 +611,7 @@ pub struct IatapayRefundWebhookBody { | |||||||
|     pub merchant_refund_id: Option<String>, |     pub merchant_refund_id: Option<String>, | ||||||
|     pub failure_code: Option<String>, |     pub failure_code: Option<String>, | ||||||
|     pub failure_details: Option<String>, |     pub failure_details: Option<String>, | ||||||
|     pub amount: f64, |     pub amount: FloatMajorUnit, | ||||||
|     pub currency: String, |     pub currency: String, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -31,6 +31,7 @@ use crate::{ | |||||||
|         transformers::ForeignTryFrom, |         transformers::ForeignTryFrom, | ||||||
|         ErrorResponse, Response, |         ErrorResponse, Response, | ||||||
|     }, |     }, | ||||||
|  |     // transformers::{ForeignFrom, ForeignTryFrom}, | ||||||
|     utils::{handle_json_response_deserialization_failure, BytesExt}, |     utils::{handle_json_response_deserialization_failure, BytesExt}, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @ -864,7 +865,7 @@ impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsR | |||||||
|             req.request |             req.request | ||||||
|                 .currency |                 .currency | ||||||
|                 .ok_or(errors::ConnectorError::MissingRequiredField { |                 .ok_or(errors::ConnectorError::MissingRequiredField { | ||||||
|                     field_name: "currency", |                     field_name: "amount", | ||||||
|                 })?; |                 })?; | ||||||
|         let amount = |         let amount = | ||||||
|             connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?; |             connector_utils::convert_amount(self.amount_converter, req_amount, req_currency)?; | ||||||
|  | |||||||
| @ -427,7 +427,9 @@ impl ConnectorData { | |||||||
|                     Ok(ConnectorEnum::Old(Box::new(&connector::Gocardless))) |                     Ok(ConnectorEnum::Old(Box::new(&connector::Gocardless))) | ||||||
|                 } |                 } | ||||||
|                 enums::Connector::Helcim => Ok(ConnectorEnum::Old(Box::new(&connector::Helcim))), |                 enums::Connector::Helcim => Ok(ConnectorEnum::Old(Box::new(&connector::Helcim))), | ||||||
|                 enums::Connector::Iatapay => Ok(ConnectorEnum::Old(Box::new(&connector::Iatapay))), |                 enums::Connector::Iatapay => { | ||||||
|  |                     Ok(ConnectorEnum::Old(Box::new(connector::Iatapay::new()))) | ||||||
|  |                 } | ||||||
|                 enums::Connector::Klarna => Ok(ConnectorEnum::Old(Box::new(&connector::Klarna))), |                 enums::Connector::Klarna => Ok(ConnectorEnum::Old(Box::new(&connector::Klarna))), | ||||||
|                 enums::Connector::Mollie => Ok(ConnectorEnum::Old(Box::new(&connector::Mollie))), |                 enums::Connector::Mollie => Ok(ConnectorEnum::Old(Box::new(&connector::Mollie))), | ||||||
|                 enums::Connector::Nmi => Ok(ConnectorEnum::Old(Box::new(connector::Nmi::new()))), |                 enums::Connector::Nmi => Ok(ConnectorEnum::Old(Box::new(connector::Nmi::new()))), | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ impl Connector for IatapayTest { | |||||||
|     fn get_data(&self) -> api::ConnectorData { |     fn get_data(&self) -> api::ConnectorData { | ||||||
|         use router::connector::Iatapay; |         use router::connector::Iatapay; | ||||||
|         utils::construct_connector_data_old( |         utils::construct_connector_data_old( | ||||||
|             Box::new(&Iatapay), |             Box::new(Iatapay::new()), | ||||||
|             types::Connector::Iatapay, |             types::Connector::Iatapay, | ||||||
|             api::GetToken::Connector, |             api::GetToken::Connector, | ||||||
|             None, |             None, | ||||||
|  | |||||||
| @ -53,15 +53,16 @@ find_prev_connector $payment_gateway previous_connector | |||||||
| previous_connector_camelcase="$(tr '[:lower:]' '[:upper:]' <<< ${previous_connector:0:1})${previous_connector:1}" | previous_connector_camelcase="$(tr '[:lower:]' '[:upper:]' <<< ${previous_connector:0:1})${previous_connector:1}" | ||||||
| sed -i'' -e "s|pub mod $previous_connector;|pub mod $previous_connector;\npub mod ${payment_gateway};|" $conn.rs | sed -i'' -e "s|pub mod $previous_connector;|pub mod $previous_connector;\npub mod ${payment_gateway};|" $conn.rs | ||||||
| sed -i'' -e "s/};/${payment_gateway}::${payment_gateway_camelcase},\n};/" $conn.rs | sed -i'' -e "s/};/${payment_gateway}::${payment_gateway_camelcase},\n};/" $conn.rs | ||||||
| sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tenums::Connector::${payment_gateway_camelcase} => Ok(Box::new(\&connector::${payment_gateway_camelcase})),|" $src/types/api.rs | sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tenums::Connector::${payment_gateway_camelcase} => Ok(Box::new(\connector::${payment_gateway_camelcase}::new())),|" $src/types/api.rs | ||||||
| sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tRoutableConnectors::${payment_gateway_camelcase} => euclid_enums::Connector::${payment_gateway_camelcase},|" crates/api_models/src/routing.rs | sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tRoutableConnectors::${payment_gateway_camelcase} => euclid_enums::Connector::${payment_gateway_camelcase},|" crates/api_models/src/routing.rs | ||||||
| sed -i'' -e "s/pub $previous_connector: \(.*\)/pub $previous_connector: \1\n\tpub ${payment_gateway}: ConnectorParams,/" $src/configs/settings.rs | sed -i'' -e "s/pub $previous_connector: \(.*\)/pub $previous_connector: \1\n\tpub ${payment_gateway}: ConnectorParams,/" $src/configs/settings.rs | ||||||
| sed -i'' -e "s|$previous_connector.base_url \(.*\)|$previous_connector.base_url \1\n${payment_gateway}.base_url = \"$base_url\"|" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml | sed -i'' -e "s|$previous_connector.base_url \(.*\)|$previous_connector.base_url \1\n${payment_gateway}.base_url = \"$base_url\"|" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml | ||||||
| sed  -r -i'' -e "s/\"$previous_connector\",/\"$previous_connector\",\n    \"${payment_gateway}\",/" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml | sed  -r -i'' -e "s/\"$previous_connector\",/\"$previous_connector\",\n    \"${payment_gateway}\",/" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml | ||||||
| sed -i '' -e "s/\(pub enum Connector {\)/\1\n\t${payment_gateway_camelcase},/" crates/api_models/src/enums.rs | sed -i '' -e "s/\(pub enum Connector {\)/\1\n\t${payment_gateway_camelcase},/" crates/api_models/src/enums.rs | ||||||
| sed -i '' -e "s/\(pub enum Connector {\)/\1\n\t${payment_gateway_camelcase},/" crates/euclid/src/enums.rs | sed -i '' -e "/\/\/ Add Separate authentication support for connectors/{N;s/\(.*\)\n/\1\n\t\t\t| Self::${payment_gateway_camelcase}\n/;}" crates/api_models/src/enums.rs | ||||||
| sed -i '' -e "s/\(match connector_name {\)/\1\n\t\tapi_enums::Connector::${payment_gateway_camelcase} => {${payment_gateway}::transformers::${payment_gateway_camelcase}AuthType::try_from(val)?;Ok(())}/" $src/core/admin.rs | sed -i '' -e "s/\(match connector_name {\)/\1\n\t\tapi_enums::Connector::${payment_gateway_camelcase} => {${payment_gateway}::transformers::${payment_gateway_camelcase}AuthType::try_from(val)?;Ok(())}/" $src/core/admin.rs | ||||||
| sed -i'' -e "s/\(pub enum RoutableConnectors {\)/\1\n\t${payment_gateway_camelcase},/" crates/common_enums/src/enums.rs | sed -i'' -e "s/\(pub enum RoutableConnectors {\)/\1\n\t${payment_gateway_camelcase},/" crates/common_enums/src/enums.rs | ||||||
|  | sed -i '' -e "s/\(pub enum Connector {\)/\1\n\t${payment_gateway_camelcase},/" crates/euclid/src/enums.rs | ||||||
| sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tapi_enums::Connector::${payment_gateway_camelcase} => Self::${payment_gateway_camelcase},|" $src/types/transformers.rs | sed -i'' -e "s|$previous_connector_camelcase \(.*\)|$previous_connector_camelcase \1\n\t\t\tapi_enums::Connector::${payment_gateway_camelcase} => Self::${payment_gateway_camelcase},|" $src/types/transformers.rs | ||||||
| sed -i'' -e "s/^default_imp_for_\(.*\)/default_imp_for_\1\n\tconnector::${payment_gateway_camelcase},/" $src/core/payments/flows.rs | sed -i'' -e "s/^default_imp_for_\(.*\)/default_imp_for_\1\n\tconnector::${payment_gateway_camelcase},/" $src/core/payments/flows.rs | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Sahkal Poddar
					Sahkal Poddar