refactor(router): remove connector_account_details and connector_webhook_details in merchant_connector_account list response (#5457)

This commit is contained in:
Sai Harsha Vardhan
2024-07-29 14:37:16 +05:30
committed by GitHub
parent db26d32d84
commit 45a149418f
6 changed files with 322 additions and 3 deletions

View File

@ -1594,7 +1594,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MerchantConnectorResponse"
"$ref": "#/components/schemas/MerchantConnectorListResponse"
}
}
}
@ -12033,6 +12033,156 @@
}
}
},
"MerchantConnectorListResponse": {
"type": "object",
"required": [
"connector_type",
"connector_name",
"merchant_connector_id",
"status"
],
"properties": {
"connector_type": {
"$ref": "#/components/schemas/ConnectorType"
},
"connector_name": {
"$ref": "#/components/schemas/Connector"
},
"connector_label": {
"type": "string",
"description": "A unique label to identify the connector account created under a business profile",
"example": "stripe_US_travel",
"nullable": true
},
"merchant_connector_id": {
"type": "string",
"description": "Unique ID of the merchant connector account",
"example": "mca_5apGeP94tMts6rg3U3kR"
},
"profile_id": {
"type": "string",
"description": "Identifier for the business profile, if not provided default will be chosen from merchant account",
"nullable": true,
"maxLength": 64
},
"payment_methods_enabled": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PaymentMethodsEnabled"
},
"description": "An object containing the details about the payment methods that need to be enabled under this merchant connector account",
"example": [
{
"accepted_countries": {
"list": [
"FR",
"DE",
"IN"
],
"type": "disable_only"
},
"accepted_currencies": {
"list": [
"USD",
"EUR"
],
"type": "enable_only"
},
"installment_payment_enabled": true,
"maximum_amount": 68607706,
"minimum_amount": 1,
"payment_method": "wallet",
"payment_method_issuers": [
"labore magna ipsum",
"aute"
],
"payment_method_types": [
"upi_collect",
"upi_intent"
],
"payment_schemes": [
"Discover",
"Discover"
],
"recurring_enabled": true
}
],
"nullable": true
},
"metadata": {
"type": "object",
"description": "You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.",
"nullable": true
},
"test_mode": {
"type": "boolean",
"description": "A boolean value to indicate if the connector is in Test mode. By default, its value is false.",
"default": false,
"example": false,
"nullable": true
},
"disabled": {
"type": "boolean",
"description": "A boolean value to indicate if the connector is disabled. By default, its value is false.",
"default": false,
"example": false,
"nullable": true
},
"frm_configs": {
"type": "array",
"items": {
"$ref": "#/components/schemas/FrmConfigs"
},
"description": "Contains the frm configs for the merchant connector",
"example": "\n[{\"gateway\":\"stripe\",\"payment_methods\":[{\"payment_method\":\"card\",\"payment_method_types\":[{\"payment_method_type\":\"credit\",\"card_networks\":[\"Visa\"],\"flow\":\"pre\",\"action\":\"cancel_txn\"},{\"payment_method_type\":\"debit\",\"card_networks\":[\"Visa\"],\"flow\":\"pre\"}]}]}]\n",
"nullable": true
},
"business_country": {
"allOf": [
{
"$ref": "#/components/schemas/CountryAlpha2"
}
],
"nullable": true
},
"business_label": {
"type": "string",
"description": "The business label to which the connector account is attached. To be deprecated soon. Use the 'profile_id' instead",
"example": "travel",
"nullable": true
},
"business_sub_label": {
"type": "string",
"description": "The business sublabel to which the connector account is attached. To be deprecated soon. Use the 'profile_id' instead",
"example": "chase",
"nullable": true
},
"applepay_verified_domains": {
"type": "array",
"items": {
"type": "string"
},
"description": "identifier for the verified domains of a particular connector account",
"nullable": true
},
"pm_auth_config": {
"type": "object",
"nullable": true
},
"status": {
"$ref": "#/components/schemas/ConnectorStatus"
},
"additional_merchant_data": {
"allOf": [
{
"$ref": "#/components/schemas/AdditionalMerchantData"
}
],
"nullable": true
}
},
"additionalProperties": false
},
"MerchantConnectorResponse": {
"type": "object",
"description": "Response of creating a new Merchant Connector for the merchant account.\"",

View File

@ -1162,6 +1162,110 @@ impl MerchantConnectorResponse {
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct MerchantConnectorListResponse {
/// Type of the Connector for the financial use case. Could range from Payments to Accounting to Banking.
#[schema(value_type = ConnectorType, example = "payment_processor")]
pub connector_type: api_enums::ConnectorType,
/// Name of the Connector
#[schema(value_type = Connector, example = "stripe")]
pub connector_name: String,
/// A unique label to identify the connector account created under a business profile
#[schema(example = "stripe_US_travel")]
pub connector_label: Option<String>,
/// Unique ID of the merchant connector account
#[schema(example = "mca_5apGeP94tMts6rg3U3kR")]
pub merchant_connector_id: String,
/// Identifier for the business profile, if not provided default will be chosen from merchant account
#[schema(max_length = 64)]
pub profile_id: Option<String>,
/// An object containing the details about the payment methods that need to be enabled under this merchant connector account
#[schema(example = json!([
{
"payment_method": "wallet",
"payment_method_types": [
"upi_collect",
"upi_intent"
],
"payment_method_issuers": [
"labore magna ipsum",
"aute"
],
"payment_schemes": [
"Discover",
"Discover"
],
"accepted_currencies": {
"type": "enable_only",
"list": ["USD", "EUR"]
},
"accepted_countries": {
"type": "disable_only",
"list": ["FR", "DE","IN"]
},
"minimum_amount": 1,
"maximum_amount": 68607706,
"recurring_enabled": true,
"installment_payment_enabled": true
}
]))]
pub payment_methods_enabled: Option<Vec<PaymentMethodsEnabled>>,
/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,max_length = 255,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,
/// A boolean value to indicate if the connector is in Test mode. By default, its value is false.
#[schema(default = false, example = false)]
pub test_mode: Option<bool>,
/// A boolean value to indicate if the connector is disabled. By default, its value is false.
#[schema(default = false, example = false)]
pub disabled: Option<bool>,
/// Contains the frm configs for the merchant connector
#[schema(example = json!(consts::FRM_CONFIGS_EG))]
pub frm_configs: Option<Vec<FrmConfigs>>,
/// The business country to which the connector account is attached. To be deprecated soon. Use the 'profile_id' instead
#[schema(value_type = Option<CountryAlpha2>, example = "US")]
pub business_country: Option<api_enums::CountryAlpha2>,
///The business label to which the connector account is attached. To be deprecated soon. Use the 'profile_id' instead
#[schema(example = "travel")]
pub business_label: Option<String>,
/// The business sublabel to which the connector account is attached. To be deprecated soon. Use the 'profile_id' instead
#[schema(example = "chase")]
pub business_sub_label: Option<String>,
/// identifier for the verified domains of a particular connector account
pub applepay_verified_domains: Option<Vec<String>>,
#[schema(value_type = Option<Object>)]
pub pm_auth_config: Option<pii::SecretSerdeValue>,
#[schema(value_type = ConnectorStatus, example = "inactive")]
pub status: api_enums::ConnectorStatus,
#[schema(value_type = Option<AdditionalMerchantData>)]
pub additional_merchant_data: Option<AdditionalMerchantData>,
}
impl MerchantConnectorListResponse {
pub fn to_merchant_connector_info(&self, connector_label: &String) -> MerchantConnectorInfo {
MerchantConnectorInfo {
connector_label: connector_label.to_string(),
merchant_connector_id: self.merchant_connector_id.clone(),
}
}
}
/// Create a new Merchant Connector for the merchant account. The connector could be a payment processor / facilitator / acquirer or specialized services like Fraud / Accounting etc."
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(deny_unknown_fields)]

