Files
2022-12-03 10:48:51 +05:30

25 lines
767 B
Rust

use crate::{
db::{get_and_deserialize_key, StorageInterface},
types::api,
};
fn default_webhook_config() -> api::MerchantWebhookConfig {
std::collections::HashSet::from([api::IncomingWebhookEvent::PaymentIntentSuccess])
}
pub async fn lookup_webhook_event(
db: &dyn StorageInterface,
connector_id: &str,
merchant_id: &str,
event: &api::IncomingWebhookEvent,
) -> bool {
let redis_key = format!("whconf_{}_{}", merchant_id, connector_id);
let webhook_config: api::MerchantWebhookConfig =
get_and_deserialize_key(db, &redis_key, "MerchantWebhookConfig")
.await
.map(|h| &h | &default_webhook_config())
.unwrap_or_else(|_| default_webhook_config());
webhook_config.contains(event)
}