-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compatibility): add support for stripe compatible webhooks (#1728)
- Loading branch information
1 parent
14c2d72
commit 87ae99f
Showing
8 changed files
with
155 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use api_models::webhooks; | ||
use common_utils::{crypto::SignMessage, ext_traits}; | ||
use error_stack::ResultExt; | ||
use serde::Serialize; | ||
|
||
use crate::{core::errors, headers, services::request::Maskable}; | ||
|
||
pub trait OutgoingWebhookType: | ||
Serialize + From<webhooks::OutgoingWebhook> + Sync + Send + std::fmt::Debug | ||
{ | ||
fn get_outgoing_webhooks_signature( | ||
&self, | ||
payment_response_hash_key: Option<String>, | ||
) -> errors::CustomResult<Option<String>, errors::WebhooksFlowError>; | ||
|
||
fn add_webhook_header(header: &mut Vec<(String, Maskable<String>)>, signature: String); | ||
} | ||
|
||
impl OutgoingWebhookType for webhooks::OutgoingWebhook { | ||
fn get_outgoing_webhooks_signature( | ||
&self, | ||
payment_response_hash_key: Option<String>, | ||
) -> errors::CustomResult<Option<String>, errors::WebhooksFlowError> { | ||
let webhook_signature_payload = | ||
ext_traits::Encode::<serde_json::Value>::encode_to_string_of_json(self) | ||
.change_context(errors::WebhooksFlowError::OutgoingWebhookEncodingFailed) | ||
.attach_printable("failed encoding outgoing webhook payload")?; | ||
|
||
Ok(payment_response_hash_key | ||
.map(|key| { | ||
common_utils::crypto::HmacSha512::sign_message( | ||
&common_utils::crypto::HmacSha512, | ||
key.as_bytes(), | ||
webhook_signature_payload.as_bytes(), | ||
) | ||
}) | ||
.transpose() | ||
.change_context(errors::WebhooksFlowError::OutgoingWebhookSigningFailed) | ||
.attach_printable("Failed to sign the message")? | ||
.map(hex::encode)) | ||
} | ||
fn add_webhook_header(header: &mut Vec<(String, Maskable<String>)>, signature: String) { | ||
header.push((headers::X_WEBHOOK_SIGNATURE.to_string(), signature.into())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters