enhance(router/webhooks): expose additional incoming request details to webhooks flow (#637)

This commit is contained in:
ItsMeShashank
2023-02-24 17:53:16 +05:30
committed by GitHub
parent aaf372505c
commit 1b3b7f5bc6
21 changed files with 144 additions and 129 deletions

View File

@ -656,18 +656,16 @@ fn get_webhook_object_from_body(
impl api::IncomingWebhook for Adyen {
fn get_webhook_source_verification_algorithm(
&self,
_headers: &actix_web::http::header::HeaderMap,
_body: &[u8],
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Box<dyn crypto::VerifySignature + Send>, errors::ConnectorError> {
Ok(Box::new(crypto::HmacSha256))
}
fn get_webhook_source_verification_signature(
&self,
_headers: &actix_web::http::header::HeaderMap,
body: &[u8],
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
let notif_item = get_webhook_object_from_body(body)
let notif_item = get_webhook_object_from_body(request.body)
.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;
let base64_signature = notif_item.additional_data.hmac_signature;
@ -682,12 +680,11 @@ impl api::IncomingWebhook for Adyen {
fn get_webhook_source_verification_message(
&self,
_headers: &actix_web::http::header::HeaderMap,
body: &[u8],
request: &api::IncomingWebhookRequestDetails<'_>,
_merchant_id: &str,
_secret: &[u8],
) -> CustomResult<Vec<u8>, errors::ConnectorError> {
let notif = get_webhook_object_from_body(body)
let notif = get_webhook_object_from_body(request.body)
.change_context(errors::ConnectorError::WebhookSourceVerificationFailed)?;
let message = format!(
@ -721,9 +718,9 @@ impl api::IncomingWebhook for Adyen {
fn get_webhook_object_reference_id(
&self,
body: &[u8],
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<String, errors::ConnectorError> {
let notif = get_webhook_object_from_body(body)
let notif = get_webhook_object_from_body(request.body)
.change_context(errors::ConnectorError::WebhookReferenceIdNotFound)?;
Ok(notif.psp_reference)
@ -731,9 +728,9 @@ impl api::IncomingWebhook for Adyen {
fn get_webhook_event_type(
&self,
body: &[u8],
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> {
let notif = get_webhook_object_from_body(body)
let notif = get_webhook_object_from_body(request.body)
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
Ok(match notif.event_code.as_str() {
@ -744,9 +741,9 @@ impl api::IncomingWebhook for Adyen {
fn get_webhook_resource_object(
&self,
body: &[u8],
request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<serde_json::Value, errors::ConnectorError> {
let notif = get_webhook_object_from_body(body)
let notif = get_webhook_object_from_body(request.body)
.change_context(errors::ConnectorError::WebhookEventTypeNotFound)?;
let response: adyen::AdyenResponse = notif.into();
@ -760,6 +757,7 @@ impl api::IncomingWebhook for Adyen {
fn get_webhook_api_response(
&self,
_request: &api::IncomingWebhookRequestDetails<'_>,
) -> CustomResult<services::api::ApplicationResponse<serde_json::Value>, errors::ConnectorError>
{
Ok(services::api::ApplicationResponse::TextPlain(