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): add support for multiple `merchant_connector_account` (#2655)

Narayan Bhat5988d8d42605
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index af6a8aa446..45c0d3c658 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -446,7 +446,17 @@ pub mod payout_routing_algorithm {
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum RoutingAlgorithm {
- Single(api_enums::RoutableConnectors),
+ Single(RoutableConnectorChoice),
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub enum RoutableConnectorChoice {
+ ConnectorName(api_enums::RoutableConnectors),
+ ConnectorId {
+ merchant_connector_id: String,
+ connector: api_enums::RoutableConnectors,
+ },
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -458,13 +468,13 @@ pub enum RoutingAlgorithm {
into = "StraightThroughAlgorithmSerde"
)]
pub enum StraightThroughAlgorithm {
- Single(api_enums::RoutableConnectors),
+ Single(RoutableConnectorChoice),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum StraightThroughAlgorithmInner {
- Single(api_enums::RoutableConnectors),
+ Single(RoutableConnectorChoice),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index f61f6f9a44..c0ec959725 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -2106,6 +2106,9 @@ pub struct PaymentsResponse {
/// Denotes the action(approve or reject) taken by merchant in case of manual review. Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
+
+ /// Identifier of the connector ( merchant connector account ) which was chosen to make the payment
+ pub merchant_connector_id: Option<String>,
}
#[derive(Clone, Debug, serde::Deserialize, ToSchema)]
diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rs
index b9021ae1ce..a3ddbe8906 100644
--- a/crates/data_models/src/payments/payment_attempt.rs
+++ b/crates/data_models/src/payments/payment_attempt.rs
@@ -142,6 +142,7 @@ pub struct PaymentAttempt {
pub connector_response_reference_id: Option<String>,
pub amount_capturable: i64,
pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -201,6 +202,7 @@ pub struct PaymentAttemptNew {
pub multiple_capture_count: Option<i16>,
pub amount_capturable: i64,
pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -226,6 +228,7 @@ pub enum PaymentAttemptUpdate {
straight_through_algorithm: Option<serde_json::Value>,
amount_capturable: Option<i64>,
updated_by: String,
+ merchant_connector_id: Option<String>,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
@@ -251,6 +254,7 @@ pub enum PaymentAttemptUpdate {
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
+ merchant_connector_id: Option<String>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
diff --git a/crates/diesel_models/src/dispute.rs b/crates/diesel_models/src/dispute.rs
index 1e1609491f..9bdac33229 100644
--- a/crates/diesel_models/src/dispute.rs
+++ b/crates/diesel_models/src/dispute.rs
@@ -28,6 +28,7 @@ pub struct DisputeNew {
pub connector: String,
pub evidence: Option<Secret<serde_json::Value>>,
pub profile_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Identifiable, Queryable)]
@@ -57,6 +58,7 @@ pub struct Dispute {
pub connector: String,
pub evidence: Secret<serde_json::Value>,
pub profile_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug)]
diff --git a/crates/diesel_models/src/file.rs b/crates/diesel_models/src/file.rs
index d6efcbbc6a..20150a6928 100644
--- a/crates/diesel_models/src/file.rs
+++ b/crates/diesel_models/src/file.rs
@@ -18,6 +18,7 @@ pub struct FileMetadataNew {
pub available: bool,
pub connector_label: Option<String>,
pub profile_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Identifiable, Queryable)]
@@ -36,6 +37,7 @@ pub struct FileMetadata {
pub created_at: time::PrimitiveDateTime,
pub connector_label: Option<String>,
pub profile_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug)]
@@ -44,7 +46,8 @@ pub enum FileMetadataUpdate {
provider_file_id: Option<String>,
file_upload_provider: Option<common_enums::FileUploadProvider>,
available: bool,
- connector_label: Option<String>,
+ profile_id: Option<String>,
+ merchant_connector_id: Option<String>,
},
}
@@ -54,7 +57,8 @@ pub struct FileMetadataUpdateInternal {
provider_file_id: Option<String>,
file_upload_provider: Option<common_enums::FileUploadProvider>,
available: bool,
- connector_label: Option<String>,
+ profile_id: Option<String>,
+ merchant_connector_id: Option<String>,
}
impl From<FileMetadataUpdate> for FileMetadataUpdateInternal {
@@ -64,12 +68,14 @@ impl From<FileMetadataUpdate> for FileMetadataUpdateInternal {
provider_file_id,
file_upload_provider,
available,
- connector_label,
+ profile_id,
+ merchant_connector_id,
} => Self {
provider_file_id,
file_upload_provider,
available,
- connector_label,
+ profile_id,
+ merchant_connector_id,
},
}
}
diff --git a/crates/diesel_models/src/mandate.rs b/crates/diesel_models/src/mandate.rs
index 0b7f3db51a..cc3474914c 100644
--- a/crates/diesel_models/src/mandate.rs
+++ b/crates/diesel_models/src/mandate.rs
@@ -31,6 +31,7 @@ pub struct Mandate {
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_mandate_ids: Option<pii::SecretSerdeValue>,
pub original_payment_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(
@@ -60,6 +61,7 @@ pub struct MandateNew {
pub metadata: Option<pii::SecretSerdeValue>,
pub connector_mandate_ids: Option<pii::SecretSerdeValue>,
pub original_payment_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug)]
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 7d2033bcbb..8603aee5cb 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -58,6 +58,7 @@ pub struct PaymentAttempt {
pub connector_response_reference_id: Option<String>,
pub amount_capturable: i64,
pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Queryable, Serialize, Deserialize)]
@@ -67,6 +68,7 @@ pub struct PaymentListFilters {
pub status: Vec<storage_enums::IntentStatus>,
pub payment_method: Vec<storage_enums::PaymentMethod>,
}
+
#[derive(
Clone, Debug, Default, Insertable, router_derive::DebugAsDisplay, Serialize, Deserialize,
)]
@@ -117,6 +119,7 @@ pub struct PaymentAttemptNew {
pub multiple_capture_count: Option<i16>,
pub amount_capturable: i64,
pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -142,6 +145,7 @@ pub enum PaymentAttemptUpdate {
straight_through_algorithm: Option<serde_json::Value>,
amount_capturable: Option<i64>,
updated_by: String,
+ merchant_connector_id: Option<String>,
},
AuthenticationTypeUpdate {
authentication_type: storage_enums::AuthenticationType,
@@ -167,6 +171,7 @@ pub enum PaymentAttemptUpdate {
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
+ merchant_connector_id: Option<String>,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
@@ -273,6 +278,7 @@ pub struct PaymentAttemptUpdateInternal {
tax_amount: Option<i64>,
amount_capturable: Option<i64>,
updated_by: String,
+ merchant_connector_id: Option<String>,
}
impl PaymentAttemptUpdate {
@@ -324,6 +330,7 @@ impl PaymentAttemptUpdate {
.amount_capturable
.unwrap_or(source.amount_capturable),
updated_by: pa_update.updated_by,
+ merchant_connector_id: pa_update.merchant_connector_id,
..source
}
}
@@ -394,6 +401,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
surcharge_amount,
tax_amount,
updated_by,
+ merchant_connector_id,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -415,6 +423,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
surcharge_amount,
tax_amount,
updated_by,
+ merchant_connector_id,
..Default::default()
},
PaymentAttemptUpdate::VoidUpdate {
@@ -502,12 +511,14 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
straight_through_algorithm,
amount_capturable,
updated_by,
+ merchant_connector_id,
} => Self {
payment_token,
connector,
straight_through_algorithm,
amount_capturable,
updated_by,
+ merchant_connector_id,
..Default::default()
},
PaymentAttemptUpdate::UnresolvedResponseUpdate {
diff --git a/crates/diesel_models/src/payout_attempt.rs b/crates/diesel_models/src/payout_attempt.rs
index 64ba105511..d87ed5319a 100644
--- a/crates/diesel_models/src/payout_attempt.rs
+++ b/crates/diesel_models/src/payout_attempt.rs
@@ -27,6 +27,7 @@ pub struct PayoutAttempt {
#[serde(with = "common_utils::custom_serde::iso8601")]
pub last_modified_at: PrimitiveDateTime,
pub profile_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
impl Default for PayoutAttempt {
@@ -51,6 +52,7 @@ impl Default for PayoutAttempt {
created_at: now,
last_modified_at: now,
profile_id: None,
+ merchant_connector_id: None,
}
}
}
@@ -88,6 +90,7 @@ pub struct PayoutAttemptNew {
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub last_modified_at: Option<PrimitiveDateTime>,
pub profile_id: Option<String>,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug)]
diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs
index 56adfaf028..73ff34030f 100644
--- a/crates/diesel_models/src/refund.rs
+++ b/crates/diesel_models/src/refund.rs
@@ -38,6 +38,7 @@ pub struct Refund {
pub refund_error_code: Option<String>,
pub profile_id: Option<String>,
pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
}
#[derive(
@@ -79,6 +80,7 @@ pub struct RefundNew {
pub refund_reason: Option<String>,
pub profile_id: Option<String>,
pub updated_by: String,
+ pub merchant_connector_id: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 2f3e7d345a..6c1b13bacf 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -246,6 +246,8 @@ diesel::table! {
evidence -> Jsonb,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
+ #[max_length = 32]
+ merchant_connector_id -> Nullable<Varchar>,
}
}
@@ -293,6 +295,8 @@ diesel::table! {
connector_label -> Nullable<Varchar>,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
+ #[max_length = 32]
+ merchant_connector_id -> Nullable<Varchar>,
}
}
@@ -404,6 +408,8 @@ diesel::table! {
connector_mandate_ids -> Nullable<Jsonb>,
#[max_length = 64]
original_payment_id -> Nullable<Varchar>,
+ #[max_length = 32]
+ merchant_connector_id -> Nullable<Varchar>,
}
}
@@ -561,6 +567,8 @@ diesel::table! {
amount_capturable -> Int8,
#[max_length = 32]
updated_by -> Varchar,
+ #[max_length = 32]
+ merchant_connector_id -> Nullable<Varchar>,
}
}
@@ -721,6 +729,8 @@ diesel::table! {
last_modified_at -> Timestamp,
#[max_length = 64]
profile_id -> Nullable<Varchar>,
+ #[max_length = 32]
+ merchant_connector_id -> Nullable<Varchar>,
}
}
@@ -828,6 +838,8 @@ diesel::table! {
profile_id -> Nullable<Varchar>,
#[max_length = 32]
updated_by -> Varchar,
+ #[max_length = 32]
+ merchant_connector_id -> Nullable<Varchar>,
}
}
diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rs
index 1cda32ffcc..4d9632f888 100644
--- a/crates/router/src/compatibility/stripe/payment_intents/types.rs
+++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs
@@ -281,7 +281,11 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
});
let routing = routable_connector
- .map(crate::types::api::RoutingAlgorithm::Single)
+ .map(|connector| {
+ crate::types::api::RoutingAlgorithm::Single(
+ api_models::admin::RoutableConnectorChoice::ConnectorName(connector),
+ )
+ })
.map(|r| {
serde_json::to_value(r)
.into_report()
diff --git a/crates/router/src/compatibility/stripe/setup_intents/types.rs b/crates/router/src/compatibility/stripe/setup_intents/types.rs
index 71bf58f651..661a08e090 100644
--- a/crates/router/src/compatibility/stripe/setup_intents/types.rs
+++ b/crates/router/src/compatibility/stripe/setup_intents/types.rs
@@ -184,7 +184,11 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
});
let routing = routable_connector
- .map(api_types::RoutingAlgorithm::Single)
+ .map(|connector| {
+ crate::types::api::RoutingAlgorithm::Single(
+ api_models::admin::RoutableConnectorChoice::ConnectorName(connector),
+ )
+ })
.map(|r| {
serde_json::to_value(r)
.into_report()
diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs
index aaf12acd0a..535d004e90 100644
--- a/crates/router/src/core/disputes.rs
+++ b/crates/router/src/core/disputes.rs
@@ -108,6 +108,7 @@ pub async fn accept_dispute(
&state.conf.connectors,
&dispute.connector,
api::GetToken::Connector,
+ dispute.merchant_connector_id.clone(),
)?;
let connector_integration: services::BoxedConnectorIntegration<
'_,
@@ -220,7 +221,9 @@ pub async fn submit_evidence(
&state.conf.connectors,
&dispute.connector,
api::GetToken::Connector,
+ dispute.merchant_connector_id.clone(),
)?;
+
let connector_integration: services::BoxedConnectorIntegration<
'_,
api::Evidence,
diff --git a/crates/router/src/core/files.rs b/crates/router/src/core/files.rs
index 83bfef69e5..13c4d3dfdf 100644
--- a/crates/router/src/core/files.rs
+++ b/crates/router/src/core/files.rs
@@ -44,14 +44,16 @@ pub async fn files_create_core(
available: false,
connector_label: None,
profile_id: None,
+ merchant_connector_id: None,
};
+
let file_metadata_object = state
.store
.insert_file_metadata(file_new)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to insert file_metadata")?;
- let (provider_file_id, file_upload_provider, connector_label) =
+ let (provider_file_id, file_upload_provider, profile_id, merchant_connector_id) =
helpers::upload_and_get_provider_provider_file_id_profile_id(
&state,
&merchant_account,
@@ -60,12 +62,14 @@ pub async fn files_create_core(
file_key.clone(),
)
.await?;
- //Update file metadata
+
+ // Update file metadata
let update_file_metadata = diesel_models::file::FileMetadataUpdate::Update {
provider_file_id: Some(provider_file_id),
file_upload_provider: Some(file_upload_provider),
available: true,
- connector_label,
+ profile_id,
+ merchant_connector_id,
};
state
.store
diff --git a/crates/router/src/core/files/helpers.rs b/crates/router/src/core/files/helpers.rs
index 7d7e694b42..818067207f 100644
--- a/crates/router/src/core/files/helpers.rs
+++ b/crates/router/src/core/files/helpers.rs
@@ -79,11 +79,14 @@ pub async fn validate_file_upload(
.to_not_found_response(errors::ApiErrorResponse::DisputeNotFound {
dispute_id: dispute_id.to_string(),
})?;
+ // Connector is not called for validating the file, connector_id can be passed as None safely
let connector_data = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
&dispute.connector,
api::GetToken::Connector,
+ None,
)?;
+
let validation = connector_data.connector.validate_file_upload(
create_file_request.purpose,
create_file_request.file_size,
@@ -162,6 +165,7 @@ pub async fn retrieve_file_from_connector(
&state.conf.connectors,
connector,
api::GetToken::Connector,
+ file_metadata.merchant_connector_id.clone(),
)?;
let connector_integration: services::BoxedConnectorIntegration<
'_,
@@ -271,6 +275,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id(
String,
api_models::enums::FileUploadProvider,
Option<String>,
+ Option<String>,
),
errors::ApiErrorResponse,
> {
@@ -289,6 +294,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id(
&state.conf.connectors,
&dispute.connector,
api::GetToken::Connector,
+ dispute.merchant_connector_id.clone(),
)?;
if connector_data.connector_name.supports_file_storage_module() {
let payment_intent = state
@@ -339,6 +345,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id(
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while calling upload file connector api")?;
+
let upload_file_response = response.response.map_err(|err| {
errors::ApiErrorResponse::ExternalConnectorError {
code: err.code,
@@ -354,6 +361,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id(
&connector_data.connector_name,
)?,
payment_intent.profile_id,
+ payment_attempt.merchant_connector_id,
))
} else {
upload_file(
@@ -367,6 +375,7 @@ pub async fn upload_and_get_provider_provider_file_id_profile_id(
file_key,
api_models::enums::FileUploadProvider::Router,
None,
+ None,
))
}
}
diff --git a/crates/router/src/core/mandate.rs b/crates/router/src/core/mandate.rs
index a1aa1fa9eb..55de11549a 100644
--- a/crates/router/src/core/mandate.rs
+++ b/crates/router/src/core/mandate.rs
@@ -143,6 +143,7 @@ pub async fn mandate_procedure<F, FData>(
mut resp: types::RouterData<F, FData, types::PaymentsResponseData>,
maybe_customer: &Option<domain::Customer>,
pm_id: Option<String>,
+ merchant_connector_id: Option<String>,
) -> errors::RouterResult<types::RouterData<F, FData, types::PaymentsResponseData>>
where
FData: MandateBehaviour,
@@ -228,6 +229,7 @@ where
network_txn_id,
get_insensitive_payment_method_data_if_exists(&resp),
mandate_reference,
+ merchant_connector_id,
)? {
let connector = new_mandate_data.connector.clone();
logger::debug!("{:?}", new_mandate_data);
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 20a571cd94..7d6cf04dd9 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -381,10 +381,13 @@ pub trait PaymentRedirectFlow<Ctx: PaymentMethodRetrieve>: Sync {
field_name: "payment_id",
})?;
+ // This connector data is ephemeral, the call payment flow will get new connector data
+ // with merchant account details, so the connector_id can be safely set to None here
let connector_data = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
&connector,
api::GetToken::Connector,
+ None,
)?;
let flow_type = connector_data
@@ -605,19 +608,12 @@ where
{
let stime_connector = Instant::now();
- let pm_data = payment_data.clone();
-
- let connector_name = pm_data
- .payment_attempt
- .connector
- .as_ref()
- .get_required_value("connector")?;
-
let merchant_connector_account = construct_profile_id_and_get_mca(
state,
merchant_account,
payment_data,
- connector_name,
+ &connector.connector_name.to_string(),
+ connector.merchant_connector_id.as_ref(),
key_store,
false,
)
@@ -829,10 +825,15 @@ where
merchant_account,
&mut payment_data,
&session_connector_data.connector.connector_name.to_string(),
+ session_connector_data
+ .connector
+ .merchant_connector_id
+ .as_ref(),
key_store,
false,
)
.await?;
+
payment_data.surcharge_details = session_surcharge_metadata
.as_ref()
.and_then(|surcharge_metadata| {
@@ -937,6 +938,7 @@ where
&state.conf.connectors,
&connector_name,
api::GetToken::Connector,
+ merchant_connector_account.get_mca_id(),
)?;
let connector_label = super::utils::get_connector_label(
@@ -946,7 +948,9 @@ where
&connector_name,
);
- let connector_label = if let Some(connector_label) = connector_label {
+ let connector_label = if let Some(connector_label) =
+ merchant_connector_account.get_mca_id().or(connector_label)
+ {
connector_label
} else {
let profile_id = utils::get_profile_id_from_business_details(
@@ -1092,7 +1096,8 @@ pub async fn construct_profile_id_and_get_mca<'a, F>(
state: &'a AppState,
merchant_account: &domain::MerchantAccount,
payment_data: &mut PaymentData<F>,
- connector_id: &str,
+ connector_name: &str,
+ merchant_connector_id: Option<&String>,
key_store: &domain::MerchantKeyStore,
should_validate: bool,
) -> RouterResult<helpers::MerchantConnectorAccountType>
@@ -1117,7 +1122,8 @@ where
payment_data.creds_identifier.to_owned(),
key_store,
&profile_id,
- connector_id,
+ connector_name,
+ merchant_connector_id,
)
.await?;
@@ -1446,6 +1452,12 @@ pub struct PaymentAddress {
pub billing: Option<api::Address>,
}
+#[derive(Clone)]
+pub struct MandateConnectorDetails {
+ pub connector: String,
+ pub merchant_connector_id: Option<String>,
+}
+
#[derive(Clone)]
pub struct PaymentData<F>
where
@@ -1458,7 +1470,7 @@ where
pub connector_response: storage::ConnectorResponse,
pub amount: api::Amount,
pub mandate_id: Option<api_models::payments::MandateIds>,
- pub mandate_connector: Option<String>,
+ pub mandate_connector: Option<MandateConnectorDetails>,
pub currency: storage_enums::Currency,
pub setup_mandate: Option<MandateData>,
pub address: PaymentAddress,
@@ -1883,11 +1895,16 @@ pub fn connector_selection<F>(
where
F: Send + Clone,
{
+ // If the connector was already decided previously, use the same connector
+ // This is in case of flows like payments_sync, payments_cancel where the successive operations
+ // with the connector have to be made using the same connector account.
if let Some(ref connector_name) = payment_data.payment_attempt.connector {
+ // Connector was already decided previously, use the same connector
let connector_data = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
connector_name,
api::GetToken::Connector,
+ payment_data.payment_attempt.merchant_connector_id.clone(),
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("invalid connector name received in payment attempt")?;
@@ -1895,30 +1912,44 @@ where
return Ok(api::ConnectorCallType::Single(connector_data));
}
- let mut routing_data = storage::RoutingData {
- routed_through: payment_data.payment_attempt.connector.clone(),
- algorithm: payment_data
- .payment_attempt
- .straight_through_algorithm
- .clone()
- .map(|val| val.parse_value("RoutingAlgorithm"))
- .transpose()
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Invalid straight through algorithm format in payment attempt")?,
- };
+ let request_straight_through = request_straight_through
+ .map(|val| val.parse_value::<api::StraightThroughAlgorithm>("StraightThroughAlgorithm"))
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Invalid straight through routing rules format")
+ .transpose();
- let request_straight_through: Option<api::StraightThroughAlgorithm> = request_straight_through
- .map(|val| val.parse_value("StraightThroughAlgorithm"))
+ let payment_routing_algorithm = request_straight_through.or(payment_data
+ .payment_attempt
+ .straight_through_algorithm
+ .clone()
+ .map(|val| val.parse_value::<api::StraightThroughAlgorithm>("RoutingAlgorithm"))
.transpose()
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Invalid straight through routing rules format")?;
+ .attach_printable("Invalid straight through algorithm format in payment attempt")
+ .transpose());
- let decided_connector = decide_connector(
- state,
- merchant_account,
- request_straight_through,
- &mut routing_data,
- )?;
+ let routing_algorithm = payment_routing_algorithm
+ .or(merchant_account
+ .routing_algorithm
+ .clone()
+ .map(|merchant_routing_algorithm| {
+ merchant_routing_algorithm
+ .parse_value::<api::StraightThroughAlgorithm>("RoutingAlgorithm")
+ .change_context(errors::ApiErrorResponse::InternalServerError) // Deserialization failed
+ .attach_printable("Unable to deserialize merchant routing algorithm")
+ }))
+ .get_required_value("RoutingAlgorithm")
+ .change_context(errors::ApiErrorResponse::PreconditionFailed {
+ message: "no routing algorithm has been configured".to_string(),
+ })??;
+
+ let mut routing_data = storage::RoutingData {
+ routed_through: payment_data.payment_attempt.connector.clone(),
+ algorithm: Some(routing_algorithm),
+ };
+
+ let (decided_connector, connector_id) = decide_connector(state, &mut routing_data)?;
let encoded_algorithm = routing_data
.algorithm
@@ -1929,89 +1960,48 @@ where
payment_data.payment_attempt.connector = routing_data.routed_through;
payment_data.payment_attempt.straight_through_algorithm = encoded_algorithm;
+ payment_data.payment_attempt.merchant_connector_id = connector_id;
Ok(decided_connector)
}
pub fn decide_connector(
state: &AppState,
- merchant_account: &domain::MerchantAccount,
- request_straight_through: Option<api::StraightThroughAlgorithm>,
routing_data: &mut storage::RoutingData,
-) -> RouterResult<api::ConnectorCallType> {
- if let Some(ref connector_name) = routing_data.routed_through {
- let connector_data = api::ConnectorData::get_connector_by_name(
- &state.conf.connectors,
- connector_name.as_str(),
- api::GetToken::Connector,
- )
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Invalid connector name received in 'routed_through'")?;
-
- return Ok(api::ConnectorCallType::Single(connector_data));
- }
-
- if let Some(routing_algorithm) = request_straight_through {
- let connector_name = match &routing_algorithm {
- api::StraightThroughAlgorithm::Single(conn) => conn.to_string(),
- };
-
- let connector_data = api::ConnectorData::get_connector_by_name(
- &state.conf.connectors,
- &connector_name,
- api::GetToken::Connector,
- )
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Invalid connector name received in routing algorithm")?;
-
- routing_data.routed_through = Some(connector_name);
- routing_data.algorithm = Some(routing_algorithm);
- return Ok(api::ConnectorCallType::Single(connector_data));
- }
-
- if let Some(ref routing_algorithm) = routing_data.algorithm {
- let connector_name = match routing_algorithm {
- api::StraightThroughAlgorithm::Single(conn) => conn.to_string(),
- };
-
- let connector_data = api::ConnectorData::get_connector_by_name(
- &state.conf.connectors,
- &connector_name,
- api::GetToken::Connector,
- )
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Invalid connector name received in routing algorithm")?;
-
- routing_data.routed_through = Some(connector_name);
- return Ok(api::ConnectorCallType::Single(connector_data));
- }
-
- let routing_algorithm = merchant_account
- .routing_algorithm
+) -> RouterResult<(api::ConnectorCallType, Option<String>)> {
+ let routing_algorithm = routing_data
+ .algorithm
.clone()
- .get_required_value("RoutingAlgorithm")
- .change_context(errors::ApiErrorResponse::PreconditionFailed {
- message: "no routing algorithm has been configured".to_string(),
- })?
- .parse_value::<api::RoutingAlgorithm>("RoutingAlgorithm")
- .change_context(errors::ApiErrorResponse::InternalServerError) // Deserialization failed
- .attach_printable("Unable to deserialize merchant routing algorithm")?;
+ .get_required_value("Routing algorithm")?;
- let connector_name = match routing_algorithm {
- api::RoutingAlgorithm::Single(conn) => conn.to_string(),
+ let (connector_name, merchant_connector_id) = match routing_algorithm {
+ api::StraightThroughAlgorithm::Single(routable_connector_choice) => {
+ match routable_connector_choice {
+ api_models::admin::RoutableConnectorChoice::ConnectorName(routable_connector) => {
+ (routable_connector.to_string(), None)
+ }
+ api_models::admin::RoutableConnectorChoice::ConnectorId {
+ merchant_connector_id,
+ connector,
+ } => (connector.to_string(), Some(merchant_connector_id)),
+ }
+ }
};
let connector_data = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
&connector_name,
api::GetToken::Connector,
+ merchant_connector_id.clone(),
)
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Routing algorithm gave invalid connector")?;
+ .attach_printable("Invalid connector name received in routing algorithm")?;
routing_data.routed_through = Some(connector_name);
-
- Ok(api::ConnectorCallType::Single(connector_data))
+ Ok((
+ api::ConnectorCallType::Single(connector_data),
+ merchant_connector_id,
+ ))
}
pub fn should_add_task_to_process_tracker<F: Clone>(payment_data: &PaymentData<F>) -> bool {
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 3164e74dcd..2c77184b9b 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -118,7 +118,14 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
}
}?;
- Ok(mandate::mandate_procedure(state, resp, maybe_customer, pm_id).await?)
+ Ok(mandate::mandate_procedure(
+ state,
+ resp,
+ maybe_customer,
+ pm_id,
+ connector.merchant_connector_id.clone(),
+ )
+ .await?)
} else {
Ok(self.clone())
}
diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
index 4860f091a2..dae9ed0bf8 100644
--- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs
+++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs
@@ -86,7 +86,14 @@ impl Feature<api::SetupMandate, types::SetupMandateRequestData> for types::Setup
)
.await?;
- mandate::mandate_procedure(state, resp, maybe_customer, pm_id).await
+ mandate::mandate_procedure(
+ state,
+ resp,
+ maybe_customer,
+ pm_id,
+ connector.merchant_connector_id.clone(),
+ )
+ .await
}
async fn add_access_token<'a>(
@@ -212,7 +219,14 @@ impl types::SetupMandateRouterData {
)
.await?;
- Ok(mandate::mandate_procedure(state, resp, maybe_customer, pm_id).await?)
+ Ok(mandate::mandate_procedure(
+ state,
+ resp,
+ maybe_customer,
+ pm_id,
+ connector.merchant_connector_id.clone(),
+ )
+ .await?)
}
_ => Ok(self.clone()),
}
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index d7d24b1540..4deac54c70 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -408,7 +408,7 @@ pub async fn get_token_pm_type_mandate_details(
Option<storage_enums::PaymentMethodType>,
Option<MandateData>,
Option<payments::RecurringMandatePaymentData>,
- Option<String>,
+ Option<payments::MandateConnectorDetails>,
)> {
let mandate_data = request.mandate_data.clone().map(MandateData::foreign_from);
match mandate_type {
@@ -460,7 +460,7 @@ pub async fn get_token_for_recurring_mandate(
Option<storage_enums::PaymentMethod>,
Option<payments::RecurringMandatePaymentData>,
Option<storage_enums::PaymentMethodType>,
- Option<String>,
+ Option<payments::MandateConnectorDetails>,
)> {
let db = &*state.store;
let mandate_id = req.mandate_id.clone().get_required_value("mandate_id")?;
@@ -498,6 +498,11 @@ pub async fn get_token_for_recurring_mandate(
let token = Uuid::new_v4().to_string();
let payment_method_type = payment_method.payment_method_type;
+ let mandate_connector_details = payments::MandateConnectorDetails {
+ connector: mandate.connector,
+ merchant_connector_id: mandate.merchant_connector_id,
+ };
+
if let diesel_models::enums::PaymentMethod::Card = payment_method.payment_method {
let _ = cards::get_lookup_key_from_locker(state, &token, &payment_method).await?;
if let Some(payment_method_from_request) = req.payment_method {
@@ -519,7 +524,7 @@ pub async fn get_token_for_recurring_mandate(
payment_method_type,
}),
payment_method.payment_method_type,
- Some(mandate.connector),
+ Some(mandate_connector_details),
))
} else {
Ok((
@@ -529,7 +534,7 @@ pub async fn get_token_for_recurring_mandate(
payment_method_type,
}),
payment_method.payment_method_type,
- Some(mandate.connector),
+ Some(mandate_connector_details),
))
}
}
@@ -2105,6 +2110,7 @@ pub fn generate_mandate(
network_txn_id: Option<String>,
payment_method_data_option: Option<api_models::payments::PaymentMethodData>,
mandate_reference: Option<MandateReference>,
+ merchant_connector_id: Option<String>,
) -> CustomResult<Option<storage::MandateNew>, errors::ApiErrorResponse> {
match (setup_mandate_details, customer) {
(Some(data), Some(cus)) => {
@@ -2140,7 +2146,8 @@ pub fn generate_mandate(
}))
.set_connector_mandate_id(
mandate_reference.and_then(|reference| reference.connector_mandate_id),
- );
+ )
+ .set_merchant_connector_id(merchant_connector_id);
Ok(Some(
match data.mandate_type.get_required_value("mandate_type")? {
@@ -2593,6 +2600,13 @@ impl MerchantConnectorAccountType {
Self::CacheVal(_) => None,
}
}
+
+ pub fn get_mca_id(&self) -> Option<String> {
+ match self {
+ Self::DbVal(db_val) => Some(db_val.merchant_connector_id.to_string()),
+ Self::CacheVal(_) => None,
+ }
+ }
}
/// Query for merchant connector account either by business label or profile id
@@ -2605,6 +2619,7 @@ pub async fn get_merchant_connector_account(
key_store: &domain::MerchantKeyStore,
profile_id: &String,
connector_name: &str,
+ merchant_connector_id: Option<&String>,
) -> RouterResult<MerchantConnectorAccountType> {
let db = &*state.store;
match creds_identifier {
@@ -2647,17 +2662,31 @@ pub async fn get_merchant_connector_account(
Ok(MerchantConnectorAccountType::CacheVal(res))
}
None => {
- db.find_merchant_connector_account_by_profile_id_connector_name(
- profile_id,
- connector_name,
- key_store,
- )
- .await
- .to_not_found_response(
- errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
- id: format!("profile id {profile_id} and connector name {connector_name}"),
- },
- )
+ if let Some(merchant_connector_id) = merchant_connector_id {
+ db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(
+ merchant_id,
+ merchant_connector_id,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: merchant_connector_id.to_string(),
+ },
+ )
+ } else {
+ db.find_merchant_connector_account_by_profile_id_connector_name(
+ profile_id,
+ connector_name,
+ key_store,
+ )
+ .await
+ .to_not_found_response(
+ errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
+ id: format!("profile id {profile_id} and connector name {connector_name}"),
+ },
+ )
+ }
}
.map(MerchantConnectorAccountType::DbVal),
}
@@ -2904,6 +2933,7 @@ impl AttemptType {
connector_response_reference_id: None,
amount_capturable: old_payment_attempt.amount,
updated_by: storage_scheme.to_string(),
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 0e0d6c2147..9e1f12b6bc 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -514,6 +514,8 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
};
let connector = payment_data.payment_attempt.connector.clone();
+ let merchant_connector_id = payment_data.payment_attempt.merchant_connector_id.clone();
+
let straight_through_algorithm = payment_data
.payment_attempt
.straight_through_algorithm
@@ -592,6 +594,7 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
surcharge_amount,
tax_amount,
updated_by: storage_scheme.to_string(),
+ merchant_connector_id,
},
storage_scheme,
)
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 87195510fc..2d31f82aeb 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -428,6 +428,7 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
.straight_through_algorithm
.clone();
let authorized_amount = payment_data.payment_attempt.amount;
+ let merchant_connector_id = payment_data.payment_attempt.merchant_connector_id.clone();
payment_data.payment_attempt = db
.update_payment_attempt_with_attempt_id(
@@ -441,6 +442,7 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
false => None,
},
updated_by: storage_scheme.to_string(),
+ merchant_connector_id,
},
storage_scheme,
)
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index b5ed79b290..cf16a05359 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -373,10 +373,11 @@ where
let mut connector_and_supporting_payment_method_type = Vec::new();
filtered_connector_accounts
- .into_iter()
+ .iter()
.for_each(|connector_account| {
let res = connector_account
.payment_methods_enabled
+ .clone()
.unwrap_or_default()
.into_iter()
.map(|payment_methods_enabled| {
@@ -412,11 +413,7 @@ where
is_invoke_sdk_client && is_sent_in_request
})
.map(|payment_method_type| {
- (
- connector_account.connector_name.to_owned(),
- payment_method_type.payment_method_type,
- connector_account.business_sub_label.to_owned(),
- )
+ (connector_account, payment_method_type.payment_method_type)
})
.collect::<Vec<_>>()
})
@@ -427,14 +424,15 @@ where
let mut session_connector_data =
Vec::with_capacity(connector_and_supporting_payment_method_type.len());
- for (connector, payment_method_type, business_sub_label) in
+ for (merchant_connector_account, payment_method_type) in
connector_and_supporting_payment_method_type
{
let connector_type = api::GetToken::from(payment_method_type);
if let Ok(connector_data) = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
- &connector,
+ &merchant_connector_account.connector_name.to_string(),
connector_type,
+ Some(merchant_connector_account.merchant_connector_id.clone()),
)
.map_err(|err| {
logger::error!(session_token_error=?err);
@@ -443,7 +441,7 @@ where
session_connector_data.push(api::SessionConnectorData {
payment_method_type,
connector: connector_data,
- business_sub_label,
+ business_sub_label: merchant_connector_account.business_sub_label.clone(),
})
};
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index d2ced5af34..2fcd792eca 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -691,6 +691,7 @@ where
.set_payment_link(payment_link_data)
.set_profile_id(payment_intent.profile_id)
.set_attempt_count(payment_intent.attempt_count)
+ .set_merchant_connector_id(payment_attempt.merchant_connector_id)
.to_owned(),
headers,
))
@@ -1102,6 +1103,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCaptureD
&additional_data.state.conf.connectors,
&additional_data.connector_name,
api::GetToken::Connector,
+ payment_data.payment_attempt.merchant_connector_id.clone(),
)?;
let amount_to_capture: i64 = payment_data
.payment_attempt
@@ -1150,6 +1152,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCancelDa
&additional_data.state.conf.connectors,
&additional_data.connector_name,
api::GetToken::Connector,
+ payment_data.payment_attempt.merchant_connector_id.clone(),
)?;
let browser_info: Option<types::BrowserInformation> = payment_data
.payment_attempt
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 2e2cb07242..fcda3c8daf 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -146,6 +146,7 @@ pub async fn trigger_refund_to_gateway(
&state.conf.connectors,
&routed_through,
api::GetToken::Connector,
+ payment_attempt.merchant_connector_id.clone(),
)?;
let currency = payment_attempt.currency.ok_or_else(|| {
@@ -380,6 +381,7 @@ pub async fn sync_refund_with_gateway(
&state.conf.connectors,
&connector_id,
api::GetToken::Connector,
+ payment_attempt.connector.clone(),
)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to get the connector")?;
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index beedfb98bc..1eb9029ae3 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -63,6 +63,7 @@ pub async fn get_mca_for_payout<'a>(
key_store,
&profile_id,
connector_id,
+ payout_attempt.merchant_connector_id.as_ref(),
)
.await?;
Ok((merchant_connector_account, profile_id))
@@ -222,6 +223,7 @@ pub async fn construct_refund_router_data<'a, F>(
key_store,
&profile_id,
connector_id,
+ payment_attempt.merchant_connector_id.as_ref(),
)
.await?;
@@ -508,6 +510,7 @@ pub async fn construct_accept_dispute_router_data<'a>(
key_store,
&profile_id,
&dispute.connector,
+ payment_attempt.merchant_connector_id.as_ref(),
)
.await?;
@@ -597,6 +600,7 @@ pub async fn construct_submit_evidence_router_data<'a>(
key_store,
&profile_id,
connector_id,
+ payment_attempt.merchant_connector_id.as_ref(),
)
.await?;
@@ -684,8 +688,10 @@ pub async fn construct_upload_file_router_data<'a>(
key_store,
&profile_id,
connector_id,
+ payment_attempt.merchant_connector_id.as_ref(),
)
.await?;
+
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();
let auth_type: types::ConnectorAuthType = merchant_connector_account
.get_connector_account_details()
@@ -774,6 +780,7 @@ pub async fn construct_defend_dispute_router_data<'a>(
key_store,
&profile_id,
connector_id,
+ payment_attempt.merchant_connector_id.as_ref(),
)
.await?;
@@ -858,6 +865,7 @@ pub async fn construct_retrieve_file_router_data<'a>(
key_store,
profile_id,
connector_id,
+ file_metadata.merchant_connector_id.as_ref(),
)
.await?;
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index 2e763751f4..45503274a6 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -361,6 +361,7 @@ pub async fn get_or_update_dispute_object(
connector_updated_at: dispute_details.updated_at,
profile_id: None,
evidence: None,
+ merchant_connector_id: payment_attempt.merchant_connector_id.clone(),
};
state
.store
@@ -1194,6 +1195,7 @@ async fn fetch_mca_and_connector(
&state.conf.connectors,
&mca.connector_name,
api::GetToken::Connector,
+ Some(mca.merchant_connector_id.clone()),
)
.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "invalid connector name received".to_string(),
@@ -1202,10 +1204,12 @@ async fn fetch_mca_and_connector(
Ok((mca, connector))
} else {
+ // Merchant connector account is already being queried, it is safe to set connector id as None
let connector = api::ConnectorData::get_connector_by_name(
&state.conf.connectors,
connector_name_or_mca_id,
api::GetToken::Connector,
+ None,
)
.change_context(errors::ApiErrorResponse::InvalidRequestData {
message: "invalid connector name received".to_string(),
diff --git a/crates/router/src/db/dispute.rs b/crates/router/src/db/dispute.rs
index 42fb85ad16..c63585205b 100644
--- a/crates/router/src/db/dispute.rs
+++ b/crates/router/src/db/dispute.rs
@@ -172,6 +172,7 @@ impl DisputeInterface for MockDb {
connector: dispute.connector,
profile_id: dispute.profile_id,
evidence,
+ merchant_connector_id: dispute.merchant_connector_id,
};
locked_disputes.push(new_dispute.clone());
@@ -405,6 +406,7 @@ mod tests {
connector: "connector".into(),
evidence: Some(Secret::from(Value::String("evidence".into()))),
profile_id: None,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs
index 381eecbe7b..fcd7171965 100644
--- a/crates/router/src/db/mandate.rs
+++ b/crates/router/src/db/mandate.rs
@@ -290,6 +290,7 @@ impl MandateInterface for MockDb {
end_date: mandate_new.end_date,
metadata: mandate_new.metadata,
connector_mandate_ids: mandate_new.connector_mandate_ids,
+ merchant_connector_id: mandate_new.merchant_connector_id,
};
mandates.push(mandate.clone());
Ok(mandate)
diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs
index ae586a48ad..a6133edad6 100644
--- a/crates/router/src/db/refund.rs
+++ b/crates/router/src/db/refund.rs
@@ -368,6 +368,7 @@ mod storage {
refund_reason: new.refund_reason.clone(),
profile_id: new.profile_id.clone(),
updated_by: new.updated_by.clone(),
+ merchant_connector_id: new.merchant_connector_id.clone(),
};
let field = format!(
@@ -796,6 +797,7 @@ impl RefundInterface for MockDb {
refund_reason: new.refund_reason.clone(),
profile_id: new.profile_id,
updated_by: new.updated_by,
+ merchant_connector_id: new.merchant_connector_id,
};
refunds.push(refund.clone());
Ok(refund)
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index 491f9a0851..00e40cc908 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -171,11 +171,15 @@ pub enum GetToken {
Connector,
}
+/// Routing algorithm will output merchant connector identifier instead of connector name
+/// In order to support backwards compatibility for older routing algorithms and merchant accounts
+/// the support for connector name is retained
#[derive(Clone)]
pub struct ConnectorData {
pub connector: BoxedConnector,
pub connector_name: types::Connector,
pub get_token: GetToken,
+ pub merchant_connector_id: Option<String>,
}
#[cfg(feature = "payouts")]
@@ -276,6 +280,7 @@ impl ConnectorData {
connectors: &Connectors,
name: &str,
connector_type: GetToken,
+ connector_id: Option<String>,
) -> CustomResult<Self, errors::ApiErrorResponse> {
let connector = Self::convert_connector(connectors, name)?;
let connector_name = api_enums::Connector::from_str(name)
@@ -287,6 +292,7 @@ impl ConnectorData {
connector,
connector_name,
get_token: connector_type,
+ merchant_connector_id: connector_id,
})
}
diff --git a/crates/router/src/types/api/webhooks.rs b/crates/router/src/types/api/webhooks.rs
index 70a40f466c..4bde2608c9 100644
--- a/crates/router/src/types/api/webhooks.rs
+++ b/crates/router/src/types/api/webhooks.rs
@@ -156,6 +156,7 @@ pub trait IncomingWebhook: ConnectorCommon + Sync {
&state.conf.connectors,
connector_name,
types::api::GetToken::Connector,
+ None,
)
.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)
.attach_printable("invalid connector name received in payment attempt")?;
diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs
index 4fe36f3687..c9ee3a34f2 100644
--- a/crates/router/tests/connectors/aci.rs
+++ b/crates/router/tests/connectors/aci.rs
@@ -173,6 +173,7 @@ async fn payments_create_success() {
connector: Box::new(&CV),
connector_name: types::Connector::Aci,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
};
let connector_integration: services::BoxedConnectorIntegration<
'_,
@@ -214,6 +215,7 @@ async fn payments_create_failure() {
connector: Box::new(&CV),
connector_name: types::Connector::Aci,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
};
let connector_integration: services::BoxedConnectorIntegration<
'_,
@@ -260,6 +262,7 @@ async fn refund_for_successful_payments() {
connector: Box::new(&CV),
connector_name: types::Connector::Aci,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
};
let tx: oneshot::Sender<()> = oneshot::channel().0;
let state = routes::AppState::with_storage(
@@ -327,6 +330,7 @@ async fn refunds_create_failure() {
connector: Box::new(&CV),
connector_name: types::Connector::Aci,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
};
let tx: oneshot::Sender<()> = oneshot::channel().0;
let state = routes::AppState::with_storage(
diff --git a/crates/router/tests/connectors/adyen.rs b/crates/router/tests/connectors/adyen.rs
index 2ee6c4912e..dca7bbfc9b 100644
--- a/crates/router/tests/connectors/adyen.rs
+++ b/crates/router/tests/connectors/adyen.rs
@@ -19,6 +19,7 @@ impl utils::Connector for AdyenTest {
connector: Box::new(&Adyen),
connector_name: types::Connector::Adyen,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/airwallex.rs b/crates/router/tests/connectors/airwallex.rs
index 7d9070a94d..6e7f6c000d 100644
--- a/crates/router/tests/connectors/airwallex.rs
+++ b/crates/router/tests/connectors/airwallex.rs
@@ -21,6 +21,7 @@ impl Connector for AirwallexTest {
connector: Box::new(&Airwallex),
connector_name: types::Connector::Airwallex,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/authorizedotnet.rs b/crates/router/tests/connectors/authorizedotnet.rs
index 4750e122a2..4021d57d54 100644
--- a/crates/router/tests/connectors/authorizedotnet.rs
+++ b/crates/router/tests/connectors/authorizedotnet.rs
@@ -18,6 +18,7 @@ impl utils::Connector for AuthorizedotnetTest {
connector: Box::new(&Authorizedotnet),
connector_name: types::Connector::Authorizedotnet,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/bambora.rs b/crates/router/tests/connectors/bambora.rs
index 5638214202..c4da2b900d 100644
--- a/crates/router/tests/connectors/bambora.rs
+++ b/crates/router/tests/connectors/bambora.rs
@@ -19,6 +19,7 @@ impl utils::Connector for BamboraTest {
connector: Box::new(&Bambora),
connector_name: types::Connector::Bambora,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/bitpay.rs b/crates/router/tests/connectors/bitpay.rs
index 2f6db7a9e8..755427140c 100644
--- a/crates/router/tests/connectors/bitpay.rs
+++ b/crates/router/tests/connectors/bitpay.rs
@@ -17,6 +17,7 @@ impl utils::Connector for BitpayTest {
connector: Box::new(&Bitpay),
connector_name: types::Connector::Bitpay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/bluesnap.rs b/crates/router/tests/connectors/bluesnap.rs
index b54261e77c..30052d11da 100644
--- a/crates/router/tests/connectors/bluesnap.rs
+++ b/crates/router/tests/connectors/bluesnap.rs
@@ -21,6 +21,7 @@ impl utils::Connector for BluesnapTest {
connector: Box::new(&Bluesnap),
connector_name: types::Connector::Bluesnap,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/boku.rs b/crates/router/tests/connectors/boku.rs
index e971ad271e..9c8ac961ca 100644
--- a/crates/router/tests/connectors/boku.rs
+++ b/crates/router/tests/connectors/boku.rs
@@ -14,6 +14,7 @@ impl utils::Connector for BokuTest {
connector: Box::new(&Boku),
connector_name: types::Connector::Boku,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/cashtocode.rs b/crates/router/tests/connectors/cashtocode.rs
index fdb1b94a71..871677bb69 100644
--- a/crates/router/tests/connectors/cashtocode.rs
+++ b/crates/router/tests/connectors/cashtocode.rs
@@ -16,6 +16,7 @@ impl utils::Connector for CashtocodeTest {
connector: Box::new(&Cashtocode),
connector_name: types::Connector::Cashtocode,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/checkout.rs b/crates/router/tests/connectors/checkout.rs
index 18d6d6d2dd..1c369332ef 100644
--- a/crates/router/tests/connectors/checkout.rs
+++ b/crates/router/tests/connectors/checkout.rs
@@ -15,6 +15,7 @@ impl utils::Connector for CheckoutTest {
connector: Box::new(&Checkout),
connector_name: types::Connector::Checkout,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/coinbase.rs b/crates/router/tests/connectors/coinbase.rs
index cc8cc774a1..512e03a5c9 100644
--- a/crates/router/tests/connectors/coinbase.rs
+++ b/crates/router/tests/connectors/coinbase.rs
@@ -18,6 +18,7 @@ impl utils::Connector for CoinbaseTest {
connector: Box::new(&Coinbase),
connector_name: types::Connector::Coinbase,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/cryptopay.rs b/crates/router/tests/connectors/cryptopay.rs
index 48313e5d1a..e9c43cee3a 100644
--- a/crates/router/tests/connectors/cryptopay.rs
+++ b/crates/router/tests/connectors/cryptopay.rs
@@ -17,6 +17,7 @@ impl utils::Connector for CryptopayTest {
connector: Box::new(&Cryptopay),
connector_name: types::Connector::Cryptopay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/cybersource.rs b/crates/router/tests/connectors/cybersource.rs
index 5f9adf39f9..70255f68d8 100644
--- a/crates/router/tests/connectors/cybersource.rs
+++ b/crates/router/tests/connectors/cybersource.rs
@@ -20,6 +20,7 @@ impl utils::Connector for Cybersource {
connector: Box::new(&Cybersource),
connector_name: types::Connector::Cybersource,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
fn get_auth_token(&self) -> types::ConnectorAuthType {
diff --git a/crates/router/tests/connectors/dlocal.rs b/crates/router/tests/connectors/dlocal.rs
index 05d42ef7fe..92ae9da11d 100644
--- a/crates/router/tests/connectors/dlocal.rs
+++ b/crates/router/tests/connectors/dlocal.rs
@@ -19,6 +19,7 @@ impl utils::Connector for DlocalTest {
connector: Box::new(&Dlocal),
connector_name: types::Connector::Dlocal,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/dummyconnector.rs b/crates/router/tests/connectors/dummyconnector.rs
index 7efaa83295..75252e85ed 100644
--- a/crates/router/tests/connectors/dummyconnector.rs
+++ b/crates/router/tests/connectors/dummyconnector.rs
@@ -17,6 +17,7 @@ impl utils::Connector for DummyConnectorTest {
connector: Box::new(&DummyConnector::<1>),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/fiserv.rs b/crates/router/tests/connectors/fiserv.rs
index 532084a746..1394667718 100644
--- a/crates/router/tests/connectors/fiserv.rs
+++ b/crates/router/tests/connectors/fiserv.rs
@@ -19,6 +19,7 @@ impl utils::Connector for FiservTest {
connector: Box::new(&Fiserv),
connector_name: types::Connector::Fiserv,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/forte.rs b/crates/router/tests/connectors/forte.rs
index 703b8900b6..f0c182d62a 100644
--- a/crates/router/tests/connectors/forte.rs
+++ b/crates/router/tests/connectors/forte.rs
@@ -19,6 +19,7 @@ impl utils::Connector for ForteTest {
connector: Box::new(&Forte),
connector_name: types::Connector::Forte,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/globalpay.rs b/crates/router/tests/connectors/globalpay.rs
index 39e0ed58f4..8553f2a768 100644
--- a/crates/router/tests/connectors/globalpay.rs
+++ b/crates/router/tests/connectors/globalpay.rs
@@ -19,6 +19,7 @@ impl Connector for Globalpay {
connector: Box::new(&Globalpay),
connector_name: types::Connector::Globalpay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/globepay.rs b/crates/router/tests/connectors/globepay.rs
index 607abac738..210f12b23d 100644
--- a/crates/router/tests/connectors/globepay.rs
+++ b/crates/router/tests/connectors/globepay.rs
@@ -16,6 +16,7 @@ impl utils::Connector for GlobepayTest {
connector: Box::new(&Globepay),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/gocardless.rs b/crates/router/tests/connectors/gocardless.rs
index 50c4bf4afb..6b6bd6d861 100644
--- a/crates/router/tests/connectors/gocardless.rs
+++ b/crates/router/tests/connectors/gocardless.rs
@@ -14,6 +14,7 @@ impl utils::Connector for GocardlessTest {
connector: Box::new(&Gocardless),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/helcim.rs b/crates/router/tests/connectors/helcim.rs
index f8eb963566..0bac1e7023 100644
--- a/crates/router/tests/connectors/helcim.rs
+++ b/crates/router/tests/connectors/helcim.rs
@@ -14,6 +14,7 @@ impl utils::Connector for HelcimTest {
connector: Box::new(&Helcim),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/iatapay.rs b/crates/router/tests/connectors/iatapay.rs
index c1f4492bce..b6469b500c 100644
--- a/crates/router/tests/connectors/iatapay.rs
+++ b/crates/router/tests/connectors/iatapay.rs
@@ -18,6 +18,7 @@ impl Connector for IatapayTest {
connector: Box::new(&Iatapay),
connector_name: types::Connector::Iatapay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/mollie.rs b/crates/router/tests/connectors/mollie.rs
index e5a1f090d3..14c77e2a9f 100644
--- a/crates/router/tests/connectors/mollie.rs
+++ b/crates/router/tests/connectors/mollie.rs
@@ -15,6 +15,7 @@ impl utils::Connector for MollieTest {
connector: Box::new(&Mollie),
connector_name: types::Connector::Mollie,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/multisafepay.rs b/crates/router/tests/connectors/multisafepay.rs
index a5d9dda922..8502a60b71 100644
--- a/crates/router/tests/connectors/multisafepay.rs
+++ b/crates/router/tests/connectors/multisafepay.rs
@@ -17,6 +17,7 @@ impl utils::Connector for MultisafepayTest {
connector: Box::new(&Multisafepay),
connector_name: types::Connector::Multisafepay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/nexinets.rs b/crates/router/tests/connectors/nexinets.rs
index f9b8affb06..ff4a283e67 100644
--- a/crates/router/tests/connectors/nexinets.rs
+++ b/crates/router/tests/connectors/nexinets.rs
@@ -20,6 +20,7 @@ impl utils::Connector for NexinetsTest {
connector: Box::new(&Nexinets),
connector_name: types::Connector::Nexinets,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/nmi.rs b/crates/router/tests/connectors/nmi.rs
index 42301dc3a2..24e1d69a60 100644
--- a/crates/router/tests/connectors/nmi.rs
+++ b/crates/router/tests/connectors/nmi.rs
@@ -16,6 +16,7 @@ impl utils::Connector for NmiTest {
connector: Box::new(&Nmi),
connector_name: types::Connector::Nmi,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/noon.rs b/crates/router/tests/connectors/noon.rs
index 01a38fcd78..0f736e3e52 100644
--- a/crates/router/tests/connectors/noon.rs
+++ b/crates/router/tests/connectors/noon.rs
@@ -21,6 +21,7 @@ impl utils::Connector for NoonTest {
connector: Box::new(&Noon),
connector_name: types::Connector::Noon,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/nuvei.rs b/crates/router/tests/connectors/nuvei.rs
index d0f8fbaa93..5d266fb46f 100644
--- a/crates/router/tests/connectors/nuvei.rs
+++ b/crates/router/tests/connectors/nuvei.rs
@@ -22,6 +22,7 @@ impl utils::Connector for NuveiTest {
connector: Box::new(&Nuvei),
connector_name: types::Connector::Nuvei,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/opayo.rs b/crates/router/tests/connectors/opayo.rs
index 23b1098e27..6d76133d34 100644
--- a/crates/router/tests/connectors/opayo.rs
+++ b/crates/router/tests/connectors/opayo.rs
@@ -18,6 +18,7 @@ impl utils::Connector for OpayoTest {
connector: Box::new(&Opayo),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/opennode.rs b/crates/router/tests/connectors/opennode.rs
index a46fc20604..248bbb02e5 100644
--- a/crates/router/tests/connectors/opennode.rs
+++ b/crates/router/tests/connectors/opennode.rs
@@ -17,6 +17,7 @@ impl utils::Connector for OpennodeTest {
connector: Box::new(&Opennode),
connector_name: types::Connector::Opennode,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/payeezy.rs b/crates/router/tests/connectors/payeezy.rs
index 01d8d1ea87..81d69503b4 100644
--- a/crates/router/tests/connectors/payeezy.rs
+++ b/crates/router/tests/connectors/payeezy.rs
@@ -24,6 +24,7 @@ impl utils::Connector for PayeezyTest {
connector: Box::new(&Payeezy),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/payme.rs b/crates/router/tests/connectors/payme.rs
index 68538ad407..5550ba12af 100644
--- a/crates/router/tests/connectors/payme.rs
+++ b/crates/router/tests/connectors/payme.rs
@@ -20,6 +20,7 @@ impl utils::Connector for PaymeTest {
connector: Box::new(&Payme),
connector_name: types::Connector::Payme,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/paypal.rs b/crates/router/tests/connectors/paypal.rs
index e9df655669..bfd2620e3f 100644
--- a/crates/router/tests/connectors/paypal.rs
+++ b/crates/router/tests/connectors/paypal.rs
@@ -17,6 +17,7 @@ impl Connector for PaypalTest {
connector: Box::new(&Paypal),
connector_name: types::Connector::Paypal,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/payu.rs b/crates/router/tests/connectors/payu.rs
index f1030092a4..c73205d9fd 100644
--- a/crates/router/tests/connectors/payu.rs
+++ b/crates/router/tests/connectors/payu.rs
@@ -14,6 +14,7 @@ impl Connector for Payu {
connector: Box::new(&Payu),
connector_name: types::Connector::Payu,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/powertranz.rs b/crates/router/tests/connectors/powertranz.rs
index 0f9ce943a4..cc0028ef3c 100644
--- a/crates/router/tests/connectors/powertranz.rs
+++ b/crates/router/tests/connectors/powertranz.rs
@@ -16,6 +16,7 @@ impl utils::Connector for PowertranzTest {
connector: Box::new(&Powertranz),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/prophetpay.rs b/crates/router/tests/connectors/prophetpay.rs
index ac288533cf..2e4c6d7e38 100644
--- a/crates/router/tests/connectors/prophetpay.rs
+++ b/crates/router/tests/connectors/prophetpay.rs
@@ -14,6 +14,7 @@ impl utils::Connector for ProphetpayTest {
connector: Box::new(&Prophetpay),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/rapyd.rs b/crates/router/tests/connectors/rapyd.rs
index 4ca7148a9c..143f87fc57 100644
--- a/crates/router/tests/connectors/rapyd.rs
+++ b/crates/router/tests/connectors/rapyd.rs
@@ -19,6 +19,7 @@ impl utils::Connector for Rapyd {
connector: Box::new(&Rapyd),
connector_name: types::Connector::Rapyd,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/shift4.rs b/crates/router/tests/connectors/shift4.rs
index e236d2ad9d..fe7a232b3e 100644
--- a/crates/router/tests/connectors/shift4.rs
+++ b/crates/router/tests/connectors/shift4.rs
@@ -18,6 +18,7 @@ impl utils::Connector for Shift4Test {
connector: Box::new(&Shift4),
connector_name: types::Connector::Shift4,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/square.rs b/crates/router/tests/connectors/square.rs
index ba7416c5a1..daed5030ce 100644
--- a/crates/router/tests/connectors/square.rs
+++ b/crates/router/tests/connectors/square.rs
@@ -20,6 +20,7 @@ impl Connector for SquareTest {
connector: Box::new(&Square),
connector_name: types::Connector::Square,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/stax.rs b/crates/router/tests/connectors/stax.rs
index 72c1d89da0..2acf96507f 100644
--- a/crates/router/tests/connectors/stax.rs
+++ b/crates/router/tests/connectors/stax.rs
@@ -16,6 +16,7 @@ impl utils::Connector for StaxTest {
connector: Box::new(&Stax),
connector_name: types::Connector::Stax,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/stripe.rs b/crates/router/tests/connectors/stripe.rs
index e2ac4a173f..735dedeffb 100644
--- a/crates/router/tests/connectors/stripe.rs
+++ b/crates/router/tests/connectors/stripe.rs
@@ -17,6 +17,7 @@ impl utils::Connector for Stripe {
connector: Box::new(&Stripe),
connector_name: types::Connector::Stripe,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/trustpay.rs b/crates/router/tests/connectors/trustpay.rs
index cefc0f5ab1..6dcd78f58a 100644
--- a/crates/router/tests/connectors/trustpay.rs
+++ b/crates/router/tests/connectors/trustpay.rs
@@ -18,6 +18,7 @@ impl utils::Connector for TrustpayTest {
connector: Box::new(&Trustpay),
connector_name: types::Connector::Trustpay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/tsys.rs b/crates/router/tests/connectors/tsys.rs
index 51d0575a7a..e7a0d747f4 100644
--- a/crates/router/tests/connectors/tsys.rs
+++ b/crates/router/tests/connectors/tsys.rs
@@ -19,6 +19,7 @@ impl utils::Connector for TsysTest {
connector: Box::new(&Tsys),
connector_name: types::Connector::Tsys,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/volt.rs b/crates/router/tests/connectors/volt.rs
index 8435e39c65..1c62c47ee0 100644
--- a/crates/router/tests/connectors/volt.rs
+++ b/crates/router/tests/connectors/volt.rs
@@ -14,6 +14,7 @@ impl utils::Connector for VoltTest {
connector: Box::new(&Volt),
connector_name: types::Connector::DummyConnector1,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/wise.rs b/crates/router/tests/connectors/wise.rs
index fad3a73caf..753ed4f4ed 100644
--- a/crates/router/tests/connectors/wise.rs
+++ b/crates/router/tests/connectors/wise.rs
@@ -16,6 +16,7 @@ impl utils::Connector for WiseTest {
connector: Box::new(&Adyen),
connector_name: types::Connector::Adyen,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/worldline.rs b/crates/router/tests/connectors/worldline.rs
index b9ea1364fd..6163949c6c 100644
--- a/crates/router/tests/connectors/worldline.rs
+++ b/crates/router/tests/connectors/worldline.rs
@@ -22,6 +22,7 @@ impl utils::Connector for WorldlineTest {
connector: Box::new(&Worldline),
connector_name: types::Connector::Worldline,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/worldpay.rs b/crates/router/tests/connectors/worldpay.rs
index a7e0f19af7..bf598e0b37 100644
--- a/crates/router/tests/connectors/worldpay.rs
+++ b/crates/router/tests/connectors/worldpay.rs
@@ -23,6 +23,7 @@ impl utils::Connector for Worldpay {
connector: Box::new(&Worldpay),
connector_name: types::Connector::Worldpay,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/router/tests/connectors/zen.rs b/crates/router/tests/connectors/zen.rs
index 3076c4be6a..12f914e13c 100644
--- a/crates/router/tests/connectors/zen.rs
+++ b/crates/router/tests/connectors/zen.rs
@@ -21,6 +21,7 @@ impl utils::Connector for ZenTest {
connector: Box::new(&Zen),
connector_name: types::Connector::Zen,
get_token: types::api::GetToken::Connector,
+ merchant_connector_id: None,
}
}
diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs
index 34bf881717..a9f9b9d3c0 100644
--- a/crates/storage_impl/src/mock_db/payment_attempt.rs
+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs
@@ -141,6 +141,7 @@ impl PaymentAttemptInterface for MockDb {
connector_response_reference_id: None,
amount_capturable: payment_attempt.amount_capturable,
updated_by: storage_scheme.to_string(),
+ merchant_connector_id: payment_attempt.merchant_connector_id,
};
payment_attempts.push(payment_attempt.clone());
Ok(payment_attempt)
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index 751796bd1d..ae756c38c0 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -361,6 +361,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
connector_response_reference_id: None,
amount_capturable: payment_attempt.amount_capturable,
updated_by: storage_scheme.to_string(),
+ merchant_connector_id: payment_attempt.merchant_connector_id.clone(),
};
let field = format!("pa_{}", created_attempt.attempt_id);
@@ -957,6 +958,7 @@ impl DataModelExt for PaymentAttempt {
amount_capturable: self.amount_capturable,
updated_by: self.updated_by,
+ merchant_connector_id: self.merchant_connector_id,
}
}
@@ -1007,6 +1009,7 @@ impl DataModelExt for PaymentAttempt {
amount_capturable: storage_model.amount_capturable,
updated_by: storage_model.updated_by,
+ merchant_connector_id: storage_model.merchant_connector_id,
}
}
}
@@ -1057,6 +1060,7 @@ impl DataModelExt for PaymentAttemptNew {
amount_capturable: self.amount_capturable,
updated_by: self.updated_by,
+ merchant_connector_id: self.merchant_connector_id,
}
}
@@ -1105,6 +1109,7 @@ impl DataModelExt for PaymentAttemptNew {
amount_capturable: storage_model.amount_capturable,
updated_by: storage_model.updated_by,
+ merchant_connector_id: storage_model.merchant_connector_id,
}
}
}
@@ -1149,12 +1154,14 @@ impl DataModelExt for PaymentAttemptUpdate {
straight_through_algorithm,
amount_capturable,
updated_by,
+ merchant_connector_id,
} => DieselPaymentAttemptUpdate::UpdateTrackers {
payment_token,
connector,
straight_through_algorithm,
amount_capturable,
updated_by,
+ merchant_connector_id,
},
Self::AuthenticationTypeUpdate {
authentication_type,
@@ -1183,6 +1190,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
updated_by,
+ merchant_connector_id: connector_id,
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
amount,
currency,
@@ -1203,6 +1211,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
updated_by,
+ merchant_connector_id: connector_id,
},
Self::VoidUpdate {
status,
@@ -1369,12 +1378,14 @@ impl DataModelExt for PaymentAttemptUpdate {
straight_through_algorithm,
amount_capturable,
updated_by,
+ merchant_connector_id: connector_id,
} => Self::UpdateTrackers {
payment_token,
connector,
straight_through_algorithm,
amount_capturable,
updated_by,
+ merchant_connector_id: connector_id,
},
DieselPaymentAttemptUpdate::AuthenticationTypeUpdate {
authentication_type,
@@ -1403,6 +1414,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
updated_by,
+ merchant_connector_id: connector_id,
} => Self::ConfirmUpdate {
amount,
currency,
@@ -1423,6 +1435,7 @@ impl DataModelExt for PaymentAttemptUpdate {
surcharge_amount,
tax_amount,
updated_by,
+ merchant_connector_id: connector_id,
},
DieselPaymentAttemptUpdate::VoidUpdate {
status,
diff --git a/migrations/2023-10-19-071731_add_connector_id_to_payment_attempt/down.sql b/migrations/2023-10-19-071731_add_connector_id_to_payment_attempt/down.sql
new file mode 100644
index 0000000000..993bba9f05
--- /dev/null
+++ b/migrations/2023-10-19-071731_add_connector_id_to_payment_attempt/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_attempt DROP COLUMN IF EXISTS connector_id;
diff --git a/migrations/2023-10-19-071731_add_connector_id_to_payment_attempt/up.sql b/migrations/2023-10-19-071731_add_connector_id_to_payment_attempt/up.sql
new file mode 100644
index 0000000000..ed475a9311
--- /dev/null
+++ b/migrations/2023-10-19-071731_add_connector_id_to_payment_attempt/up.sql
@@ -0,0 +1,5 @@
+-- Your SQL goes here
+-- The type is VARCHAR(32) as this will store the merchant_connector_account id
+-- which will be generated by the application using default length
+ALTER TABLE payment_attempt
+ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
diff --git a/migrations/2023-10-19-124023_add_connector_id_to_other_tables/down.sql b/migrations/2023-10-19-124023_add_connector_id_to_other_tables/down.sql
new file mode 100644
index 0000000000..8bb1a2b8e3
--- /dev/null
+++ b/migrations/2023-10-19-124023_add_connector_id_to_other_tables/down.sql
@@ -0,0 +1,10 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE file_metadata DROP COLUMN IF EXISTS merchant_connector_id;
+
+ALTER TABLE refund DROP COLUMN IF EXISTS merchant_connector_id;
+
+ALTER TABLE payout_attempt DROP COLUMN IF EXISTS merchant_connector_id;
+
+ALTER TABLE dispute DROP COLUMN IF EXISTS merchant_connector_id;
+
+ALTER TABLE mandate DROP COLUMN IF EXISTS merchant_connector_id;
diff --git a/migrations/2023-10-19-124023_add_connector_id_to_other_tables/up.sql b/migrations/2023-10-19-124023_add_connector_id_to_other_tables/up.sql
new file mode 100644
index 0000000000..42de0188f3
--- /dev/null
+++ b/migrations/2023-10-19-124023_add_connector_id_to_other_tables/up.sql
@@ -0,0 +1,15 @@
+-- Your SQL goes here
+ALTER TABLE file_metadata
+ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
+
+ALTER TABLE refund
+ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
+
+ALTER TABLE payout_attempt
+ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
+
+ALTER TABLE dispute
+ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
+
+ALTER TABLE mandate
+ADD COLUMN IF NOT EXISTS merchant_connector_id VARCHAR(32);
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index 7649a4e982..8b5988dcb4 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -9746,6 +9746,11 @@
"type": "string",
"description": "Denotes the action(approve or reject) taken by merchant in case of manual review. Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment",
"nullable": true
+ },
+ "merchant_connector_id": {
+ "type": "string",
+ "description": "Identifier of the connector ( merchant connector account ) which was chosen to make the payment",
+ "nullable": true
}
}
},