View File

@ -205,6 +205,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::admin::MerchantAccountDeleteResponse,
api_models::admin::MerchantConnectorDeleteResponse,
api_models::admin::MerchantConnectorResponse,
api_models::admin::MerchantConnectorListResponse,
api_models::admin::AuthenticationConnectorDetails,
api_models::admin::ExtendedCardInfoConfig,
api_models::admin::BusinessGenericLinkConfig,

View File

@ -91,7 +91,7 @@ pub async fn payment_connector_retrieve() {}
("account_id" = String, Path, description = "The unique identifier for the merchant account"),
),
responses(
(status = 200, description = "Merchant Connector list retrieved successfully", body = Vec<MerchantConnectorResponse>),
(status = 200, description = "Merchant Connector list retrieved successfully", body = Vec<MerchantConnectorListResponse>),
(status = 404, description = "Merchant Connector does not exist in records"),
(status = 401, description = "Unauthorized request")
),

View File

@ -2509,7 +2509,7 @@ pub async fn retrieve_payment_connector(
pub async fn list_payment_connectors(
state: SessionState,
merchant_id: id_type::MerchantId,
) -> RouterResponse<Vec<api_models::admin::MerchantConnectorResponse>> {
) -> RouterResponse<Vec<api_models::admin::MerchantConnectorListResponse>> {
let store = state.store.as_ref();
let key_manager_state = &(&state).into();
let key_store = store

View File

@ -922,6 +922,70 @@ impl ForeignFrom<diesel_models::cards_info::CardInfo> for api_models::cards_info
}
}
impl TryFrom<domain::MerchantConnectorAccount>
for api_models::admin::MerchantConnectorListResponse
{
type Error = error_stack::Report<errors::ApiErrorResponse>;
fn try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {
let payment_methods_enabled = match item.payment_methods_enabled {
Some(val) => serde_json::Value::Array(val)
.parse_value("PaymentMethods")
.change_context(errors::ApiErrorResponse::InternalServerError)?,
None => None,
};
let frm_configs = match item.frm_configs {
Some(frm_value) => {
let configs_for_frm : Vec<api_models::admin::FrmConfigs> = frm_value
.iter()
.map(|config| { config
.peek()
.clone()
.parse_value("FrmConfigs")
.change_context(errors::ApiErrorResponse::InvalidDataFormat {
field_name: "frm_configs".to_string(),
expected_format: r#"[{ "gateway": "stripe", "payment_methods": [{ "payment_method": "card","payment_method_types": [{"payment_method_type": "credit","card_networks": ["Visa"],"flow": "pre","action": "cancel_txn"}]}]}]"#.to_string(),
})
})
.collect::<Result<Vec<_>, _>>()?;
Some(configs_for_frm)
}
None => None,
};
let response = Self {
connector_type: item.connector_type,
connector_name: item.connector_name,
connector_label: item.connector_label,
merchant_connector_id: item.merchant_connector_id,
test_mode: item.test_mode,
disabled: item.disabled,
payment_methods_enabled,
metadata: item.metadata,
business_country: item.business_country,
business_label: item.business_label,
business_sub_label: item.business_sub_label,
frm_configs,
profile_id: item.profile_id,
applepay_verified_domains: item.applepay_verified_domains,
pm_auth_config: item.pm_auth_config,
status: item.status,
additional_merchant_data: item
.additional_merchant_data
.map(|data| {
let data = data.into_inner();
serde_json::Value::parse_value::<router_types::AdditionalMerchantData>(
data.expose(),
"AdditionalMerchantData",
)
.attach_printable("Unable to deserialize additional_merchant_data")
.change_context(errors::ApiErrorResponse::InternalServerError)
})
.transpose()?
.map(api_models::admin::AdditionalMerchantData::foreign_from),
};
Ok(response)
}
}
impl TryFrom<domain::MerchantConnectorAccount> for api_models::admin::MerchantConnectorResponse {
type Error = error_stack::Report<errors::ApiErrorResponse>;
fn try_from(item: domain::MerchantConnectorAccount) -> Result<Self, Self::Error> {