pub struct WebhookHandler { /* private fields */ }Expand description
Handler for SagaPay webhook notifications
Implementations§
Source§impl WebhookHandler
impl WebhookHandler
Sourcepub fn process_webhook(
&self,
body: &str,
signature: &str,
) -> Result<WebhookPayload, Error>
pub fn process_webhook( &self, body: &str, signature: &str, ) -> Result<WebhookPayload, Error>
Process and verify a webhook
§Example
use sagapay::{WebhookHandler, Error};
use std::collections::HashMap;
async fn handle_webhook(
headers: HashMap<String, String>,
body: &str,
) -> Result<(), Error> {
let api_secret = "your-api-secret";
let handler = WebhookHandler::new(api_secret);
// Get the signature from headers
let signature = headers.get("x-sagapay-signature")
.ok_or_else(|| Error::InvalidSignature)?;
// Process and validate the webhook
let payload = handler.process_webhook(body, signature)?;
// Handle the webhook data
println!("Transaction ID: {}", payload.id);
println!("Type: {:?}", payload.transaction_type);
println!("Status: {:?}", payload.status);
println!("Amount: {}", payload.amount);
Ok(())
}Sourcepub fn process_webhook_from_request(
&self,
headers: &HashMap<String, String>,
body: &str,
) -> Result<WebhookPayload, Error>
pub fn process_webhook_from_request( &self, headers: &HashMap<String, String>, body: &str, ) -> Result<WebhookPayload, Error>
Helper method to extract headers and process a webhook in a single step
Trait Implementations§
Source§impl Clone for WebhookHandler
impl Clone for WebhookHandler
Source§fn clone(&self) -> WebhookHandler
fn clone(&self) -> WebhookHandler
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WebhookHandler
impl RefUnwindSafe for WebhookHandler
impl Send for WebhookHandler
impl Sync for WebhookHandler
impl Unpin for WebhookHandler
impl UnwindSafe for WebhookHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more