Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(payment_connector): allow connector label to be updated #2622

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,9 @@ pub struct MerchantConnectorCreate {
/// Name of the Connector
#[schema(value_type = Connector, example = "stripe")]
pub connector_name: api_enums::Connector,
// /// Connector label for specific country and Business
#[serde(skip_deserializing)]
/// Connector label for a connector, this can serve as a field to identify the connector as per business details
#[schema(example = "stripe_US_travel")]
pub connector_label: String,
pub connector_label: Option<String>,

/// Unique ID of the connector
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
Expand Down Expand Up @@ -656,8 +655,8 @@ pub struct MerchantConnectorResponse {
/// Name of the Connector
#[schema(example = "stripe")]
pub connector_name: String,
// /// Connector label for specific country and Business
#[serde(skip_deserializing)]

/// Connector label for a connector, this can serve as a field to identify the connector as per business details
#[schema(example = "stripe_US_travel")]
pub connector_label: Option<String>,

Expand Down Expand Up @@ -750,6 +749,9 @@ pub struct MerchantConnectorUpdate {
#[schema(value_type = ConnectorType, example = "payment_processor")]
pub connector_type: api_enums::ConnectorType,

/// Connector label for a connector, this can serve as a field to identify the connector as per business details
pub connector_label: Option<String>,

/// Account details of the Connector. You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "auth_type": "HeaderKey","api_key": "Basic MyVerySecretApiKey" }))]
pub connector_account_details: Option<pii::SecretSerdeValue>,
Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/merchant_connector_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct MerchantConnectorAccountUpdateInternal {
pub connector_type: Option<storage_enums::ConnectorType>,
pub connector_name: Option<String>,
pub connector_account_details: Option<Encryption>,
pub connector_label: Option<String>,
pub test_mode: Option<bool>,
pub disabled: Option<bool>,
pub merchant_connector_id: Option<String>,
Expand Down
47 changes: 32 additions & 15 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,38 @@ pub async fn create_payment_connector(
&merchant_account,
)?;

let connector_label = core_utils::get_connector_label(
// Business label support will be deprecated soon
let profile_id = core_utils::get_profile_id_from_business_details(
req.business_country,
req.business_label.as_ref(),
req.business_sub_label.as_ref(),
&req.connector_name.to_string(),
);
&merchant_account,
req.profile_id.as_ref(),
store,
true,
)
.await?;

let business_profile = state
.store
.find_business_profile_by_profile_id(&profile_id)
.await
.to_not_found_response(errors::ApiErrorResponse::BusinessProfileNotFound {
id: profile_id.to_owned(),
})?;

// If connector label is not passed in the request, generate one
let connector_label = req
.connector_label
.or(core_utils::get_connector_label(
req.business_country,
req.business_label.as_ref(),
req.business_sub_label.as_ref(),
&req.connector_name.to_string(),
))
.unwrap_or(format!(
"{}_{}",
req.connector_name, business_profile.profile_name
));

let mut vec = Vec::new();
let payment_methods_enabled = match req.payment_methods_enabled {
Expand Down Expand Up @@ -682,16 +708,6 @@ pub async fn create_payment_connector(

let frm_configs = get_frm_config_as_secret(req.frm_configs);

let profile_id = core_utils::get_profile_id_from_business_details(
req.business_country,
req.business_label.as_ref(),
&merchant_account,
req.profile_id.as_ref(),
&*state.store,
true,
)
.await?;

let merchant_connector_account = domain::MerchantConnectorAccount {
merchant_id: merchant_id.to_string(),
connector_type: req.connector_type,
Expand All @@ -713,7 +729,7 @@ pub async fn create_payment_connector(
disabled: req.disabled,
metadata: req.metadata,
frm_configs,
connector_label: connector_label.clone(),
connector_label: Some(connector_label),
business_country: req.business_country,
business_label: req.business_label.clone(),
business_sub_label: req.business_sub_label,
Expand Down Expand Up @@ -875,6 +891,7 @@ pub async fn update_payment_connector(
connector_type: Some(req.connector_type),
connector_name: None,
merchant_connector_id: None,
connector_label: req.connector_label,
connector_account_details: req
.connector_account_details
.async_lift(|inner| {
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/verification/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub async fn check_existence_and_add_domain_to_db(
connector_webhook_details: None,
applepay_verified_domains: Some(already_verified_domains.clone()),
pm_auth_config: None,
connector_label: None,
};
state
.store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum MerchantConnectorAccountUpdate {
connector_webhook_details: Option<pii::SecretSerdeValue>,
applepay_verified_domains: Option<Vec<String>>,
pm_auth_config: Option<serde_json::Value>,
connector_label: Option<String>,
},
}

Expand Down Expand Up @@ -175,6 +176,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
connector_webhook_details,
applepay_verified_domains,
pm_auth_config,
connector_label,
} => Self {
merchant_id,
connector_type,
Expand All @@ -191,6 +193,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
connector_webhook_details,
applepay_verified_domains,
pm_auth_config,
connector_label,
},
}
}
Expand Down
17 changes: 17 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -6494,6 +6494,12 @@
"connector_name": {
"$ref": "#/components/schemas/Connector"
},
"connector_label": {
"type": "string",
"description": "Connector label for a connector, this can serve as a field to identify the connector as per business details",
"example": "stripe_US_travel",
"nullable": true
},
"merchant_connector_id": {
"type": "string",
"description": "Unique ID of the connector",
Expand Down Expand Up @@ -6706,6 +6712,12 @@
"description": "Name of the Connector",
"example": "stripe"
},
"connector_label": {
"type": "string",
"description": "Connector label for a connector, this can serve as a field to identify the connector as per business details",
"example": "stripe_US_travel",
"nullable": true
},
"merchant_connector_id": {
"type": "string",
"description": "Unique ID of the connector",
Expand Down Expand Up @@ -6845,6 +6857,11 @@
"connector_type": {
"$ref": "#/components/schemas/ConnectorType"
},
"connector_label": {
"type": "string",
"description": "Connector label for a connector, this can serve as a field to identify the connector as per business details",
"nullable": true
},
"connector_account_details": {
"type": "object",
"description": "Account details of the Connector. You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Useful for storing additional, structured information on an object.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pm.test(
let jsonData = {};
try {
jsonData = pm.response.json();
} catch (e) {}
} catch (e) { }

// pm.collectionVariables - Set merchant_connector_id as variable for jsonData.merchant_connector_id
if (jsonData?.merchant_connector_id) {
Expand All @@ -37,3 +37,11 @@ if (jsonData?.merchant_connector_id) {
"INFO - Unable to assign variable {{merchant_connector_id}}, as jsonData.merchant_connector_id is undefined.",
);
}

// Validate if the connector label is the one that is passed in the request
pm.test(
"[POST]::/accounts/:account_id/connectors - connector_label is not autogenerated",
function () {
pm.expect(jsonData.connector_label).to.eql("first_stripe_connector")
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"connector_name": "stripe",
"business_country": "US",
"business_label": "default",
"connector_label": "first_stripe_connector",
"connector_account_details": {
"auth_type": "HeaderKey",
"api_key": "{{connector_api_key}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pm.test(
let jsonData = {};
try {
jsonData = pm.response.json();
} catch (e) {}
} catch (e) { }

// pm.collectionVariables - Set merchant_connector_id as variable for jsonData.merchant_connector_id
if (jsonData?.merchant_connector_id) {
Expand All @@ -37,3 +37,11 @@ if (jsonData?.merchant_connector_id) {
"INFO - Unable to assign variable {{merchant_connector_id}}, as jsonData.merchant_connector_id is undefined.",
);
}

// Validate if the connector label is the one that is passed in the request
pm.test(
"[POST]::/accounts/:account_id/connectors - connector_label is not autogenerated",
function () {
pm.expect(jsonData.connector_label).to.eql("updated_stripe_connector")
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"auth_type": "HeaderKey",
"api_key": "{{connector_api_key}}"
},
"connector_label": "updated_stripe_connector",
"test_mode": false,
"disabled": false,
"payment_methods_enabled": [
Expand Down
Loading