mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
feat(core): add runtime flag to disable dummy connector (#2100)
This commit is contained in:
@ -316,6 +316,7 @@ trustpay = {payment_method = "card,bank_redirect,wallet"}
|
|||||||
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
|
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
|
||||||
|
|
||||||
[dummy_connector]
|
[dummy_connector]
|
||||||
|
enabled = true # Whether dummy connector is enabled or not
|
||||||
payment_ttl = 172800 # Time to live for dummy connector payment in redis
|
payment_ttl = 172800 # Time to live for dummy connector payment in redis
|
||||||
payment_duration = 1000 # Fake delay duration for dummy connector payment
|
payment_duration = 1000 # Fake delay duration for dummy connector payment
|
||||||
payment_tolerance = 100 # Fake delay tolerance for dummy connector payment
|
payment_tolerance = 100 # Fake delay tolerance for dummy connector payment
|
||||||
|
|||||||
@ -382,6 +382,7 @@ connector_list = "bluesnap,stax,stripe"
|
|||||||
payout_connector_list = "wise"
|
payout_connector_list = "wise"
|
||||||
|
|
||||||
[dummy_connector]
|
[dummy_connector]
|
||||||
|
enabled = true
|
||||||
payment_ttl = 172800
|
payment_ttl = 172800
|
||||||
payment_duration = 1000
|
payment_duration = 1000
|
||||||
payment_tolerance = 100
|
payment_tolerance = 100
|
||||||
|
|||||||
@ -207,6 +207,7 @@ trustpay = {payment_method = "card,bank_redirect,wallet"}
|
|||||||
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
|
stripe = {payment_method = "card,bank_redirect,pay_later,wallet,bank_debit"}
|
||||||
|
|
||||||
[dummy_connector]
|
[dummy_connector]
|
||||||
|
enabled = true
|
||||||
payment_ttl = 172800
|
payment_ttl = 172800
|
||||||
payment_duration = 1000
|
payment_duration = 1000
|
||||||
payment_tolerance = 100
|
payment_tolerance = 100
|
||||||
|
|||||||
@ -164,6 +164,7 @@ where
|
|||||||
#[cfg(feature = "dummy_connector")]
|
#[cfg(feature = "dummy_connector")]
|
||||||
#[derive(Debug, Deserialize, Clone, Default)]
|
#[derive(Debug, Deserialize, Clone, Default)]
|
||||||
pub struct DummyConnector {
|
pub struct DummyConnector {
|
||||||
|
pub enabled: bool,
|
||||||
pub payment_ttl: i64,
|
pub payment_ttl: i64,
|
||||||
pub payment_duration: u64,
|
pub payment_duration: u64,
|
||||||
pub payment_tolerance: u64,
|
pub payment_tolerance: u64,
|
||||||
|
|||||||
@ -17,7 +17,7 @@ use crate::{
|
|||||||
utils as core_utils,
|
utils as core_utils,
|
||||||
},
|
},
|
||||||
db::StorageInterface,
|
db::StorageInterface,
|
||||||
routes::metrics,
|
routes::{metrics, AppState},
|
||||||
services::{self, api as service_api},
|
services::{self, api as service_api},
|
||||||
types::{
|
types::{
|
||||||
self, api,
|
self, api,
|
||||||
@ -547,12 +547,18 @@ fn validate_certificate_in_mca_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_payment_connector(
|
pub async fn create_payment_connector(
|
||||||
store: &dyn StorageInterface,
|
state: &AppState,
|
||||||
req: api::MerchantConnectorCreate,
|
req: api::MerchantConnectorCreate,
|
||||||
merchant_id: &String,
|
merchant_id: &String,
|
||||||
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
|
) -> RouterResponse<api_models::admin::MerchantConnectorResponse> {
|
||||||
let key_store = store
|
#[cfg(feature = "dummy_connector")]
|
||||||
.get_merchant_key_store_by_merchant_id(merchant_id, &store.get_master_key().to_vec().into())
|
validate_dummy_connector_enabled(state, &req.connector_name).await?;
|
||||||
|
let key_store = state
|
||||||
|
.store
|
||||||
|
.get_merchant_key_store_by_merchant_id(
|
||||||
|
merchant_id,
|
||||||
|
&state.store.get_master_key().to_vec().into(),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||||
|
|
||||||
@ -561,7 +567,8 @@ pub async fn create_payment_connector(
|
|||||||
.map(validate_certificate_in_mca_metadata)
|
.map(validate_certificate_in_mca_metadata)
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let merchant_account = store
|
let merchant_account = state
|
||||||
|
.store
|
||||||
.find_merchant_account_by_merchant_id(merchant_id, &key_store)
|
.find_merchant_account_by_merchant_id(merchant_id, &key_store)
|
||||||
.await
|
.await
|
||||||
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
|
||||||
@ -624,7 +631,7 @@ pub async fn create_payment_connector(
|
|||||||
req.business_label.as_ref(),
|
req.business_label.as_ref(),
|
||||||
&merchant_account,
|
&merchant_account,
|
||||||
req.profile_id.as_ref(),
|
req.profile_id.as_ref(),
|
||||||
store,
|
&*state.store,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -671,7 +678,8 @@ pub async fn create_payment_connector(
|
|||||||
profile_id: Some(profile_id.clone()),
|
profile_id: Some(profile_id.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mca = store
|
let mca = state
|
||||||
|
.store
|
||||||
.insert_merchant_connector_account(merchant_connector_account, &key_store)
|
.insert_merchant_connector_account(merchant_connector_account, &key_store)
|
||||||
.await
|
.await
|
||||||
.to_duplicate_response(
|
.to_duplicate_response(
|
||||||
@ -1379,3 +1387,28 @@ pub(crate) fn validate_auth_type(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "dummy_connector")]
|
||||||
|
pub async fn validate_dummy_connector_enabled(
|
||||||
|
state: &AppState,
|
||||||
|
connector_name: &api_enums::Connector,
|
||||||
|
) -> Result<(), errors::ApiErrorResponse> {
|
||||||
|
if !state.conf.dummy_connector.enabled
|
||||||
|
&& matches!(
|
||||||
|
connector_name,
|
||||||
|
api_enums::Connector::DummyConnector1
|
||||||
|
| api_enums::Connector::DummyConnector2
|
||||||
|
| api_enums::Connector::DummyConnector3
|
||||||
|
| api_enums::Connector::DummyConnector4
|
||||||
|
| api_enums::Connector::DummyConnector5
|
||||||
|
| api_enums::Connector::DummyConnector6
|
||||||
|
| api_enums::Connector::DummyConnector7
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Err(errors::ApiErrorResponse::InvalidRequestData {
|
||||||
|
message: "Invalid connector name".to_string(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -180,7 +180,7 @@ pub async fn payment_connector_create(
|
|||||||
state.get_ref(),
|
state.get_ref(),
|
||||||
&req,
|
&req,
|
||||||
json_payload.into_inner(),
|
json_payload.into_inner(),
|
||||||
|state, _, req| create_payment_connector(&*state.store, req, &merchant_id),
|
|state, _, req| create_payment_connector(state, req, &merchant_id),
|
||||||
&auth::AdminApiAuth,
|
&auth::AdminApiAuth,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@ -187,6 +187,7 @@ mollie = {long_lived_token = false, payment_method = "card"}
|
|||||||
braintree = { long_lived_token = false, payment_method = "card" }
|
braintree = { long_lived_token = false, payment_method = "card" }
|
||||||
|
|
||||||
[dummy_connector]
|
[dummy_connector]
|
||||||
|
enabled = true
|
||||||
payment_ttl = 172800
|
payment_ttl = 172800
|
||||||
payment_duration = 1000
|
payment_duration = 1000
|
||||||
payment_tolerance = 100
|
payment_tolerance = 100
|
||||||
|
|||||||
Reference in New Issue
Block a user