mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +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:
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user