mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
Frm integration with hyperswitch (#857)
Co-authored-by: Arun Raj M <jarnura47@gmail.com> Co-authored-by: SamraatBansal <55536657+SamraatBansal@users.noreply.github.com>
This commit is contained in:
@ -372,6 +372,17 @@ pub struct MerchantConnectorCreate {
|
||||
/// 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>,
|
||||
/// contains the frm configs for the merchant connector
|
||||
#[schema(example = json!([
|
||||
{
|
||||
"frm_enabled_pms" : ["card"],
|
||||
"frm_enabled_pm_types" : ["credit"],
|
||||
"frm_enabled_gateways" : ["stripe"],
|
||||
"frm_action": "cancel_txn",
|
||||
"frm_preferred_flow_type" : "pre"
|
||||
}
|
||||
]))]
|
||||
pub frm_configs: Option<FrmConfigs>,
|
||||
|
||||
/// Business Country of the connector
|
||||
#[schema(example = "US")]
|
||||
@ -465,6 +476,18 @@ pub struct MerchantConnectorResponse {
|
||||
/// Business Sub label of the merchant
|
||||
#[schema(example = "chase")]
|
||||
pub business_sub_label: Option<String>,
|
||||
|
||||
/// contains the frm configs for the merchant connector
|
||||
#[schema(example = json!([
|
||||
{
|
||||
"frm_enabled_pms" : ["card"],
|
||||
"frm_enabled_pm_types" : ["credit"],
|
||||
"frm_enabled_gateways" : ["stripe"],
|
||||
"frm_action": "cancel_txn",
|
||||
"frm_preferred_flow_type" : "pre"
|
||||
}
|
||||
]))]
|
||||
pub frm_configs: Option<FrmConfigs>,
|
||||
}
|
||||
|
||||
/// 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."
|
||||
@ -522,8 +545,30 @@ pub struct MerchantConnectorUpdate {
|
||||
/// 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>,
|
||||
|
||||
/// contains the frm configs for the merchant connector
|
||||
#[schema(example = json!([
|
||||
{
|
||||
"frm_enabled_pms" : ["card"],
|
||||
"frm_enabled_pm_types" : ["credit"],
|
||||
"frm_enabled_gateways" : ["stripe"],
|
||||
"frm_action": "cancel_txn",
|
||||
"frm_preferred_flow_type" : "pre"
|
||||
}
|
||||
]))]
|
||||
pub frm_configs: Option<FrmConfigs>,
|
||||
}
|
||||
|
||||
///Details of FrmConfigs are mentioned here... it should be passed in payment connector create api call, and stored in merchant_connector_table
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct FrmConfigs {
|
||||
pub frm_enabled_pms: Option<Vec<String>>,
|
||||
pub frm_enabled_pm_types: Option<Vec<String>>,
|
||||
pub frm_enabled_gateways: Option<Vec<String>>,
|
||||
pub frm_action: api_enums::FrmAction, //What should be the action if FRM declines the txn (autorefund/cancel txn/manual review)
|
||||
pub frm_preferred_flow_type: api_enums::FrmPreferredFlowTypes,
|
||||
}
|
||||
/// Details of all the payment methods enabled for the connector for the given merchant account
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
||||
@ -842,6 +842,40 @@ pub enum DisputeStatus {
|
||||
DisputeLost,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumString,
|
||||
frunk::LabelledGeneric,
|
||||
ToSchema,
|
||||
)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum FrmAction {
|
||||
CancelTxn,
|
||||
AutoRefund,
|
||||
ManualReview,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumString,
|
||||
frunk::LabelledGeneric,
|
||||
ToSchema,
|
||||
)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum FrmPreferredFlowTypes {
|
||||
Pre,
|
||||
Post,
|
||||
}
|
||||
#[derive(Debug, Eq, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct UnresolvedResponseReason {
|
||||
pub code: String,
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use api_models::admin::PrimaryBusinessDetails;
|
||||
use common_utils::ext_traits::ValueExt;
|
||||
use error_stack::{report, FutureExt, IntoReport, ResultExt};
|
||||
use masking::Secret; //PeekInterface
|
||||
use storage_models::{enums, merchant_account};
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -401,7 +402,15 @@ pub async fn create_payment_connector(
|
||||
field_name: "connector_account_details".to_string(),
|
||||
expected_format: "auth_type and api_key".to_string(),
|
||||
})?;
|
||||
|
||||
let frm_configs = match req.frm_configs {
|
||||
Some(frm_value) => {
|
||||
let configs_for_frm_value: serde_json::Value =
|
||||
utils::Encode::<api_models::admin::FrmConfigs>::encode_to_value(&frm_value)
|
||||
.change_context(errors::ApiErrorResponse::ConfigNotFound)?;
|
||||
Some(Secret::new(configs_for_frm_value))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let merchant_connector_account = storage::MerchantConnectorAccountNew {
|
||||
merchant_id: Some(merchant_id.to_string()),
|
||||
connector_type: Some(req.connector_type.foreign_into()),
|
||||
@ -412,6 +421,7 @@ pub async fn create_payment_connector(
|
||||
test_mode: req.test_mode,
|
||||
disabled: req.disabled,
|
||||
metadata: req.metadata,
|
||||
frm_configs,
|
||||
connector_label: connector_label.clone(),
|
||||
business_country,
|
||||
business_label,
|
||||
@ -516,7 +526,15 @@ pub async fn update_payment_connector(
|
||||
})
|
||||
.collect::<Vec<serde_json::Value>>()
|
||||
});
|
||||
|
||||
let frm_configs = match req.frm_configs.as_ref() {
|
||||
Some(frm_value) => {
|
||||
let configs_for_frm_value: serde_json::Value =
|
||||
utils::Encode::<api_models::admin::FrmConfigs>::encode_to_value(&frm_value)
|
||||
.change_context(errors::ApiErrorResponse::ConfigNotFound)?;
|
||||
Some(Secret::new(configs_for_frm_value))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
let payment_connector = storage::MerchantConnectorAccountUpdate::Update {
|
||||
merchant_id: Some(merchant_id.to_string()),
|
||||
connector_type: Some(req.connector_type.foreign_into()),
|
||||
@ -526,6 +544,7 @@ pub async fn update_payment_connector(
|
||||
test_mode: req.test_mode,
|
||||
disabled: req.disabled,
|
||||
metadata: req.metadata,
|
||||
frm_configs,
|
||||
};
|
||||
|
||||
let updated_mca = db
|
||||
|
||||
@ -50,7 +50,6 @@ impl
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAuthorizeRouterData {
|
||||
async fn decide_flows<'a>(
|
||||
|
||||
@ -287,6 +287,7 @@ impl MerchantConnectorAccountInterface for MockDb {
|
||||
merchant_connector_id: t.merchant_connector_id,
|
||||
payment_methods_enabled: t.payment_methods_enabled,
|
||||
metadata: t.metadata,
|
||||
frm_configs: t.frm_configs,
|
||||
connector_type: t
|
||||
.connector_type
|
||||
.unwrap_or(crate::types::storage::enums::ConnectorType::FinOperations),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use api_models::enums as api_enums;
|
||||
use common_utils::ext_traits::ValueExt;
|
||||
use error_stack::ResultExt;
|
||||
use masking::Secret;
|
||||
use masking::{PeekInterface, Secret};
|
||||
use storage_models::enums as storage_enums;
|
||||
|
||||
use crate::{
|
||||
@ -535,7 +535,20 @@ impl ForeignTryFrom<storage_models::merchant_connector_account::MerchantConnecto
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)?,
|
||||
None => None,
|
||||
};
|
||||
|
||||
let frm_configs = match item.frm_configs {
|
||||
Some(frm_value) => {
|
||||
let configs_for_frm : api_models::admin::FrmConfigs = frm_value
|
||||
.peek()
|
||||
.clone()
|
||||
.parse_value("FrmConfigs")
|
||||
.change_context(errors::ApiErrorResponse::InvalidDataFormat {
|
||||
field_name: "frm_configs".to_string(),
|
||||
expected_format: "\"frm_configs\" : { \"frm_enabled_pms\" : [\"card\"], \"frm_enabled_pm_types\" : [\"credit\"], \"frm_enabled_gateways\" : [\"stripe\"], \"frm_action\": \"cancel_txn\", \"frm_preferred_flow_type\" : \"pre\" }".to_string(),
|
||||
})?;
|
||||
Some(configs_for_frm)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
Ok(Self {
|
||||
connector_type: item.connector_type.foreign_into(),
|
||||
connector_name: item.connector_name,
|
||||
@ -549,6 +562,7 @@ impl ForeignTryFrom<storage_models::merchant_connector_account::MerchantConnecto
|
||||
business_country: item.business_country,
|
||||
business_label: item.business_label,
|
||||
business_sub_label: item.business_sub_label,
|
||||
frm_configs,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ pub struct MerchantConnectorAccount {
|
||||
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
|
||||
pub connector_type: storage_enums::ConnectorType,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub frm_configs: Option<Secret<serde_json::Value>>, //Option<FrmConfigs>
|
||||
pub connector_label: String,
|
||||
pub business_country: storage_enums::CountryCode,
|
||||
pub business_label: String,
|
||||
@ -46,6 +47,7 @@ pub struct MerchantConnectorAccountNew {
|
||||
pub merchant_connector_id: String,
|
||||
pub payment_methods_enabled: Option<Vec<serde_json::Value>>,
|
||||
pub metadata: Option<pii::SecretSerdeValue>,
|
||||
pub frm_configs: Option<Secret<serde_json::Value>>,
|
||||
pub connector_label: String,
|
||||
pub business_country: storage_enums::CountryCode,
|
||||
pub business_label: String,
|
||||
@ -63,6 +65,7 @@ pub enum MerchantConnectorAccountUpdate {
|
||||
merchant_connector_id: Option<String>,
|
||||
payment_methods_enabled: Option<Vec<serde_json::Value>>,
|
||||
metadata: Option<pii::SecretSerdeValue>,
|
||||
frm_configs: Option<Secret<serde_json::Value>>,
|
||||
},
|
||||
}
|
||||
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
|
||||
@ -76,6 +79,7 @@ pub struct MerchantConnectorAccountUpdateInternal {
|
||||
merchant_connector_id: Option<String>,
|
||||
payment_methods_enabled: Option<Vec<serde_json::Value>>,
|
||||
metadata: Option<pii::SecretSerdeValue>,
|
||||
frm_configs: Option<Secret<serde_json::Value>>,
|
||||
}
|
||||
|
||||
impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInternal {
|
||||
@ -90,6 +94,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
|
||||
merchant_connector_id,
|
||||
payment_methods_enabled,
|
||||
metadata,
|
||||
frm_configs,
|
||||
} => Self {
|
||||
merchant_id,
|
||||
connector_type,
|
||||
@ -99,6 +104,7 @@ impl From<MerchantConnectorAccountUpdate> for MerchantConnectorAccountUpdateInte
|
||||
merchant_connector_id,
|
||||
payment_methods_enabled,
|
||||
metadata,
|
||||
frm_configs,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,6 +243,7 @@ diesel::table! {
|
||||
payment_methods_enabled -> Nullable<Array<Nullable<Json>>>,
|
||||
connector_type -> ConnectorType,
|
||||
metadata -> Nullable<Jsonb>,
|
||||
frm_configs -> Nullable<Jsonb>,
|
||||
connector_label -> Varchar,
|
||||
business_country -> CountryCode,
|
||||
business_label -> Varchar,
|
||||
|
||||
@ -0,0 +1 @@
|
||||
ALTER TABLE "merchant_connector_account" DROP COLUMN frm_configs;
|
||||
@ -0,0 +1 @@
|
||||
ALTER TABLE "merchant_connector_account" ADD COLUMN frm_configs jsonb;
|
||||
Reference in New Issue
Block a user