mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 11:24:45 +08:00
feat(router): allow enabling/disabling of outgoing webhooks based on env configuration (#476)
This commit is contained in:
@ -49,6 +49,9 @@ cards = ["stripe","adyen","authorizedotnet","checkout","braintree","aci","shift4
|
||||
max_attempts = 10
|
||||
max_age = 365
|
||||
|
||||
[webhooks]
|
||||
outgoing_enabled = true
|
||||
|
||||
[eph_key]
|
||||
validity = 1
|
||||
|
||||
|
||||
@ -97,6 +97,9 @@ locker_decryption_key2 = "" # private key 2 in pem format, corresponding public
|
||||
max_attempts = 10 # Number of refund attempts allowed
|
||||
max_age = 365 # Max age of a refund in days.
|
||||
|
||||
[webhooks]
|
||||
outgoing_enabled = true
|
||||
|
||||
# Validity of an Ephemeral Key in Hours
|
||||
[eph_key]
|
||||
validity = 1
|
||||
|
||||
@ -50,6 +50,7 @@ pub struct Settings {
|
||||
#[cfg(feature = "kv_store")]
|
||||
pub drainer: DrainerSettings,
|
||||
pub jwekey: Jwekey,
|
||||
pub webhooks: WebhooksSettings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
@ -195,6 +196,12 @@ pub struct DrainerSettings {
|
||||
pub max_read_count: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct WebhooksSettings {
|
||||
pub outgoing_enabled: bool,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new() -> ApplicationResult<Self> {
|
||||
Self::with_config_path(None)
|
||||
|
||||
@ -72,6 +72,7 @@ async fn payments_incoming_webhook_flow(
|
||||
.change_context(errors::WebhooksFlowError::PaymentsCoreFailed)?;
|
||||
|
||||
create_event_and_trigger_outgoing_webhook(
|
||||
state,
|
||||
merchant_account,
|
||||
event_type,
|
||||
enums::EventClass::Payments,
|
||||
@ -79,7 +80,6 @@ async fn payments_incoming_webhook_flow(
|
||||
payment_id,
|
||||
enums::EventObjectType::PaymentDetails,
|
||||
api::OutgoingWebhookContent::PaymentDetails(payments_response),
|
||||
state.store,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@ -93,6 +93,7 @@ async fn payments_incoming_webhook_flow(
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[instrument(skip_all)]
|
||||
async fn create_event_and_trigger_outgoing_webhook(
|
||||
state: AppState,
|
||||
merchant_account: storage::MerchantAccount,
|
||||
event_type: enums::EventType,
|
||||
event_class: enums::EventClass,
|
||||
@ -100,12 +101,7 @@ async fn create_event_and_trigger_outgoing_webhook(
|
||||
primary_object_id: String,
|
||||
primary_object_type: enums::EventObjectType,
|
||||
content: api::OutgoingWebhookContent,
|
||||
db: Box<dyn StorageInterface>,
|
||||
) -> CustomResult<(), errors::WebhooksFlowError> {
|
||||
let arbiter = actix::Arbiter::try_current()
|
||||
.ok_or(errors::WebhooksFlowError::ForkFlowFailed)
|
||||
.into_report()?;
|
||||
|
||||
let new_event = storage::EventNew {
|
||||
event_id: generate_id(consts::ID_LENGTH, "evt"),
|
||||
event_type,
|
||||
@ -116,26 +112,34 @@ async fn create_event_and_trigger_outgoing_webhook(
|
||||
primary_object_type,
|
||||
};
|
||||
|
||||
let event = db
|
||||
let event = state
|
||||
.store
|
||||
.insert_event(new_event)
|
||||
.await
|
||||
.change_context(errors::WebhooksFlowError::WebhookEventCreationFailed)?;
|
||||
|
||||
let outgoing_webhook = api::OutgoingWebhook {
|
||||
merchant_id: merchant_account.merchant_id.clone(),
|
||||
event_id: event.event_id,
|
||||
event_type: event.event_type.foreign_into(),
|
||||
content,
|
||||
timestamp: event.created_at,
|
||||
};
|
||||
if state.conf.webhooks.outgoing_enabled {
|
||||
let arbiter = actix::Arbiter::try_current()
|
||||
.ok_or(errors::WebhooksFlowError::ForkFlowFailed)
|
||||
.into_report()?;
|
||||
|
||||
arbiter.spawn(async move {
|
||||
let result = trigger_webhook_to_merchant(merchant_account, outgoing_webhook, db).await;
|
||||
let outgoing_webhook = api::OutgoingWebhook {
|
||||
merchant_id: merchant_account.merchant_id.clone(),
|
||||
event_id: event.event_id,
|
||||
event_type: event.event_type.foreign_into(),
|
||||
content,
|
||||
timestamp: event.created_at,
|
||||
};
|
||||
|
||||
if let Err(e) = result {
|
||||
logger::error!(?e);
|
||||
}
|
||||
});
|
||||
arbiter.spawn(async move {
|
||||
let result =
|
||||
trigger_webhook_to_merchant(merchant_account, outgoing_webhook, state.store).await;
|
||||
|
||||
if let Err(e) = result {
|
||||
logger::error!(?e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -45,6 +45,9 @@ locker_encryption_key2 = ""
|
||||
locker_decryption_key1 = ""
|
||||
locker_decryption_key2 = ""
|
||||
|
||||
[webhooks]
|
||||
outgoing_enabled = true
|
||||
|
||||
[connectors.aci]
|
||||
base_url = "https://eu-test.oppwa.com/"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user