Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(connector): [Cryptopay]Enhance currency Mapping with ConnectorCurrencyCommon Trait (#2195)
chikke srujand8c384573e1f
diff --git a/crates/router/src/connector/cryptopay.rs b/crates/router/src/connector/cryptopay.rsindex 2ee645a277..fd324fcc68 100644--- a/crates/router/src/connector/cryptopay.rs+++ b/crates/router/src/connector/cryptopay.rs@@ -129,6 +129,10 @@ impl ConnectorCommon for Cryptopay {"cryptopay"}+ fn get_currency_unit(&self) -> api::CurrencyUnit {+ api::CurrencyUnit::Base+ }+fn common_get_content_type(&self) -> &'static str {"application/json"}@@ -211,7 +215,14 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P&self,req: &types::PaymentsAuthorizeRouterData,) -> CustomResult<Option<types::RequestBody>, errors::ConnectorError> {- let connector_request = cryptopay::CryptopayPaymentsRequest::try_from(req)?;+ let connector_router_data = cryptopay::CryptopayRouterData::try_from((+ &self.get_currency_unit(),+ req.request.currency,+ req.request.amount,+ req,+ ))?;+ let connector_request =+ cryptopay::CryptopayPaymentsRequest::try_from(&connector_router_data)?;let cryptopay_req = types::RequestBody::log_and_get_request_body(&connector_request,Encode::<cryptopay::CryptopayPaymentsRequest>::encode_to_string_of_json,diff --git a/crates/router/src/connector/cryptopay/transformers.rs b/crates/router/src/connector/cryptopay/transformers.rsindex d360fbcca3..a49380cb36 100644--- a/crates/router/src/connector/cryptopay/transformers.rs+++ b/crates/router/src/connector/cryptopay/transformers.rs@@ -9,6 +9,37 @@ use crate::{types::{self, api, storage::enums},};+#[derive(Debug, Serialize)]+pub struct CryptopayRouterData<T> {+ pub amount: String,+ pub router_data: T,+}++impl<T>+ TryFrom<(+ &types::api::CurrencyUnit,+ types::storage::enums::Currency,+ i64,+ T,+ )> for CryptopayRouterData<T>+{+ type Error = error_stack::Report<errors::ConnectorError>;+ fn try_from(+ (currency_unit, currency, amount, item): (+ &types::api::CurrencyUnit,+ types::storage::enums::Currency,+ i64,+ T,+ ),+ ) -> Result<Self, Self::Error> {+ let amount = utils::get_amount_as_string(currency_unit, amount, currency)?;+ Ok(Self {+ amount,+ router_data: item,+ })+ }+}+#[derive(Default, Debug, Serialize)]pub struct CryptopayPaymentsRequest {price_amount: String,@@ -19,22 +50,23 @@ pub struct CryptopayPaymentsRequest {custom_id: String,}-impl TryFrom<&types::PaymentsAuthorizeRouterData> for CryptopayPaymentsRequest {+impl TryFrom<&CryptopayRouterData<&types::PaymentsAuthorizeRouterData>>+ for CryptopayPaymentsRequest+{type Error = error_stack::Report<errors::ConnectorError>;- fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {- let cryptopay_request = match item.request.payment_method_data {+ fn try_from(+ item: &CryptopayRouterData<&types::PaymentsAuthorizeRouterData>,+ ) -> Result<Self, Self::Error> {+ let cryptopay_request = match item.router_data.request.payment_method_data {api::PaymentMethodData::Crypto(ref cryptodata) => {let pay_currency = cryptodata.get_pay_currency()?;Ok(Self {- price_amount: utils::to_currency_base_unit(- item.request.amount,- item.request.currency,- )?,- price_currency: item.request.currency,+ price_amount: item.amount.to_owned(),+ price_currency: item.router_data.request.currency,pay_currency,- success_redirect_url: item.clone().request.router_return_url,- unsuccess_redirect_url: item.clone().request.router_return_url,- custom_id: item.connector_request_reference_id.clone(),+ success_redirect_url: item.router_data.request.router_return_url.clone(),+ unsuccess_redirect_url: item.router_data.request.router_return_url.clone(),+ custom_id: item.router_data.connector_request_reference_id.clone(),})}_ => Err(errors::ConnectorError::NotImplemented(