mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
initial commit
This commit is contained in:
16
crates/router/src/core/webhooks/transformers.rs
Normal file
16
crates/router/src/core/webhooks/transformers.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use crate::{core::errors, types::storage::enums};
|
||||
|
||||
impl TryFrom<enums::IntentStatus> for enums::EventType {
|
||||
type Error = errors::ValidationError;
|
||||
|
||||
fn try_from(value: enums::IntentStatus) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
enums::IntentStatus::Succeeded => Ok(Self::PaymentSucceeded),
|
||||
_ => Err(errors::ValidationError::IncorrectValueProvided {
|
||||
field_name: "intent_status",
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
22
crates/router/src/core/webhooks/utils.rs
Normal file
22
crates/router/src/core/webhooks/utils.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use error_stack::ResultExt;
|
||||
|
||||
use crate::{
|
||||
connection::RedisPool,
|
||||
core::errors::{self, CustomResult},
|
||||
types::api,
|
||||
};
|
||||
|
||||
pub async fn lookup_webhook_event(
|
||||
connector_id: &str,
|
||||
merchant_id: &str,
|
||||
event: &str,
|
||||
conn: RedisPool,
|
||||
) -> CustomResult<Option<api::WebhookFlow>, errors::WebhooksFlowError> {
|
||||
let redis_key = format!("whconf_{}_{}", merchant_id, connector_id);
|
||||
let mut webhook_config: api::MerchantWebhookConfig = conn
|
||||
.get_and_deserialize_key(&redis_key, "MerchantWebhookConfig")
|
||||
.await
|
||||
.change_context(errors::WebhooksFlowError::MerchantConfigNotFound)?;
|
||||
|
||||
Ok(webhook_config.remove(event))
|
||||
}
|
||||
Reference in New Issue
Block a user