fix: merchant webhook config should be looked up in config table instead of redis (#1241)

This commit is contained in:
Hrithikesh
2023-05-23 20:24:38 +05:30
committed by GitHub
parent 3857d06627
commit 48e537568d
2 changed files with 23 additions and 4 deletions

View File

@ -20,11 +20,28 @@ pub async fn lookup_webhook_event(
event: &api::IncomingWebhookEvent,
) -> bool {
let redis_key = format!("whconf_{merchant_id}_{connector_id}");
let webhook_config: api::MerchantWebhookConfig =
let merchant_webhook_config_result =
get_and_deserialize_key(db, &redis_key, "MerchantWebhookConfig")
.await
.map(|h| &h | &default_webhook_config())
.unwrap_or_else(|_| default_webhook_config());
.map(|h| &h | &default_webhook_config());
webhook_config.contains(event)
match merchant_webhook_config_result {
Ok(merchant_webhook_config) => merchant_webhook_config.contains(event),
Err(..) => {
//if failed to fetch from redis. fetch from db and populate redis
db.find_config_by_key_cached(&redis_key)
.await
.map(|config| {
if let Ok(set) =
serde_json::from_str::<api::MerchantWebhookConfig>(&config.config)
{
&set | &default_webhook_config()
} else {
default_webhook_config()
}
})
.unwrap_or_else(|_| default_webhook_config())
.contains(event)
}
}
}