Skip to content

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

feat(core): Move RouterData to crate hyperswitch_domain_models (#4524)

DEEPANSHU BANSALff1c2ddf8b9d
diff --git a/Cargo.lock b/Cargo.lock
index b823f9e5c9..5ba2d0dae6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3647,6 +3647,7 @@ dependencies = [
"common_utils",
"diesel_models",
"error-stack",
+ "http 0.2.12",
"masking",
"serde",
"serde_json",
diff --git a/connector-template/mod.rs b/connector-template/mod.rs
index 760e1528cf..cecf5ef1c6 100644
--- a/connector-template/mod.rs
+++ b/connector-template/mod.rs
@@ -7,7 +7,7 @@ use masking::ExposeInterface;
use crate::{
events::connector_api_logs::ConnectorEvent,
configs::settings,
- utils::{self, BytesExt},
+ utils::BytesExt,
core::{
errors::{self, CustomResult},
},
diff --git a/connector-template/transformers.rs b/connector-template/transformers.rs
index 60b1369305..0d9e99c86a 100644
--- a/connector-template/transformers.rs
+++ b/connector-template/transformers.rs
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use masking::Secret;
-use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self,api, storage::enums}};
+use crate::{connector::utils::{PaymentsAuthorizeRequestData},core::errors,types::{self, domain, api, storage::enums}};
//TODO: Fill the struct with respective fields
pub struct {{project-name | downcase | pascal_case}}RouterData<T> {
@@ -53,7 +53,7 @@ impl TryFrom<&{{project-name | downcase | pascal_case}}RouterData<&types::Paymen
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &{{project-name | downcase | pascal_case}}RouterData<&types::PaymentsAuthorizeRouterData>) -> Result<Self,Self::Error> {
match item.router_data.request.payment_method_data.clone() {
- api::PaymentMethodData::Card(req_card) => {
+ domain::PaymentMethodData::Card(req_card) => {
let card = {{project-name | downcase | pascal_case}}Card {
number: req_card.card_number,
expiry_month: req_card.card_exp_month,
diff --git a/crates/hyperswitch_domain_models/Cargo.toml b/crates/hyperswitch_domain_models/Cargo.toml
index 58eff10a36..dd3335cb2c 100644
--- a/crates/hyperswitch_domain_models/Cargo.toml
+++ b/crates/hyperswitch_domain_models/Cargo.toml
@@ -23,6 +23,7 @@ diesel_models = { version = "0.1.0", path = "../diesel_models", features = ["kv_
# Third party deps
async-trait = "0.1.79"
error-stack = "0.4.1"
+http = "0.2.12"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
thiserror = "1.0.58"
diff --git a/crates/hyperswitch_domain_models/src/lib.rs b/crates/hyperswitch_domain_models/src/lib.rs
index 30279fae54..b470b538d7 100644
--- a/crates/hyperswitch_domain_models/src/lib.rs
+++ b/crates/hyperswitch_domain_models/src/lib.rs
@@ -1,8 +1,10 @@
pub mod errors;
pub mod mandates;
+pub mod payment_address;
pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
+pub mod router_data;
#[cfg(not(feature = "payouts"))]
pub trait PayoutAttemptInterface {}
diff --git a/crates/hyperswitch_domain_models/src/payment_address.rs b/crates/hyperswitch_domain_models/src/payment_address.rs
new file mode 100644
index 0000000000..d4f2cf9f35
--- /dev/null
+++ b/crates/hyperswitch_domain_models/src/payment_address.rs
@@ -0,0 +1,82 @@
+use api_models::payments::Address;
+
+#[derive(Clone, Default, Debug)]
+pub struct PaymentAddress {
+ shipping: Option<Address>,
+ billing: Option<Address>,
+ unified_payment_method_billing: Option<Address>,
+ payment_method_billing: Option<Address>,
+}
+
+impl PaymentAddress {
+ pub fn new(
+ shipping: Option<Address>,
+ billing: Option<Address>,
+ payment_method_billing: Option<Address>,
+ should_unify_address: Option<bool>,
+ ) -> Self {
+ // billing -> .billing, this is the billing details passed in the root of payments request
+ // payment_method_billing -> .payment_method_data.billing
+
+ let unified_payment_method_billing = if should_unify_address.unwrap_or(true) {
+ // Merge the billing details field from both `payment.billing` and `payment.payment_method_data.billing`
+ // The unified payment_method_billing will be used as billing address and passed to the connector module
+ // This unification is required in order to provide backwards compatibility
+ // so that if `payment.billing` is passed it should be sent to the connector module
+ // Unify the billing details with `payment_method_data.billing`
+ payment_method_billing
+ .as_ref()
+ .map(|payment_method_billing| {
+ payment_method_billing
+ .clone()
+ .unify_address(billing.as_ref())
+ })
+ .or(billing.clone())
+ } else {
+ payment_method_billing.clone()
+ };
+
+ Self {
+ shipping,
+ billing,
+ unified_payment_method_billing,
+ payment_method_billing,
+ }
+ }
+
+ pub fn get_shipping(&self) -> Option<&Address> {
+ self.shipping.as_ref()
+ }
+
+ pub fn get_payment_method_billing(&self) -> Option<&Address> {
+ self.unified_payment_method_billing.as_ref()
+ }
+
+ /// Unify the billing details from `payment_method_data.[payment_method_data].billing details`.
+ pub fn unify_with_payment_method_data_billing(
+ self,
+ payment_method_data_billing: Option<Address>,
+ ) -> Self {
+ // Unify the billing details with `payment_method_data.billing_details`
+ let unified_payment_method_billing = payment_method_data_billing
+ .map(|payment_method_data_billing| {
+ payment_method_data_billing.unify_address(self.get_payment_method_billing())
+ })
+ .or(self.get_payment_method_billing().cloned());
+
+ Self {
+ shipping: self.shipping,
+ billing: self.billing,
+ unified_payment_method_billing,
+ payment_method_billing: self.payment_method_billing,
+ }
+ }
+
+ pub fn get_request_payment_method_billing(&self) -> Option<&Address> {
+ self.payment_method_billing.as_ref()
+ }
+
+ pub fn get_payment_billing(&self) -> Option<&Address> {
+ self.billing.as_ref()
+ }
+}
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
new file mode 100644
index 0000000000..cbaaeeda42
--- /dev/null
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -0,0 +1,207 @@
+use std::{collections::HashMap, marker::PhantomData};
+
+use masking::Secret;
+
+use crate::payment_address::PaymentAddress;
+
+#[derive(Debug, Clone)]
+pub struct RouterData<Flow, Request, Response> {
+ pub flow: PhantomData<Flow>,
+ pub merchant_id: String,
+ pub customer_id: Option<String>,
+ pub connector_customer: Option<String>,
+ pub connector: String,
+ pub payment_id: String,
+ pub attempt_id: String,
+ pub status: common_enums::enums::AttemptStatus,
+ pub payment_method: common_enums::enums::PaymentMethod,
+ pub connector_auth_type: ConnectorAuthType,
+ pub description: Option<String>,
+ pub return_url: Option<String>,
+ pub address: PaymentAddress,
+ pub auth_type: common_enums::enums::AuthenticationType,
+ pub connector_meta_data: Option<common_utils::pii::SecretSerdeValue>,
+ pub amount_captured: Option<i64>,
+ pub access_token: Option<AccessToken>,
+ pub session_token: Option<String>,
+ pub reference_id: Option<String>,
+ pub payment_method_token: Option<PaymentMethodToken>,
+ pub recurring_mandate_payment_data: Option<RecurringMandatePaymentData>,
+ pub preprocessing_id: Option<String>,
+ /// This is the balance amount for gift cards or voucher
+ pub payment_method_balance: Option<PaymentMethodBalance>,
+
+ ///for switching between two different versions of the same connector
+ pub connector_api_version: Option<String>,
+
+ /// Contains flow-specific data required to construct a request and send it to the connector.
+ pub request: Request,
+
+ /// Contains flow-specific data that the connector responds with.
+ pub response: Result<Response, ErrorResponse>,
+
+ /// Contains a reference ID that should be sent in the connector request
+ pub connector_request_reference_id: String,
+
+ #[cfg(feature = "payouts")]
+ /// Contains payout method data
+ pub payout_method_data: Option<api_models::payouts::PayoutMethodData>,
+
+ #[cfg(feature = "payouts")]
+ /// Contains payout's quote ID
+ pub quote_id: Option<String>,
+
+ pub test_mode: Option<bool>,
+ pub connector_http_status_code: Option<u16>,
+ pub external_latency: Option<u128>,
+ /// Contains apple pay flow type simplified or manual
+ pub apple_pay_flow: Option<common_enums::enums::ApplePayFlow>,
+
+ pub frm_metadata: Option<serde_json::Value>,
+
+ pub dispute_id: Option<String>,
+ pub refund_id: Option<String>,
+
+ /// This field is used to store various data regarding the response from connector
+ pub connector_response: Option<ConnectorResponseData>,
+ pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
+}
+
+// Different patterns of authentication.
+#[derive(Default, Debug, Clone, serde::Deserialize, serde::Serialize)]
+#[serde(tag = "auth_type")]
+pub enum ConnectorAuthType {
+ TemporaryAuth,
+ HeaderKey {
+ api_key: Secret<String>,
+ },
+ BodyKey {
+ api_key: Secret<String>,
+ key1: Secret<String>,
+ },
+ SignatureKey {
+ api_key: Secret<String>,
+ key1: Secret<String>,
+ api_secret: Secret<String>,
+ },
+ MultiAuthKey {
+ api_key: Secret<String>,
+ key1: Secret<String>,
+ api_secret: Secret<String>,
+ key2: Secret<String>,
+ },
+ CurrencyAuthKey {
+ auth_key_map: HashMap<common_enums::enums::Currency, common_utils::pii::SecretSerdeValue>,
+ },
+ CertificateAuth {
+ certificate: Secret<String>,
+ private_key: Secret<String>,
+ },
+ #[default]
+ NoKey,
+}
+
+#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
+pub struct AccessToken {
+ pub token: Secret<String>,
+ pub expires: i64,
+}
+
+#[derive(Debug, Clone, serde::Deserialize)]
+pub enum PaymentMethodToken {
+ Token(Secret<String>),
+ ApplePayDecrypt(Box<ApplePayPredecryptData>),
+}
+
+#[derive(Debug, Clone, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ApplePayPredecryptData {
+ pub application_primary_account_number: Secret<String>,
+ pub application_expiration_date: String,
+ pub currency_code: String,
+ pub transaction_amount: i64,
+ pub device_manufacturer_identifier: Secret<String>,
+ pub payment_data_type: Secret<String>,
+ pub payment_data: ApplePayCryptogramData,
+}
+
+#[derive(Debug, Clone, serde::Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ApplePayCryptogramData {
+ pub online_payment_cryptogram: Secret<String>,
+ pub eci_indicator: Option<String>,
+}
+
+#[derive(Debug, Default, Clone)]
+pub struct RecurringMandatePaymentData {
+ pub payment_method_type: Option<common_enums::enums::PaymentMethodType>, //required for making recurring payment using saved payment method through stripe
+ pub original_payment_authorized_amount: Option<i64>,
+ pub original_payment_authorized_currency: Option<common_enums::enums::Currency>,
+}
+
+#[derive(Debug, Clone)]
+pub struct PaymentMethodBalance {
+ pub amount: i64,
+ pub currency: common_enums::enums::Currency,
+}
+
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
+pub struct ConnectorResponseData {
+ pub additional_payment_method_data: Option<AdditionalPaymentMethodConnectorResponse>,
+}
+
+impl ConnectorResponseData {
+ pub fn with_additional_payment_method_data(
+ additional_payment_method_data: AdditionalPaymentMethodConnectorResponse,
+ ) -> Self {
+ Self {
+ additional_payment_method_data: Some(additional_payment_method_data),
+ }
+ }
+}
+
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
+pub enum AdditionalPaymentMethodConnectorResponse {
+ Card {
+ /// Details regarding the authentication details of the connector, if this is a 3ds payment.
+ authentication_data: Option<serde_json::Value>,
+ /// Various payment checks that are done for a payment
+ payment_checks: Option<serde_json::Value>,
+ },
+}
+
+#[derive(Clone, Debug, serde::Serialize)]
+pub struct ErrorResponse {
+ pub code: String,
+ pub message: String,
+ pub reason: Option<String>,
+ pub status_code: u16,
+ pub attempt_status: Option<common_enums::enums::AttemptStatus>,
+ pub connector_transaction_id: Option<String>,
+}
+
+impl Default for ErrorResponse {
+ fn default() -> Self {
+ Self {
+ code: "HE_00".to_string(),
+ message: "Something went wrong".to_string(),
+ reason: None,
+ status_code: http::StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
+ attempt_status: None,
+ connector_transaction_id: None,
+ }
+ }
+}
+
+impl ErrorResponse {
+ pub fn get_not_implemented() -> Self {
+ Self {
+ code: "IR_00".to_string(),
+ message: "This API is under development and will be made available soon.".to_string(),
+ reason: None,
+ status_code: http::StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
+ attempt_status: None,
+ connector_transaction_id: None,
+ }
+ }
+}
diff --git a/crates/router/src/connector/adyen.rs b/crates/router/src/connector/adyen.rs
index 943eedf87d..f80b8725f2 100644
--- a/crates/router/src/connector/adyen.rs
+++ b/crates/router/src/connector/adyen.rs
@@ -30,7 +30,7 @@ use crate::{
self,
api::{self, ConnectorCommon},
domain,
- transformers::ForeignFrom,
+ transformers::{ForeignFrom, ForeignTryFrom},
},
utils::{crypto, ByteSliceExt, BytesExt, OptionExt},
};
@@ -364,7 +364,7 @@ impl
req: &types::SetupMandateRouterData,
_connectors: &settings::Connectors,
) -> CustomResult<RequestContent, errors::ConnectorError> {
- let authorize_req = types::PaymentsAuthorizeRouterData::from((
+ let authorize_req = types::PaymentsAuthorizeRouterData::foreign_from((
req,
types::PaymentsAuthorizeData::from(req),
));
@@ -419,7 +419,7 @@ impl
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
@@ -703,7 +703,7 @@ impl
types::SyncRequestType::MultipleCaptureSync(_) => true,
types::SyncRequestType::SinglePaymentSync => false,
};
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
@@ -830,7 +830,7 @@ impl
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs
index 9dd523b73c..ab01f9e70c 100644
--- a/crates/router/src/connector/adyen/transformers.rs
+++ b/crates/router/src/connector/adyen/transformers.rs
@@ -3808,7 +3808,7 @@ pub fn get_present_to_shopper_metadata(
}
impl<F, Req>
- TryFrom<(
+ ForeignTryFrom<(
types::ResponseRouterData<F, AdyenPaymentResponse, Req, types::PaymentsResponseData>,
Option<storage_enums::CaptureMethod>,
bool,
@@ -3816,7 +3816,7 @@ impl<F, Req>
)> for types::RouterData<F, Req, types::PaymentsResponseData>
{
type Error = Error;
- fn try_from(
+ fn foreign_try_from(
(item, capture_method, is_multiple_capture_psync_flow, pmt): (
types::ResponseRouterData<F, AdyenPaymentResponse, Req, types::PaymentsResponseData>,
Option<storage_enums::CaptureMethod>,
diff --git a/crates/router/src/connector/airwallex.rs b/crates/router/src/connector/airwallex.rs
index bdd842bf95..ca511534b9 100644
--- a/crates/router/src/connector/airwallex.rs
+++ b/crates/router/src/connector/airwallex.rs
@@ -1,5 +1,4 @@
pub mod transformers;
-
use std::fmt::Debug;
use common_utils::{
@@ -28,6 +27,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
+ transformers::ForeignFrom,
ErrorResponse, Response, RouterData,
},
utils::{crypto, BytesExt},
@@ -349,7 +349,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
+ Sync
+ 'static),
> = Box::new(&Self);
- let authorize_data = &types::PaymentsInitRouterData::from((
+ let authorize_data = &types::PaymentsInitRouterData::foreign_from((
&router_data.to_owned(),
router_data.request.clone(),
));
diff --git a/crates/router/src/connector/authorizedotnet.rs b/crates/router/src/connector/authorizedotnet.rs
index 2ca78e630f..0eb4297a41 100644
--- a/crates/router/src/connector/authorizedotnet.rs
+++ b/crates/router/src/connector/authorizedotnet.rs
@@ -1,5 +1,4 @@
pub mod transformers;
-
use std::fmt::Debug;
use common_utils::{crypto, ext_traits::ByteSliceExt, request::RequestContent};
@@ -24,6 +23,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt, PaymentsCompleteAuthorize},
+ transformers::ForeignTryFrom,
},
utils::BytesExt,
};
@@ -218,7 +218,7 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
@@ -410,7 +410,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
@@ -791,7 +791,7 @@ impl
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index ca8b13298b..ddcfdfacad 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -17,7 +17,7 @@ use crate::{
api::{self, enums as api_enums},
domain,
storage::enums,
- transformers::ForeignFrom,
+ transformers::{ForeignFrom, ForeignTryFrom},
},
utils::OptionExt,
};
@@ -620,7 +620,7 @@ impl From<AuthorizedotnetVoidStatus> for enums::AttemptStatus {
}
impl<F, T>
- TryFrom<(
+ ForeignTryFrom<(
types::ResponseRouterData<
F,
AuthorizedotnetPaymentsResponse,
@@ -631,7 +631,7 @@ impl<F, T>
)> for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(
+ fn foreign_try_from(
(item, is_auto_capture): (
types::ResponseRouterData<
F,
diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs
index 1e8a167a17..4a5d99023c 100644
--- a/crates/router/src/connector/bankofamerica/transformers.rs
+++ b/crates/router/src/connector/bankofamerica/transformers.rs
@@ -375,7 +375,7 @@ impl<F, T>
.consumer_authentication_information
.as_ref()
.map(|consumer_auth_information| {
- types::AdditionalPaymentMethodConnectorResponse::from((
+ types::AdditionalPaymentMethodConnectorResponse::foreign_from((
processor_information,
consumer_auth_information,
))
@@ -422,7 +422,10 @@ impl<F, T>
})
}
BankOfAmericaSetupMandatesResponse::ErrorInformation(ref error_response) => {
- let response = Err(types::ErrorResponse::from((error_response, item.http_code)));
+ let response = Err(types::ErrorResponse::foreign_from((
+ error_response,
+ item.http_code,
+ )));
Ok(Self {
response,
status: enums::AttemptStatus::Failure,
@@ -1538,13 +1541,13 @@ pub struct BankOfAmericaErrorInformation {
}
impl<F, T>
- From<(
+ ForeignFrom<(
&BankOfAmericaErrorInformationResponse,
types::ResponseRouterData<F, BankOfAmericaPaymentsResponse, T, types::PaymentsResponseData>,
Option<enums::AttemptStatus>,
)> for types::RouterData<F, T, types::PaymentsResponseData>
{
- fn from(
+ fn foreign_from(
(error_response, item, transaction_status): (
&BankOfAmericaErrorInformationResponse,
types::ResponseRouterData<
@@ -1594,7 +1597,7 @@ fn get_error_response_if_failure(
),
) -> Option<types::ErrorResponse> {
if utils::is_payment_failure(status) {
- Some(types::ErrorResponse::from((
+ Some(types::ErrorResponse::foreign_from((
&info_response.error_information,
&info_response.risk_information,
Some(status),
@@ -1993,7 +1996,7 @@ impl<F>
let status = enums::AttemptStatus::from(info_response.status);
let risk_info: Option<ClientRiskInformation> = None;
if utils::is_payment_failure(status) {
- let response = Err(types::ErrorResponse::from((
+ let response = Err(types::ErrorResponse::foreign_from((
&info_response.error_information,
&risk_info,
Some(status),
@@ -2055,7 +2058,10 @@ impl<F>
}
}
BankOfAmericaPreProcessingResponse::ErrorInformation(ref error_response) => {
- let response = Err(types::ErrorResponse::from((error_response, item.http_code)));
+ let response = Err(types::ErrorResponse::foreign_from((
+ error_response,
+ item.http_code,
+ )));
Ok(Self {
response,
status: enums::AttemptStatus::AuthenticationFailed,
@@ -2102,7 +2108,7 @@ impl<F>
.consumer_authentication_information
.as_ref()
.map(|consumer_auth_information| {
- types::AdditionalPaymentMethodConnectorResponse::from((
+ types::AdditionalPaymentMethodConnectorResponse::foreign_from((
processor_information,
consumer_auth_information,
))
@@ -2130,7 +2136,7 @@ impl<F>
})
}
BankOfAmericaPaymentsResponse::ErrorInformation(ref error_response) => {
- Ok(Self::from((
+ Ok(Self::foreign_from((
&error_response.clone(),
item,
Some(enums::AttemptStatus::Failure),
@@ -2175,7 +2181,7 @@ impl<F>
.consumer_authentication_information
.as_ref()
.map(|consumer_auth_information| {
- types::AdditionalPaymentMethodConnectorResponse::from((
+ types::AdditionalPaymentMethodConnectorResponse::foreign_from((
processor_information,
consumer_auth_information,
))
@@ -2203,7 +2209,7 @@ impl<F>
})
}
BankOfAmericaPaymentsResponse::ErrorInformation(ref error_response) => {
- Ok(Self::from((
+ Ok(Self::foreign_from((
&error_response.clone(),
item,
Some(enums::AttemptStatus::Failure),
@@ -2214,12 +2220,12 @@ impl<F>
}
impl
- From<(
+ ForeignFrom<(
&ClientProcessorInformation,
&ConsumerAuthenticationInformation,
)> for types::AdditionalPaymentMethodConnectorResponse
{
- fn from(
+ fn foreign_from(
item: (
&ClientProcessorInformation,
&ConsumerAuthenticationInformation,
@@ -2281,7 +2287,7 @@ impl<F>
})
}
BankOfAmericaPaymentsResponse::ErrorInformation(ref error_response) => {
- Ok(Self::from((&error_response.clone(), item, None)))
+ Ok(Self::foreign_from((&error_response.clone(), item, None)))
}
}
}
@@ -2318,7 +2324,7 @@ impl<F>
})
}
BankOfAmericaPaymentsResponse::ErrorInformation(ref error_response) => {
- Ok(Self::from((&error_response.clone(), item, None)))
+ Ok(Self::foreign_from((&error_response.clone(), item, None)))
}
}
}
@@ -2396,7 +2402,7 @@ impl<F>
.consumer_authentication_information
.as_ref()
.map(|consumer_auth_information| {
- types::AdditionalPaymentMethodConnectorResponse::from((
+ types::AdditionalPaymentMethodConnectorResponse::foreign_from((
processor_information,
consumer_auth_information,
))
@@ -2419,7 +2425,7 @@ impl<F>
let risk_info: Option<ClientRiskInformation> = None;
if utils::is_payment_failure(status) {
Ok(Self {
- response: Err(types::ErrorResponse::from((
+ response: Err(types::ErrorResponse::foreign_from((
&app_response.error_information,
&risk_info,
Some(status),
@@ -2626,7 +2632,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, BankOfAmericaRefundR
) -> Result<Self, Self::Error> {
let refund_status = enums::RefundStatus::from(item.response.status.clone());
let response = if utils::is_refund_failure(refund_status) {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&item.response.error_information,
&None,
None,
@@ -2689,7 +2695,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, BankOfAmericaRsyncResp
enums::RefundStatus::from(status.clone());
if utils::is_refund_failure(refund_status) {
if status == BankofamericaRefundStatus::Voided {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&Some(BankOfAmericaErrorInformation {
message: Some(consts::REFUND_VOIDED.to_string()),
reason: None,
@@ -2700,7 +2706,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, BankOfAmericaRsyncResp
item.response.id.clone(),
)))
} else {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&item.response.error_information,
&None,
None,
@@ -2789,7 +2795,7 @@ pub struct AuthenticationErrorInformation {
}
impl
- From<(
+ ForeignFrom<(
&Option<BankOfAmericaErrorInformation>,
&Option<ClientRiskInformation>,
Option<enums::AttemptStatus>,
@@ -2797,7 +2803,7 @@ impl
String,
)> for types::ErrorResponse
{
- fn from(
+ fn foreign_from(
(error_data, risk_information, attempt_status, status_code, transaction_id): (
&Option<BankOfAmericaErrorInformation>,
&Option<ClientRiskInformation>,
@@ -3059,8 +3065,10 @@ impl From<&domain::GooglePayWalletData> for PaymentInformation {
}
}
-impl From<(&BankOfAmericaErrorInformationResponse, u16)> for types::ErrorResponse {
- fn from((error_response, status_code): (&BankOfAmericaErrorInformationResponse, u16)) -> Self {
+impl ForeignFrom<(&BankOfAmericaErrorInformationResponse, u16)> for types::ErrorResponse {
+ fn foreign_from(
+ (error_response, status_code): (&BankOfAmericaErrorInformationResponse, u16),
+ ) -> Self {
let error_reason = error_response
.error_information
.message
diff --git a/crates/router/src/connector/billwerk/transformers.rs b/crates/router/src/connector/billwerk/transformers.rs
index 3e5e53286e..372a65af9f 100644
--- a/crates/router/src/connector/billwerk/transformers.rs
+++ b/crates/router/src/connector/billwerk/transformers.rs
@@ -178,7 +178,7 @@ impl TryFrom<&BillwerkRouterData<&types::PaymentsAuthorizeRouterData>> for Billw
.into());
};
let source = match item.router_data.get_payment_method_token()? {
- types::PaymentMethodToken::Token(pm_token) => Ok(Secret::new(pm_token)),
+ types::PaymentMethodToken::Token(pm_token) => Ok(pm_token),
_ => Err(errors::ConnectorError::MissingRequiredField {
field_name: "payment_method_token",
}),
diff --git a/crates/router/src/connector/braintree/braintree_graphql_transformers.rs b/crates/router/src/connector/braintree/braintree_graphql_transformers.rs
index bd860e7290..a607d8fc60 100644
--- a/crates/router/src/connector/braintree/braintree_graphql_transformers.rs
+++ b/crates/router/src/connector/braintree/braintree_graphql_transformers.rs
@@ -1324,7 +1324,7 @@ impl
variables: VariablePaymentInput {
input: PaymentInput {
payment_method_id: match item.router_data.get_payment_method_token()? {
- types::PaymentMethodToken::Token(token) => token.into(),
+ types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Braintree"),
)?,
@@ -1405,7 +1405,7 @@ fn get_braintree_redirect_form(
.client_token
.expose(),
card_token: match payment_method_token {
- types::PaymentMethodToken::Token(token) => token,
+ types::PaymentMethodToken::Token(token) => token.expose(),
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(unimplemented_payment_method!(
"Apple Pay",
"Simplified",
diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs
index cc937c0ef6..ddf65d23aa 100644
--- a/crates/router/src/connector/checkout/transformers.rs
+++ b/crates/router/src/connector/checkout/transformers.rs
@@ -294,7 +294,7 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
domain::WalletData::GooglePay(_) => Ok(PaymentSource::Wallets(WalletSource {
source_type: CheckoutSourceTypes::Token,
token: match item.router_data.get_payment_method_token()? {
- types::PaymentMethodToken::Token(token) => token.into(),
+ types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Checkout"),
)?,
@@ -306,7 +306,7 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
types::PaymentMethodToken::Token(apple_pay_payment_token) => {
Ok(PaymentSource::Wallets(WalletSource {
source_type: CheckoutSourceTypes::Token,
- token: apple_pay_payment_token.into(),
+ token: apple_pay_payment_token,
}))
}
types::PaymentMethodToken::ApplePayDecrypt(decrypt_data) => {
diff --git a/crates/router/src/connector/cryptopay.rs b/crates/router/src/connector/cryptopay.rs
index 7245694bd4..f7d137eff2 100644
--- a/crates/router/src/connector/cryptopay.rs
+++ b/crates/router/src/connector/cryptopay.rs
@@ -30,6 +30,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
+ transformers::ForeignTryFrom,
ErrorResponse, Response,
},
utils::BytesExt,
@@ -287,7 +288,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
@@ -374,7 +375,7 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
diff --git a/crates/router/src/connector/cryptopay/transformers.rs b/crates/router/src/connector/cryptopay/transformers.rs
index baea07faa6..d9d164ac20 100644
--- a/crates/router/src/connector/cryptopay/transformers.rs
+++ b/crates/router/src/connector/cryptopay/transformers.rs
@@ -10,7 +10,7 @@ use crate::{
consts,
core::errors,
services,
- types::{self, domain, storage::enums},
+ types::{self, domain, storage::enums, transformers::ForeignTryFrom},
};
#[derive(Debug, Serialize)]
@@ -141,13 +141,13 @@ pub struct CryptopayPaymentsResponse {
}
impl<F, T>
- TryFrom<(
+ ForeignTryFrom<(
types::ResponseRouterData<F, CryptopayPaymentsResponse, T, types::PaymentsResponseData>,
diesel_models::enums::Currency,
)> for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(
+ fn foreign_try_from(
(item, currency): (
types::ResponseRouterData<F, CryptopayPaymentsResponse, T, types::PaymentsResponseData>,
diesel_models::enums::Currency,
diff --git a/crates/router/src/connector/cybersource.rs b/crates/router/src/connector/cybersource.rs
index 763680d754..43e5660d2b 100644
--- a/crates/router/src/connector/cybersource.rs
+++ b/crates/router/src/connector/cybersource.rs
@@ -31,6 +31,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
+ transformers::ForeignTryFrom,
},
utils::BytesExt,
};
@@ -1600,7 +1601,7 @@ impl
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs
index 517d406a9d..a9b1c37ae9 100644
--- a/crates/router/src/connector/cybersource/transformers.rs
+++ b/crates/router/src/connector/cybersource/transformers.rs
@@ -26,7 +26,7 @@ use crate::{
api::{self, enums as api_enums},
domain,
storage::enums,
- transformers::ForeignFrom,
+ transformers::{ForeignFrom, ForeignTryFrom},
ApplePayPredecryptData,
},
unimplemented_payment_method,
@@ -1670,13 +1670,13 @@ pub struct CybersourceErrorInformation {
}
impl<F, T>
- From<(
+ ForeignFrom<(
&CybersourceErrorInformationResponse,
types::ResponseRouterData<F, CybersourcePaymentsResponse, T, types::PaymentsResponseData>,
Option<enums::AttemptStatus>,
)> for types::RouterData<F, T, types::PaymentsResponseData>
{
- fn from(
+ fn foreign_from(
(error_response, item, transaction_status): (
&CybersourceErrorInformationResponse,
types::ResponseRouterData<
@@ -1726,7 +1726,7 @@ fn get_error_response_if_failure(
),
) -> Option<types::ErrorResponse> {
if utils::is_payment_failure(status) {
- Some(types::ErrorResponse::from((
+ Some(types::ErrorResponse::foreign_from((
&info_response.error_information,
&info_response.risk_information,
Some(status),
@@ -1822,11 +1822,13 @@ impl<F>
..item.data
})
}
- CybersourcePaymentsResponse::ErrorInformation(ref error_response) => Ok(Self::from((
- &error_response.clone(),
- item,
- Some(enums::AttemptStatus::Failure),
- ))),
+ CybersourcePaymentsResponse::ErrorInformation(ref error_response) => {
+ Ok(Self::foreign_from((
+ &error_response.clone(),
+ item,
+ Some(enums::AttemptStatus::Failure),
+ )))
+ }
}
}
}
@@ -2189,7 +2191,7 @@ impl<F>
let status = enums::AttemptStatus::from(info_response.status);
let risk_info: Option<ClientRiskInformation> = None;
if utils::is_payment_failure(status) {
- let response = Err(types::ErrorResponse::from((
+ let response = Err(types::ErrorResponse::foreign_from((
&info_response.error_information,
&risk_info,
Some(status),
@@ -2315,11 +2317,13 @@ impl<F>
..item.data
})
}
- CybersourcePaymentsResponse::ErrorInformation(ref error_response) => Ok(Self::from((
- &error_response.clone(),
- item,
- Some(enums::AttemptStatus::Failure),
- ))),
+ CybersourcePaymentsResponse::ErrorInformation(ref error_response) => {
+ Ok(Self::foreign_from((
+ &error_response.clone(),
+ item,
+ Some(enums::AttemptStatus::Failure),
+ )))
+ }
}
}
}
@@ -2368,7 +2372,7 @@ impl<F>
})
}
CybersourcePaymentsResponse::ErrorInformation(ref error_response) => {
- Ok(Self::from((&error_response.clone(), item, None)))
+ Ok(Self::foreign_from((&error_response.clone(), item, None)))
}
}
}
@@ -2405,7 +2409,7 @@ impl<F>
})
}
CybersourcePaymentsResponse::ErrorInformation(ref error_response) => {
- Ok(Self::from((&error_response.clone(), item, None)))
+ Ok(Self::foreign_from((&error_response.clone(), item, None)))
}
}
}
@@ -2516,7 +2520,7 @@ impl<F, T>
}
impl<F, T>
- TryFrom<(
+ ForeignTryFrom<(
types::ResponseRouterData<
F,
CybersourcePaymentsIncrementalAuthorizationResponse,
@@ -2527,7 +2531,7 @@ impl<F, T>
)> for types::RouterData<F, T, types::PaymentsResponseData>
{
type Error = error_stack::Report<errors::ConnectorError>;
- fn try_from(
+ fn foreign_try_from(
data: (
types::ResponseRouterData<
F,
@@ -2615,7 +2619,7 @@ impl<F>
let risk_info: Option<ClientRiskInformation> = None;
if utils::is_payment_failure(status) {
Ok(Self {
- response: Err(types::ErrorResponse::from((
+ response: Err(types::ErrorResponse::foreign_from((
&app_response.error_information,
&risk_info,
Some(status),
@@ -2733,7 +2737,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, CybersourceRefundRes
) -> Result<Self, Self::Error> {
let refund_status = enums::RefundStatus::from(item.response.status.clone());
let response = if utils::is_refund_failure(refund_status) {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&item.response.error_information,
&None,
None,
@@ -2784,7 +2788,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, CybersourceRsyncRespon
let refund_status = enums::RefundStatus::from(status.clone());
if utils::is_refund_failure(refund_status) {
if status == CybersourceRefundStatus::Voided {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&Some(CybersourceErrorInformation {
message: Some(consts::REFUND_VOIDED.to_string()),
reason: None,
@@ -2795,7 +2799,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, CybersourceRsyncRespon
item.response.id.clone(),
)))
} else {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&item.response.error_information,
&None,
None,
@@ -3117,7 +3121,7 @@ pub struct AuthenticationErrorInformation {
}
impl
- From<(
+ ForeignFrom<(
&Option<CybersourceErrorInformation>,
&Option<ClientRiskInformation>,
Option<enums::AttemptStatus>,
@@ -3125,7 +3129,7 @@ impl
String,
)> for types::ErrorResponse
{
- fn from(
+ fn foreign_from(
(error_data, risk_information, attempt_status, status_code, transaction_id): (
&Option<CybersourceErrorInformation>,
&Option<ClientRiskInformation>,
diff --git a/crates/router/src/connector/globalpay.rs b/crates/router/src/connector/globalpay.rs
index d98281cb84..d00b0e545a 100644
--- a/crates/router/src/connector/globalpay.rs
+++ b/crates/router/src/connector/globalpay.rs
@@ -2,7 +2,6 @@ mod requests;
use super::utils as connector_utils;
mod response;
pub mod transformers;
-
use std::fmt::Debug;
use ::common_utils::{errors::ReportSwitchExt, ext_traits::ByteSliceExt, request::RequestContent};
@@ -35,6 +34,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt, PaymentsCompleteAuthorize},
+ transformers::ForeignTryFrom,
ErrorResponse,
},
utils::{crypto, BytesExt},
@@ -547,7 +547,7 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe
types::SyncRequestType::MultipleCaptureSync(_) => true,
types::SyncRequestType::SinglePaymentSync => false,
};
- types::RouterData::try_from((
+ types::RouterData::foreign_try_from((
types::ResponseRouterData {
response,
data: data.clone(),
diff --git a/crates/router/src/connector/globalpay/transformers.rs b/crates/router/src/connector/globalpay/transformers.rs
index 478da2cf90..6653205c06 100644
--- a/crates/router/src/connector/globalpay/transformers.rs
+++ b/crates/router/src/connector/globalpay/transformers.rs
@@ -17,7 +17,7 @@ use crate::{
consts,
core::errors,
services::{self, RedirectForm},
- types::{self, api, domain, storage::enums, ErrorResponse},
+ types::{self, api, domain, storage::enums, transformers::ForeignTryFrom, ErrorResponse},
};
type Error = error_stack::Report<errors::ConnectorError>;
@@ -279,14 +279,14 @@ impl<F, T>
}
impl
- TryFrom<(
+ ForeignTryFrom<(
types::PaymentsSyncResponseRouterData<GlobalpayPaymentsResponse>,
bool,
)> for types::PaymentsSyncRouterData
{
type Error = Error;
- fn try_from(
+ fn foreign_try_from(
(value, is_multiple_capture_sync): (
types::PaymentsSyncResponseRouterData<GlobalpayPaymentsResponse>,
bool,
diff --git a/crates/router/src/connector/gocardless/transformers.rs b/crates/router/src/connector/gocardless/transformers.rs
index 97f1146b50..b94dd73dd2 100644
--- a/crates/router/src/connector/gocardless/transformers.rs
+++ b/crates/router/src/connector/gocardless/transformers.rs
@@ -433,7 +433,7 @@ impl TryFrom<&types::SetupMandateRouterData> for GocardlessMandateRequest {
},
payer_ip_address,
links: MandateLink {
- customer_bank_account: Secret::new(customer_bank_account),
+ customer_bank_account,
},
},
})
diff --git a/crates/router/src/connector/mollie/transformers.rs b/crates/router/src/connector/mollie/transformers.rs
index e2c3fc6699..4a6c5b314e 100644
--- a/crates/router/src/connector/mollie/transformers.rs
+++ b/crates/router/src/connector/mollie/transformers.rs
@@ -175,7 +175,7 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP
CreditCardMethodData {
billing_address: get_billing_details(item.router_data)?,
shipping_address: get_shipping_details(item.router_data)?,
- card_token: Some(Secret::new(match pm_token {
+ card_token: Some(match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(unimplemented_payment_method!(
@@ -184,7 +184,7 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP
"Mollie"
))?
}
- })),
+ }),
},
)))
}
@@ -497,7 +497,7 @@ impl<F, T>
Ok(Self {
status: storage_enums::AttemptStatus::Pending,
payment_method_token: Some(types::PaymentMethodToken::Token(
- item.response.card_token.clone().expose(),
+ item.response.card_token.clone(),
)),
response: Ok(types::PaymentsResponseData::TokenizationResponse {
token: item.response.card_token.expose(),
diff --git a/crates/router/src/connector/multisafepay.rs b/crates/router/src/connector/multisafepay.rs
index a8a79095d3..117d8f764f 100644
--- a/crates/router/src/connector/multisafepay.rs
+++ b/crates/router/src/connector/multisafepay.rs
@@ -23,6 +23,7 @@ use crate::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
storage::enums,
+ transformers::ForeignFrom,
ErrorResponse, Response,
},
utils::BytesExt,
@@ -88,7 +89,7 @@ impl ConnectorCommon for Multisafepay {
let attempt_status = Option::<AttemptStatus>::from(response.clone());
- Ok(ErrorResponse::from((
+ Ok(ErrorResponse::foreign_from((
Some(response.error_code.to_string()),
Some(response.error_info.clone()),
Some(response.error_info),
diff --git a/crates/router/src/connector/multisafepay/transformers.rs b/crates/router/src/connector/multisafepay/transformers.rs
index f993928d94..400e5ecd11 100644
--- a/crates/router/src/connector/multisafepay/transformers.rs
+++ b/crates/router/src/connector/multisafepay/transformers.rs
@@ -11,7 +11,7 @@ use crate::{
core::errors,
pii::Secret,
services,
- types::{self, api, domain, storage::enums},
+ types::{self, api, domain, storage::enums, transformers::ForeignFrom},
};
#[derive(Debug, Serialize)]
@@ -671,7 +671,7 @@ impl<F, T>
Ok(Self {
status,
response: if utils::is_payment_failure(status) {
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
payment_response.data.reason_code,
payment_response.data.reason.clone(),
payment_response.data.reason,
@@ -707,7 +707,7 @@ impl<F, T>
MultisafepayAuthResponse::ErrorResponse(error_response) => {
let attempt_status = Option::<AttemptStatus>::from(error_response.clone());
Ok(Self {
- response: Err(types::ErrorResponse::from((
+ response: Err(types::ErrorResponse::foreign_from((
Some(error_response.error_code.to_string()),
Some(error_response.error_info.clone()),
Some(error_response.error_info),
@@ -857,7 +857,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, MultisafepayRefundResp
})
}
MultisafepayRefundResponse::ErrorResponse(error_response) => Ok(Self {
- response: Err(types::ErrorResponse::from((
+ response: Err(types::ErrorResponse::foreign_from((
Some(error_response.error_code.to_string()),
Some(error_response.error_info.clone()),
Some(error_response.error_info),
diff --git a/crates/router/src/connector/nuvei.rs b/crates/router/src/connector/nuvei.rs
index 1f9fd861c0..4b8793a8e8 100644
--- a/crates/router/src/connector/nuvei.rs
+++ b/crates/router/src/connector/nuvei.rs
@@ -26,6 +26,7 @@ use crate::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt, InitPayment},
storage::enums,
+ transformers::ForeignFrom,
ErrorResponse, Response,
},
utils::ByteSliceExt,
@@ -536,7 +537,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
+ Sync
+ 'static),
> = Box::new(&Self);
- let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::from((
+ let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::foreign_from((
&router_data.to_owned(),
types::AuthorizeSessionTokenData::from(&router_data),
));
@@ -564,7 +565,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
+ Sync
+ 'static),
> = Box::new(&Self);
- let init_data = &types::PaymentsInitRouterData::from((
+ let init_data = &types::PaymentsInitRouterData::foreign_from((
&router_data.to_owned(),
router_data.request.clone(),
));
diff --git a/crates/router/src/connector/payme/transformers.rs b/crates/router/src/connector/payme/transformers.rs
index b04b8cb474..bf20eb1a0b 100644
--- a/crates/router/src/connector/payme/transformers.rs
+++ b/crates/router/src/connector/payme/transformers.rs
@@ -17,7 +17,10 @@ use crate::{
consts,
core::errors,
services,
- types::{self, api, domain, domain::PaymentMethodData, storage::enums, MandateReference},
+ types::{
+ self, api, domain, domain::PaymentMethodData, storage::enums, transformers::ForeignFrom,
+ MandateReference,
+ },
unimplemented_payment_method,
};
@@ -68,7 +71,7 @@ pub struct MandateRequest {
pub struct Pay3dsRequest {
buyer_name: Secret<String>,
buyer_email: pii::Email,
- buyer_key: String,
+ buyer_key: Secret<String>,
payme_sale_id: String,
meta_data_jwt: Secret<String>,
}
@@ -188,7 +191,10 @@ impl<F, T>
let status = enums::AttemptStatus::from(item.response.sale_status.clone());
let response = if is_payment_failure(status) {
// To populate error message in case of failure
- Err(types::ErrorResponse::from((&item.response, item.http_code)))
+ Err(types::ErrorResponse::foreign_from((
+ &item.response,
+ item.http_code,
+ )))
} else {
Ok(types::PaymentsResponseData::try_from(&item.response)?)
};
@@ -200,8 +206,8 @@ impl<F, T>
}
}
-impl From<(&PaymePaySaleResponse, u16)> for types::ErrorResponse {
- fn from((pay_sale_response, http_code): (&PaymePaySaleResponse, u16)) -> Self {
+impl ForeignFrom<(&PaymePaySaleResponse, u16)> for types::ErrorResponse {
+ fn foreign_from((pay_sale_response, http_code): (&PaymePaySaleResponse, u16)) -> Self {
let code = pay_sale_response
.status_error_code
.map(|error_code| error_code.to_string())
@@ -266,7 +272,7 @@ impl<F, T> TryFrom<types::ResponseRouterData<F, SaleQueryResponse, T, types::Pay
let status = enums::AttemptStatus::from(transaction_response.sale_status.clone());
let response = if is_payment_failure(status) {
// To populate error message in case of failure
- Err(types::ErrorResponse::from((
+ Err(types::ErrorResponse::foreign_from((
&transaction_response,
item.http_code,
)))
@@ -281,8 +287,8 @@ impl<F, T> TryFrom<types::ResponseRouterData<F, SaleQueryResponse, T, types::Pay
}
}
-impl From<(&SaleQuery, u16)> for types::ErrorResponse {
- fn from((sale_query_response, http_code): (&SaleQuery, u16)) -> Self {
+impl ForeignFrom<(&SaleQuery, u16)> for types::ErrorResponse {
+ fn foreign_from((sale_query_response, http_code): (&SaleQuery, u16)) -> Self {
Self {
code: sale_query_response
.sale_error_code
@@ -880,7 +886,7 @@ impl<F, T>
) -> Result<Self, Self::Error> {
Ok(Self {
payment_method_token: Some(types::PaymentMethodToken::Token(
- item.response.buyer_key.clone().expose(),
+ item.response.buyer_key.clone(),
)),
response: Ok(types::PaymentsResponseData::TokenizationResponse {
token: item.response.buyer_key.expose(),
diff --git a/crates/router/src/connector/shift4.rs b/crates/router/src/connector/shift4.rs
index e7487e795b..6c54c7019c 100644
--- a/crates/router/src/connector/shift4.rs
+++ b/crates/router/src/connector/shift4.rs
@@ -25,6 +25,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
+ transformers::ForeignFrom,
ErrorResponse,
},
utils::BytesExt,
@@ -229,7 +230,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
+ Sync
+ 'static),
> = Box::new(&Self);
- let init_data = &types::PaymentsInitRouterData::from((
+ let init_data = &types::PaymentsInitRouterData::foreign_from((
&router_data.to_owned(),
router_data.request.clone(),
));
diff --git a/crates/router/src/connector/square.rs b/crates/router/src/connector/square.rs
index 915a9a9ca1..f9a81031b0 100644
--- a/crates/router/src/connector/square.rs
+++ b/crates/router/src/connector/square.rs
@@ -27,6 +27,7 @@ use crate::{
types::{
self,
api::{self, ConnectorCommon, ConnectorCommonExt},
+ transformers::ForeignFrom,
ErrorResponse, Response,
},
utils::BytesExt,
@@ -214,7 +215,7 @@ impl
amount: router_data.request.amount,
};
- let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::from((
+ let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::foreign_from((
&router_data.to_owned(),
authorize_session_token_data,
));
diff --git a/crates/router/src/connector/square/transformers.rs b/crates/router/src/connector/square/transformers.rs
index c980a4e749..0de122d5da 100644
--- a/crates/router/src/connector/square/transformers.rs
+++ b/crates/router/src/connector/square/transformers.rs
@@ -258,12 +258,12 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for SquarePaymentsRequest {
let pm_token = item.get_payment_method_token()?;
Ok(Self {
idempotency_key: Secret::new(item.attempt_id.clone()),
- source_id: Secret::new(match pm_token {
+ source_id: match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Square"),
)?,
- }),
+ },
amount_money: SquarePaymentsAmountData {
amount: item.request.amount,
currency: item.request.currency,
diff --git a/crates/router/src/connector/stax/transformers.rs b/crates/router/src/connector/stax/transformers.rs
index 95e5dbe4f4..6477b2325e 100644
--- a/crates/router/src/connector/stax/transformers.rs
+++ b/crates/router/src/connector/stax/transformers.rs
@@ -67,12 +67,12 @@ impl TryFrom<&StaxRouterData<&types::PaymentsAuthorizeRouterData>> for StaxPayme
total,
is_refundable: true,
pre_auth,
- payment_method_id: Secret::new(match pm_token {
+ payment_method_id: match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Stax"),
)?,
- }),
+ },
idempotency_id: Some(item.router_data.connector_request_reference_id.clone()),
})
}
@@ -86,12 +86,12 @@ impl TryFrom<&StaxRouterData<&types::PaymentsAuthorizeRouterData>> for StaxPayme
total,
is_refundable: true,
pre_auth,
- payment_method_id: Secret::new(match pm_token {
+ payment_method_id: match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Stax"),
)?,
- }),
+ },
idempotency_id: Some(item.router_data.connector_request_reference_id.clone()),
})
}
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index 1e58a144b9..20c1b4e70f 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -1828,7 +1828,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
};
Some(StripePaymentMethodData::Wallet(
StripeWallet::ApplepayPayment(ApplepayPayment {
- token: Secret::new(payment_method_token),
+ token: payment_method_token,
payment_method_types: StripePaymentMethodType::Card,
}),
))
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index 14d856bb09..6a569e76a6 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -27,11 +27,13 @@ use crate::{
consts,
core::{
errors::{self, ApiErrorResponse, CustomResult},
- payments::{types::AuthenticationData, PaymentData, RecurringMandatePaymentData},
+ payments::{types::AuthenticationData, PaymentData},
},
pii::PeekInterface,
types::{
- self, api, domain, storage::enums as storage_enums, transformers::ForeignTryFrom,
+ self, api, domain,
+ storage::enums as storage_enums,
+ transformers::{ForeignFrom, ForeignTryFrom},
ApplePayPredecryptData, BrowserInformation, PaymentsCancelData, ResponseId,
},
utils::{OptionExt, ValueExt},
@@ -86,7 +88,9 @@ pub trait RouterData {
fn get_customer_id(&self) -> Result<String, Error>;
fn get_connector_customer_id(&self) -> Result<String, Error>;
fn get_preprocessing_id(&self) -> Result<String, Error>;
- fn get_recurring_mandate_payment_data(&self) -> Result<RecurringMandatePaymentData, Error>;
+ fn get_recurring_mandate_payment_data(
+ &self,
+ ) -> Result<types::RecurringMandatePaymentData, Error>;
#[cfg(feature = "payouts")]
fn get_payout_method_data(&self) -> Result<api::PayoutMethodData, Error>;
#[cfg(feature = "payouts")]
@@ -411,7 +415,9 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
.to_owned()
.ok_or_else(missing_field_err("preprocessing_id"))
}
- fn get_recurring_mandate_payment_data(&self) -> Result<RecurringMandatePaymentData, Error> {
+ fn get_recurring_mandate_payment_data(
+ &self,
+ ) -> Result<types::RecurringMandatePaymentData, Error> {
self.recurring_mandate_payment_data
.to_owned()
.ok_or_else(missing_field_err("recurring_mandate_payment_data"))
@@ -1545,7 +1551,7 @@ pub trait RecurringMandateData {
fn get_original_payment_currency(&self) -> Result<enums::Currency, Error>;
}
-impl RecurringMandateData for RecurringMandatePaymentData {
+impl RecurringMandateData for types::RecurringMandatePaymentData {
fn get_original_payment_amount(&self) -> Result<i64, Error> {
self.original_payment_authorized_amount
.ok_or_else(missing_field_err("original_payment_authorized_amount"))
@@ -2181,7 +2187,7 @@ pub fn is_refund_failure(status: enums::RefundStatus) -> bool {
}
impl
- From<(
+ ForeignFrom<(
Option<String>,
Option<String>,
Option<String>,
@@ -2190,7 +2196,7 @@ impl
Option<String>,
)> for types::ErrorResponse
{
- fn from(
+ fn foreign_from(
(code, message, reason, http_code, attempt_status, connector_transaction_id): (
Option<String>,
Option<String>,
diff --git a/crates/router/src/connector/wise.rs b/crates/router/src/connector/wise.rs
index 3a241fe4ed..667e182b67 100644
--- a/crates/router/src/connector/wise.rs
+++ b/crates/router/src/connector/wise.rs
@@ -27,7 +27,7 @@ use crate::{
utils::BytesExt,
};
#[cfg(feature = "payouts")]
-use crate::{core::payments, routes};
+use crate::{core::payments, routes, types::transformers::ForeignFrom};
#[derive(Debug, Clone)]
pub struct Wise;
@@ -510,7 +510,7 @@ impl services::ConnectorIntegration<api::PoCreate, types::PayoutsData, types::Pa
) -> CustomResult<(), errors::ConnectorError> {
// Create a quote
let quote_router_data =
- &types::PayoutsRouterData::from((&router_data, router_data.request.clone()));
+ &types::PayoutsRouterData::foreign_from((&router_data, router_data.request.clone()));
let quote_connector_integration: Box<
&(dyn services::ConnectorIntegration<
api::PoQuote,
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index 50ebea2487..144c7d09b1 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -4,16 +4,14 @@ use router_env::tracing::{self, instrument};
use crate::{
core::{
- errors::RouterResult,
- fraud_check::frm_core_types::FrmFulfillmentRequest,
- payments::{helpers, PaymentAddress},
- utils as core_utils,
+ errors::RouterResult, fraud_check::frm_core_types::FrmFulfillmentRequest,
+ payments::helpers, utils as core_utils,
},
errors,
types::{
domain,
fraud_check::{FraudCheckFulfillmentData, FrmFulfillmentRouterData},
- storage, ConnectorAuthType, ErrorResponse, RouterData,
+ storage, ConnectorAuthType, ErrorResponse, PaymentAddress, RouterData,
},
utils, AppState,
};
diff --git a/crates/router/src/core/mandate/helpers.rs b/crates/router/src/core/mandate/helpers.rs
index f3b7b384e2..4e9d07b7f8 100644
--- a/crates/router/src/core/mandate/helpers.rs
+++ b/crates/router/src/core/mandate/helpers.rs
@@ -81,7 +81,8 @@ pub struct MandateGenericData {
pub payment_method: Option<enums::PaymentMethod>,
pub payment_method_type: Option<enums::PaymentMethodType>,
pub mandate_data: Option<MandateData>,
- pub recurring_mandate_payment_data: Option<payments::RecurringMandatePaymentData>,
+ pub recurring_mandate_payment_data:
+ Option<hyperswitch_domain_models::router_data::RecurringMandatePaymentData>,
pub mandate_connector: Option<payments::MandateConnectorDetails>,
pub payment_method_info: Option<diesel_models::PaymentMethod>,
}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 1d25db6a0b..668a4242b0 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -34,9 +34,12 @@ use error_stack::{report, ResultExt};
use events::EventInfo;
use futures::future::join_all;
use helpers::ApplePayData;
-use hyperswitch_domain_models::mandates::{CustomerAcceptance, MandateData};
+use hyperswitch_domain_models::{
+ mandates::{CustomerAcceptance, MandateData},
+ payment_address::PaymentAddress,
+ router_data::RouterData,
+};
use masking::{ExposeInterface, Secret};
-pub use payment_address::PaymentAddress;
use redis_interface::errors::RedisError;
use router_env::{instrument, tracing};
#[cfg(feature = "olap")]
@@ -117,7 +120,7 @@ where
// To create connector flow specific interface data
PaymentData<F>: ConstructFlowSpecificData<F, FData, router_types::PaymentsResponseData>,
- router_types::RouterData<F, FData, router_types::PaymentsResponseData>: Feature<F, FData>,
+ RouterData<F, FData, router_types::PaymentsResponseData>: Feature<F, FData>,
// To construct connector flow specific api
dyn api::Connector:
@@ -756,7 +759,7 @@ where
Res: transformers::ToResponse<PaymentData<F>, Op>,
// To create connector flow specific interface data
PaymentData<F>: ConstructFlowSpecificData<F, FData, router_types::PaymentsResponseData>,
- router_types::RouterData<F, FData, router_types::PaymentsResponseData>: Feature<F, FData>,
+ RouterData<F, FData, router_types::PaymentsResponseData>: Feature<F, FData>,
// To construct connector flow specific api
dyn api::Connector:
@@ -1386,15 +1389,14 @@ pub async fn call_connector_service<F, RouterDReq, ApiRequest>(
header_payload: HeaderPayload,
frm_suggestion: Option<storage_enums::FrmSuggestion>,
business_profile: &storage::business_profile::BusinessProfile,
-) -> RouterResult<router_types::RouterData<F, RouterDReq, router_types::PaymentsResponseData>>
+) -> RouterResult<RouterData<F, RouterDReq, router_types::PaymentsResponseData>>
where
F: Send + Clone + Sync,
RouterDReq: Send + Sync,
// To create connector flow specific interface data
PaymentData<F>: ConstructFlowSpecificData<F, RouterDReq, router_types::PaymentsResponseData>,
- router_types::RouterData<F, RouterDReq, router_types::PaymentsResponseData>:
- Feature<F, RouterDReq> + Send,
+ RouterData<F, RouterDReq, router_types::PaymentsResponseData>: Feature<F, RouterDReq> + Send,
// To construct connector flow specific api
dyn api::Connector:
services::api::ConnectorIntegration<F, RouterDReq, router_types::PaymentsResponseData>,
@@ -1495,23 +1497,29 @@ where
};
let apple_pay_predecrypt = apple_pay_data
- .parse_value::<router_types::ApplePayPredecryptData>("ApplePayPredecryptData")
+ .parse_value::<hyperswitch_domain_models::router_data::ApplePayPredecryptData>(
+ "ApplePayPredecryptData",
+ )
.change_context(errors::ApiErrorResponse::InternalServerError)?;
logger::debug!(?apple_pay_predecrypt);
- router_data.payment_method_token = Some(router_types::PaymentMethodToken::ApplePayDecrypt(
- Box::new(apple_pay_predecrypt),
- ));
+ router_data.payment_method_token = Some(
+ hyperswitch_domain_models::router_data::PaymentMethodToken::ApplePayDecrypt(Box::new(
+ apple_pay_predecrypt,
+ )),
+ );
}
let pm_token = router_data
.add_payment_method_token(state, &connector, &tokenization_action)
.await?;
if let Some(payment_method_token) = pm_token.clone() {
- router_data.payment_method_token = Some(router_types::PaymentMethodToken::Token(
- payment_method_token,
- ));
+ router_data.payment_method_token = Some(
+ hyperswitch_domain_models::router_data::PaymentMethodToken::Token(Secret::new(
+ payment_method_token,
+ )),
+ );
};
(router_data, should_continue_further) = complete_preprocessing_steps_if_required(
@@ -1657,7 +1665,7 @@ where
// To create connector flow specific interface data
PaymentData<F>: ConstructFlowSpecificData<F, Req, router_types::PaymentsResponseData>,
- router_types::RouterData<F, Req, router_types::PaymentsResponseData>: Feature<F, Req>,
+ RouterData<F, Req, router_types::PaymentsResponseData>: Feature<F, Req>,
// To construct connector flow specific api
dyn api::Connector:
@@ -1771,7 +1779,7 @@ where
// To create connector flow specific interface data
PaymentData<F>: ConstructFlowSpecificData<F, Req, router_types::PaymentsResponseData>,
- router_types::RouterData<F, Req, router_types::PaymentsResponseData>: Feature<F, Req> + Send,
+ RouterData<F, Req, router_types::PaymentsResponseData>: Feature<F, Req> + Send,
// To construct connector flow specific api
dyn api::Connector:
@@ -1863,17 +1871,14 @@ async fn complete_preprocessing_steps_if_required<F, Req, Q>(
state: &AppState,
connector: &api::ConnectorData,
payment_data: &PaymentData<F>,
- mut router_data: router_types::RouterData<F, Req, router_types::PaymentsResponseData>,
+ mut router_data: RouterData<F, Req, router_types::PaymentsResponseData>,
operation: &BoxedOperation<'_, F, Q>,
should_continue_payment: bool,
-) -> RouterResult<(
- router_types::RouterData<F, Req, router_types::PaymentsResponseData>,
- bool,
-)>
+) -> RouterResult<(RouterData<F, Req, router_types::PaymentsResponseData>, bool)>
where
F: Send + Clone + Sync,
Req: Send + Sync,
- router_types::RouterData<F, Req, router_types::PaymentsResponseData>: Feature<F, Req> + Send,
+ RouterData<F, Req, router_types::PaymentsResponseData>: Feature<F, Req> + Send,
dyn api::Connector:
services::api::ConnectorIntegration<F, Req, router_types::PaymentsResponseData>,
{
@@ -2398,91 +2403,6 @@ pub enum CallConnectorAction {
HandleResponse(Vec<u8>),
}
-pub mod payment_address {
- use super::*;
-
- #[derive(Clone, Default, Debug)]
- pub struct PaymentAddress {
- shipping: Option<api::Address>,
- billing: Option<api::Address>,
- unified_payment_method_billing: Option<api::Address>,
- payment_method_billing: Option<api::Address>,
- }
-
- impl PaymentAddress {
- pub fn new(
- shipping: Option<api::Address>,
- billing: Option<api::Address>,
- payment_method_billing: Option<api::Address>,
- should_unify_address: Option<bool>,
- ) -> Self {
- // billing -> .billing, this is the billing details passed in the root of payments request
- // payment_method_billing -> payment_method_data.billing
-
- let unified_payment_method_billing = if should_unify_address.unwrap_or(true) {
- // Merge the billing details field from both `payment.billing` and `payment.payment_method_data.billing`
- // The unified payment_method_billing will be used as billing address and passed to the connector module
- // This unification is required in order to provide backwards compatibility
- // so that if `payment.billing` is passed it should be sent to the connector module
- // Unify the billing details with `payment_method_data.billing`
- payment_method_billing
- .as_ref()
- .map(|payment_method_billing| {
- payment_method_billing
- .clone()
- .unify_address(billing.as_ref())
- })
- .or(billing.clone())
- } else {
- payment_method_billing.clone()
- };
-
- Self {
- shipping,
- billing,
- unified_payment_method_billing,
- payment_method_billing,
- }
- }
-
- pub fn get_shipping(&self) -> Option<&api::Address> {
- self.shipping.as_ref()
- }
-
- pub fn get_payment_method_billing(&self) -> Option<&api::Address> {
- self.unified_payment_method_billing.as_ref()
- }
-
- /// Unify the billing details from `payment_method_data.[payment_method_data].billing details`.
- pub fn unify_with_payment_method_data_billing(
- self,
- payment_method_data_billing: Option<api::Address>,
- ) -> Self {
- // Unify the billing details with `payment_method_data.billing_details`
- let unified_payment_method_billing = payment_method_data_billing
- .map(|payment_method_data_billing| {
- payment_method_data_billing.unify_address(self.get_payment_method_billing())
- })
- .or(self.get_payment_method_billing().cloned());
-
- Self {
- shipping: self.shipping,
- billing: self.billing,
- unified_payment_method_billing,
- payment_method_billing: self.payment_method_billing,
- }
- }
-
- pub fn get_request_payment_method_billing(&self) -> Option<&api::Address> {
- self.payment_method_billing.as_ref()
- }
-
- pub fn get_payment_billing(&self) -> Option<&api::Address> {
- self.billing.as_ref()
- }
- }
-}
-
#[derive(Clone)]
pub struct MandateConnectorDetails {
pub connector: String,
@@ -2520,7 +2440,8 @@ where
pub creds_identifier: Option<String>,
pub pm_token: Option<String>,
pub connector_customer_id: Option<String>,
- pub recurring_mandate_payment_data: Option<RecurringMandatePaymentData>,
+ pub recurring_mandate_payment_data:
+ Option<hyperswitch_domain_models::router_data::RecurringMandatePaymentData>,
pub ephemeral_key: Option<ephemeral_key::EphemeralKey>,
pub redirect_response: Option<api_models::payments::RedirectResponse>,
pub surcharge_details: Option<types::SurchargeDetails>,
@@ -2568,13 +2489,6 @@ pub struct IncrementalAuthorizationDetails {
pub authorization_id: Option<String>,
}
-#[derive(Debug, Default, Clone)]
-pub struct RecurringMandatePaymentData {
- pub payment_method_type: Option<storage_enums::PaymentMethodType>, //required for making recurring payment using saved payment method through stripe
- pub original_payment_authorized_amount: Option<i64>,
- pub original_payment_authorized_currency: Option<storage_enums::Currency>,
-}
-
#[derive(Debug, Default, Clone)]
pub struct CustomerDetails {
pub customer_id: Option<String>,
@@ -3506,7 +3420,7 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
},
));
payment_data.recurring_mandate_payment_data =
- Some(RecurringMandatePaymentData {
+ Some(hyperswitch_domain_models::router_data::RecurringMandatePaymentData {
payment_method_type: mandate_reference_record
.payment_method_type,
original_payment_authorized_amount: mandate_reference_record
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index a770454b20..75bbb5bda8 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -212,7 +212,14 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
}
}
-impl types::PaymentsAuthorizeRouterData {
+pub trait RouterDataAuthorize {
+ fn decide_authentication_type(&mut self);
+
+ /// to decide if we need to proceed with authorize or not, Eg: If any of the pretask returns `redirection_response` then we should not proceed with authorize call
+ fn should_proceed_with_authorize(&self) -> bool;
+}
+
+impl RouterDataAuthorize for types::PaymentsAuthorizeRouterData {
fn decide_authentication_type(&mut self) {
if self.auth_type == diesel_models::enums::AuthenticationType::ThreeDs
&& !self.request.enrolled_for_3ds
diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs
index d1e2e4b0ab..51627e2d68 100644
--- a/crates/router/src/core/payments/flows/psync_flow.rs
+++ b/crates/router/src/core/payments/flows/psync_flow.rs
@@ -145,9 +145,31 @@ impl Feature<api::PSync, types::PaymentsSyncData>
}
}
-impl types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData> {
+#[async_trait]
+pub trait RouterDataPSync
+where
+ Self: Sized,
+{
async fn execute_connector_processing_step_for_each_capture(
- mut self,
+ &self,
+ _state: &AppState,
+ _pending_connector_capture_id_list: Vec<String>,
+ _call_connector_action: payments::CallConnectorAction,
+ _connector_integration: services::BoxedConnectorIntegration<
+ '_,
+ api::PSync,
+ types::PaymentsSyncData,
+ types::PaymentsResponseData,
+ >,
+ ) -> RouterResult<Self>;
+}
+
+#[async_trait]
+impl RouterDataPSync
+ for types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData>
+{
+ async fn execute_connector_processing_step_for_each_capture(
+ &self,
state: &AppState,
pending_connector_capture_id_list: Vec<String>,
call_connector_action: payments::CallConnectorAction,
@@ -164,7 +186,7 @@ impl types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsRespo
let resp = services::execute_connector_processing_step(
state,
connector_integration.clone(),
- &self,
+ self,
call_connector_action.clone(),
None,
)
@@ -174,12 +196,15 @@ impl types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsRespo
} else {
// in trigger, call connector for every capture_id
for connector_capture_id in pending_connector_capture_id_list {
- self.request.connector_transaction_id =
+ // TEMPORARY FIX: remove the clone on router data after removing this function as an impl on trait RouterDataPSync
+ // TRACKING ISSUE: https://github.com/juspay/hyperswitch/issues/4644
+ let mut cloned_router_data = self.clone();
+ cloned_router_data.request.connector_transaction_id =
types::ResponseId::ConnectorTransactionId(connector_capture_id.clone());
let resp = services::execute_connector_processing_step(
state,
connector_integration.clone(),
- &self,
+ &cloned_router_data,
call_connector_action.clone(),
None,
)
@@ -201,10 +226,12 @@ impl types::RouterData<api::PSync, types::PaymentsSyncData, types::PaymentsRespo
_ => Err(ApiErrorResponse::PreconditionFailed { message: "Response type must be PaymentsResponseData::MultipleCaptureResponse for payment sync".into() })?,
};
}
- self.response = Ok(types::PaymentsResponseData::MultipleCaptureResponse {
- capture_sync_response_list: capture_sync_response_map,
- });
- Ok(self)
+ let mut cloned_router_data = self.clone();
+ cloned_router_data.response =
+ Ok(types::PaymentsResponseData::MultipleCaptureResponse {
+ capture_sync_response_list: capture_sync_response_map,
+ });
+ Ok(cloned_router_data)
}
}
}
diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs
index e0837be251..2eb0c921bb 100644
--- a/crates/router/src/core/payments/flows/session_flow.rs
+++ b/crates/router/src/core/payments/flows/session_flow.rs
@@ -642,8 +642,24 @@ fn log_session_response_if_error(
.map(|res| res.as_ref().map_err(|error| logger::error!(?error)));
}
-impl types::PaymentsSessionRouterData {
- pub async fn decide_flow<'a, 'b>(
+#[async_trait]
+pub trait RouterDataSession
+where
+ Self: Sized,
+{
+ async fn decide_flow<'a, 'b>(
+ &'b self,
+ state: &'a routes::AppState,
+ connector: &api::ConnectorData,
+ _confirm: Option<bool>,
+ call_connector_action: payments::CallConnectorAction,
+ business_profile: &storage::business_profile::BusinessProfile,
+ ) -> RouterResult<Self>;
+}
+
+#[async_trait]
+impl RouterDataSession for types::PaymentsSessionRouterData {
+ async fn decide_flow<'a, 'b>(
&'b self,
state: &'a routes::AppState,
connector: &api::ConnectorData,
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index b4b1b09c3f..5723c7f8b9 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -48,7 +48,6 @@ use crate::{
routes::{metrics, payment_methods as payment_methods_handler, AppState},
services,
types::{
- self as core_types,
api::{self, admin, enums as api_enums, MandateValidationFieldsExt},
domain::{
self,
@@ -58,7 +57,8 @@ use crate::{
self, enums as storage_enums, ephemeral_key, CardTokenData, CustomerUpdate::Update,
},
transformers::{ForeignFrom, ForeignTryFrom},
- ErrorResponse, MandateReference, RouterData,
+ AdditionalPaymentMethodConnectorResponse, ErrorResponse, MandateReference,
+ RecurringMandatePaymentData, RouterData,
},
utils::{
self,
@@ -665,7 +665,7 @@ pub async fn get_token_for_recurring_mandate(
Ok(MandateGenericData {
token: Some(token),
payment_method: payment_method.payment_method,
- recurring_mandate_payment_data: Some(payments::RecurringMandatePaymentData {
+ recurring_mandate_payment_data: Some(RecurringMandatePaymentData {
payment_method_type,
original_payment_authorized_amount,
original_payment_authorized_currency,
@@ -679,7 +679,7 @@ pub async fn get_token_for_recurring_mandate(
Ok(MandateGenericData {
token: None,
payment_method: payment_method.payment_method,
- recurring_mandate_payment_data: Some(payments::RecurringMandatePaymentData {
+ recurring_mandate_payment_data: Some(RecurringMandatePaymentData {
payment_method_type,
original_payment_authorized_amount,
original_payment_authorized_currency,
@@ -4198,7 +4198,7 @@ pub fn validate_session_expiry(session_expiry: u32) -> Result<(), errors::ApiErr
pub fn add_connector_response_to_additional_payment_data(
additional_payment_data: api_models::payments::AdditionalPaymentData,
- connector_response_payment_method_data: core_types::AdditionalPaymentMethodConnectorResponse,
+ connector_response_payment_method_data: AdditionalPaymentMethodConnectorResponse,
) -> api_models::payments::AdditionalPaymentData {
match (
&additional_payment_data,
@@ -4206,7 +4206,7 @@ pub fn add_connector_response_to_additional_payment_data(
) {
(
api_models::payments::AdditionalPaymentData::Card(additional_card_data),
- core_types::AdditionalPaymentMethodConnectorResponse::Card {
+ AdditionalPaymentMethodConnectorResponse::Card {
authentication_data,
payment_checks,
},
@@ -4223,7 +4223,7 @@ pub fn add_connector_response_to_additional_payment_data(
pub fn update_additional_payment_data_with_connector_response_pm_data(
additional_payment_data: Option<serde_json::Value>,
- connector_response_pm_data: Option<core_types::AdditionalPaymentMethodConnectorResponse>,
+ connector_response_pm_data: Option<AdditionalPaymentMethodConnectorResponse>,
) -> RouterResult<Option<serde_json::Value>> {
let parsed_additional_payment_method_data = additional_payment_data
.as_ref()
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index d41bfcf66d..081dac14df 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -111,7 +111,7 @@ where
.to_owned()
.get_required_value("payment_token")?;
let token = match tokens {
- types::PaymentMethodToken::Token(connector_token) => connector_token,
+ types::PaymentMethodToken::Token(connector_token) => connector_token.expose(),
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ApiErrorResponse::NotSupported {
message: "Apple Pay Decrypt token is not supported".to_string(),
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 41ce77a4de..42d30da766 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -7,7 +7,7 @@ use common_enums::RequestIncrementalAuthorization;
use common_utils::{consts::X_HS_LATENCY, fp_utils};
use diesel_models::ephemeral_key;
use error_stack::{report, ResultExt};
-use masking::Maskable;
+use masking::{Maskable, Secret};
use router_env::{instrument, tracing};
use super::{flows::Feature, types::AuthenticationData, PaymentData};
@@ -156,7 +156,9 @@ where
session_token: None,
reference_id: None,
payment_method_status: payment_data.payment_method_info.map(|info| info.status),
- payment_method_token: payment_data.pm_token.map(types::PaymentMethodToken::Token),
+ payment_method_token: payment_data
+ .pm_token
+ .map(|token| types::PaymentMethodToken::Token(Secret::new(token))),
connector_customer: payment_data.connector_customer_id,
recurring_mandate_payment_data: payment_data.recurring_mandate_payment_data,
connector_request_reference_id: core_utils::get_connector_request_reference_id(
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 6f0d099896..6571546448 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -8,13 +8,14 @@ use common_enums::{IntentStatus, RequestIncrementalAuthorization};
use common_utils::{crypto::Encryptable, pii::Email};
use common_utils::{errors::CustomResult, ext_traits::AsyncExt};
use error_stack::{report, ResultExt};
+use hyperswitch_domain_models::{payment_address::PaymentAddress, router_data::ErrorResponse};
#[cfg(feature = "payouts")]
use masking::PeekInterface;
use maud::{html, PreEscaped};
use router_env::{instrument, tracing};
use uuid::Uuid;
-use super::payments::{helpers, PaymentAddress};
+use super::payments::helpers;
#[cfg(feature = "payouts")]
use super::payouts::PayoutData;
#[cfg(feature = "payouts")]
@@ -28,7 +29,7 @@ use crate::{
types::{
self, domain,
storage::{self, enums},
- ErrorResponse, PollConfig,
+ PollConfig,
},
utils::{generate_id, generate_uuid, OptionExt, ValueExt},
};
diff --git a/crates/router/src/core/verify_connector.rs b/crates/router/src/core/verify_connector.rs
index 17cedd1e2d..8a8b0a14f7 100644
--- a/crates/router/src/core/verify_connector.rs
+++ b/crates/router/src/core/verify_connector.rs
@@ -6,8 +6,11 @@ use crate::{
core::errors,
services,
types::{
- api,
- api::verify_connector::{self as types, VerifyConnector},
+ api::{
+ self,
+ verify_connector::{self as types, VerifyConnector},
+ },
+ transformers::ForeignInto,
},
utils::verify_connector as utils,
AppState,
@@ -38,7 +41,7 @@ pub async fn verify_connector_credentials(
&state,
types::VerifyConnectorData {
connector: *boxed_connector.connector,
- connector_auth: req.connector_account_details.into(),
+ connector_auth: req.connector_account_details.foreign_into(),
card_details,
},
)
@@ -48,7 +51,7 @@ pub async fn verify_connector_credentials(
&state,
types::VerifyConnectorData {
connector: *boxed_connector.connector,
- connector_auth: req.connector_account_details.into(),
+ connector_auth: req.connector_account_details.foreign_into(),
card_details,
},
)
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index bffa3eaf8f..886e7c65fd 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -26,11 +26,19 @@ pub use common_utils::request::RequestContent;
use common_utils::{pii, pii::Email};
use error_stack::ResultExt;
use hyperswitch_domain_models::mandates::{CustomerAcceptance, MandateData};
+pub use hyperswitch_domain_models::{
+ payment_address::PaymentAddress,
+ router_data::{
+ AccessToken, AdditionalPaymentMethodConnectorResponse, ApplePayCryptogramData,
+ ApplePayPredecryptData, ConnectorAuthType, ConnectorResponseData, ErrorResponse,
+ PaymentMethodBalance, PaymentMethodToken, RecurringMandatePaymentData, RouterData,
+ },
+};
use masking::Secret;
use serde::Serialize;
use self::storage::enums as storage_enums;
-pub use crate::core::payments::{payment_address::PaymentAddress, CustomerDetails};
+pub use crate::core::payments::CustomerDetails;
#[cfg(feature = "payouts")]
use crate::{
connector::utils::missing_field_err,
@@ -40,7 +48,7 @@ use crate::{
consts,
core::{
errors::{self},
- payments::{types, PaymentData, RecurringMandatePaymentData},
+ payments::{types, PaymentData},
},
services,
types::{transformers::ForeignFrom, types::AuthenticationData},
@@ -267,125 +275,6 @@ pub type PayoutsRouterData<F> = RouterData<F, PayoutsData, PayoutsResponseData>;
pub type PayoutsResponseRouterData<F, R> =
ResponseRouterData<F, R, PayoutsData, PayoutsResponseData>;
-#[derive(Debug, Clone)]
-pub struct RouterData<Flow, Request, Response> {
- pub flow: PhantomData<Flow>,
- pub merchant_id: String,
- pub customer_id: Option<String>,
- pub connector_customer: Option<String>,
- pub connector: String,
- pub payment_id: String,
- pub attempt_id: String,
- pub status: storage_enums::AttemptStatus,
- pub payment_method: storage_enums::PaymentMethod,
- pub connector_auth_type: ConnectorAuthType,
- pub description: Option<String>,
- pub return_url: Option<String>,
- pub address: PaymentAddress,
- pub auth_type: storage_enums::AuthenticationType,
- pub connector_meta_data: Option<pii::SecretSerdeValue>,
- pub amount_captured: Option<i64>,
- pub access_token: Option<AccessToken>,
- pub session_token: Option<String>,
- pub reference_id: Option<String>,
- pub payment_method_token: Option<PaymentMethodToken>,
- pub recurring_mandate_payment_data: Option<RecurringMandatePaymentData>,
- pub preprocessing_id: Option<String>,
- /// This is the balance amount for gift cards or voucher
- pub payment_method_balance: Option<PaymentMethodBalance>,
-
- ///for switching between two different versions of the same connector
- pub connector_api_version: Option<String>,
-
- /// Contains flow-specific data required to construct a request and send it to the connector.
- pub request: Request,
-
- /// Contains flow-specific data that the connector responds with.
- pub response: Result<Response, ErrorResponse>,
-
- /// Contains a reference ID that should be sent in the connector request
- pub connector_request_reference_id: String,
-
- #[cfg(feature = "payouts")]
- /// Contains payout method data
- pub payout_method_data: Option<api::PayoutMethodData>,
-
- #[cfg(feature = "payouts")]
- /// Contains payout's quote ID
- pub quote_id: Option<String>,
-
- pub test_mode: Option<bool>,
- pub connector_http_status_code: Option<u16>,
- pub external_latency: Option<u128>,
- /// Contains apple pay flow type simplified or manual
- pub apple_pay_flow: Option<storage_enums::ApplePayFlow>,
-
- pub frm_metadata: Option<serde_json::Value>,
-
- pub dispute_id: Option<String>,
- pub refund_id: Option<String>,
-
- /// This field is used to store various data regarding the response from connector
- pub connector_response: Option<ConnectorResponseData>,
- pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
-}
-
-#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
-pub enum AdditionalPaymentMethodConnectorResponse {
- Card {
- /// Details regarding the authentication details of the connector, if this is a 3ds payment.
- authentication_data: Option<serde_json::Value>,
- /// Various payment checks that are done for a payment
- payment_checks: Option<serde_json::Value>,
- },
-}
-
-#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
-pub struct ConnectorResponseData {
- pub additional_payment_method_data: Option<AdditionalPaymentMethodConnectorResponse>,
-}
-
-impl ConnectorResponseData {
- pub fn with_additional_payment_method_data(
- additional_payment_method_data: AdditionalPaymentMethodConnectorResponse,
- ) -> Self {
- Self {
- additional_payment_method_data: Some(additional_payment_method_data),
- }
- }
-}
-
-#[derive(Debug, Clone, serde::Deserialize)]
-pub enum PaymentMethodToken {
- Token(String),
- ApplePayDecrypt(Box<ApplePayPredecryptData>),
-}
-
-#[derive(Debug, Clone, serde::Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ApplePayPredecryptData {
- pub application_primary_account_number: Secret<String>,
- pub application_expiration_date: String,
- pub currency_code: String,
- pub transaction_amount: i64,
- pub device_manufacturer_identifier: Secret<String>,
- pub payment_data_type: Secret<String>,
- pub payment_data: ApplePayCryptogramData,
-}
-
-#[derive(Debug, Clone, serde::Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ApplePayCryptogramData {
- pub online_payment_cryptogram: Secret<String>,
- pub eci_indicator: Option<String>,
-}
-
-#[derive(Debug, Clone)]
-pub struct PaymentMethodBalance {
- pub amount: i64,
- pub currency: storage_enums::Currency,
-}
-
#[cfg(feature = "payouts")]
#[derive(Debug, Clone)]
pub struct PayoutsData {
@@ -876,12 +765,6 @@ pub struct AddAccessTokenResult {
pub connector_supports_access_token: bool,
}
-#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
-pub struct AccessToken {
- pub token: Secret<String>,
- pub expires: i64,
-}
-
#[derive(serde::Serialize, Debug, Clone)]
pub struct MandateReference {
pub connector_mandate_id: Option<String>,
@@ -1225,42 +1108,8 @@ pub struct MandateRevokeResponseData {
pub mandate_status: MandateStatus,
}
-// Different patterns of authentication.
-#[derive(Default, Debug, Clone, serde::Deserialize, serde::Serialize)]
-#[serde(tag = "auth_type")]
-pub enum ConnectorAuthType {
- TemporaryAuth,
- HeaderKey {
- api_key: Secret<String>,
- },
- BodyKey {
- api_key: Secret<String>,
- key1: Secret<String>,
- },
- SignatureKey {
- api_key: Secret<String>,
- key1: Secret<String>,
- api_secret: Secret<String>,
- },
- MultiAuthKey {
- api_key: Secret<String>,
- key1: Secret<String>,
- api_secret: Secret<String>,
- key2: Secret<String>,
- },
- CurrencyAuthKey {
- auth_key_map: HashMap<storage_enums::Currency, pii::SecretSerdeValue>,
- },
- CertificateAuth {
- certificate: Secret<String>,
- private_key: Secret<String>,
- },
- #[default]
- NoKey,
-}
-
-impl From<api_models::admin::ConnectorAuthType> for ConnectorAuthType {
- fn from(value: api_models::admin::ConnectorAuthType) -> Self {
+impl ForeignFrom<api_models::admin::ConnectorAuthType> for ConnectorAuthType {
+ fn foreign_from(value: api_models::admin::ConnectorAuthType) -> Self {
match value {
api_models::admin::ConnectorAuthType::TemporaryAuth => Self::TemporaryAuth,
api_models::admin::ConnectorAuthType::HeaderKey { api_key } => {
@@ -1357,35 +1206,6 @@ pub struct Response {
pub status_code: u16,
}
-#[derive(Clone, Debug, serde::Serialize)]
-pub struct ErrorResponse {
- pub code: String,
- pub message: String,
- pub reason: Option<String>,
- pub status_code: u16,
- pub attempt_status: Option<storage_enums::AttemptStatus>,
- pub connector_transaction_id: Option<String>,
-}
-
-impl ErrorResponse {
- pub fn get_not_implemented() -> Self {
- Self {
- code: errors::ApiErrorResponse::NotImplemented {
- message: errors::api_error_response::NotImplementedMessage::Default,
- }
- .error_code(),
- message: errors::ApiErrorResponse::NotImplemented {
- message: errors::api_error_response::NotImplementedMessage::Default,
- }
- .error_message(),
- reason: None,
- status_code: http::StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
- attempt_status: None,
- connector_transaction_id: None,
- }
- }
-}
-
impl TryFrom<ConnectorAuthType> for AccessTokenRequestData {
type Error = errors::ApiErrorResponse;
fn try_from(connector_auth: ConnectorAuthType) -> Result<Self, Self::Error> {
@@ -1430,12 +1250,6 @@ impl From<errors::ApiErrorResponse> for ErrorResponse {
}
}
-impl Default for ErrorResponse {
- fn default() -> Self {
- Self::from(errors::ApiErrorResponse::InternalServerError)
- }
-}
-
impl From<&&mut PaymentsAuthorizeRouterData> for AuthorizeSessionTokenData {
fn from(data: &&mut PaymentsAuthorizeRouterData) -> Self {
Self {
@@ -1515,10 +1329,10 @@ impl From<&SetupMandateRouterData> for PaymentsAuthorizeData {
}
}
-impl<F1, F2, T1, T2> From<(&RouterData<F1, T1, PaymentsResponseData>, T2)>
+impl<F1, F2, T1, T2> ForeignFrom<(&RouterData<F1, T1, PaymentsResponseData>, T2)>
for RouterData<F2, T2, PaymentsResponseData>
{
- fn from(item: (&RouterData<F1, T1, PaymentsResponseData>, T2)) -> Self {
+ fn foreign_from(item: (&RouterData<F1, T1, PaymentsResponseData>, T2)) -> Self {
let data = item.0;
let request = item.1;
Self {
@@ -1568,12 +1382,12 @@ impl<F1, F2, T1, T2> From<(&RouterData<F1, T1, PaymentsResponseData>, T2)>
#[cfg(feature = "payouts")]
impl<F1, F2>
- From<(
+ ForeignFrom<(
&&mut RouterData<F1, PayoutsData, PayoutsResponseData>,
PayoutsData,
)> for RouterData<F2, PayoutsData, PayoutsResponseData>
{
- fn from(
+ fn foreign_from(
item: (
&&mut RouterData<F1, PayoutsData, PayoutsResponseData>,
PayoutsData,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index c19fdb26ad..cd1a44a702 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -529,9 +529,10 @@ pub trait ConnectorActions: Connector {
access_token: info.clone().and_then(|a| a.access_token),
session_token: None,
reference_id: None,
- payment_method_token: info
- .clone()
- .and_then(|a| a.payment_method_token.map(types::PaymentMethodToken::Token)),
+ payment_method_token: info.clone().and_then(|a| {
+ a.payment_method_token
+ .map(|token| types::PaymentMethodToken::Token(Secret::new(token)))
+ }),
connector_customer: info.clone().and_then(|a| a.connector_customer),
recurring_mandate_payment_data: None,