pub struct WebhookContext { /* private fields */ }Expand description
Represents verified webhook metadata after successful signature verification.
This struct is returned by verify_webhook and contains the parsed headers
from a verified webhook request. It provides both the parsed topic enum (when
the topic is a known value) and the raw topic string (always available).
§Example
use shopify_sdk::webhooks::{WebhookRequest, verify_webhook, WebhookContext};
use shopify_sdk::webhooks::WebhookTopic;
use shopify_sdk::{ShopifyConfig, ApiKey, ApiSecretKey};
use shopify_sdk::auth::oauth::hmac::compute_signature_base64;
let config = ShopifyConfig::builder()
.api_key(ApiKey::new("key").unwrap())
.api_secret_key(ApiSecretKey::new("secret").unwrap())
.build()
.unwrap();
let body = b"test";
let hmac = compute_signature_base64(body, "secret");
let request = WebhookRequest::new(
body.to_vec(),
hmac,
Some("orders/create".to_string()),
Some("example.myshopify.com".to_string()),
None,
None,
);
let context = verify_webhook(&config, &request).unwrap();
assert_eq!(context.topic(), Some(WebhookTopic::OrdersCreate));
assert_eq!(context.topic_raw(), "orders/create");Implementations§
Source§impl WebhookContext
impl WebhookContext
Sourcepub fn topic(&self) -> Option<WebhookTopic>
pub fn topic(&self) -> Option<WebhookTopic>
Returns the parsed webhook topic enum, if the topic is a known value.
Returns None for unknown or custom topics.
Sourcepub fn topic_raw(&self) -> &str
pub fn topic_raw(&self) -> &str
Returns the raw topic string as received in the header.
This is always available, even for unknown or custom topics.
Sourcepub fn shop_domain(&self) -> Option<&str>
pub fn shop_domain(&self) -> Option<&str>
Returns the shop domain, if present in the webhook headers.
Sourcepub fn api_version(&self) -> Option<&str>
pub fn api_version(&self) -> Option<&str>
Returns the API version, if present in the webhook headers.
Sourcepub fn webhook_id(&self) -> Option<&str>
pub fn webhook_id(&self) -> Option<&str>
Returns the webhook ID, if present in the webhook headers.
Trait Implementations§
Source§impl Clone for WebhookContext
impl Clone for WebhookContext
Source§fn clone(&self) -> WebhookContext
fn clone(&self) -> WebhookContext
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 moreSource§impl Debug for WebhookContext
impl Debug for WebhookContext
Source§impl PartialEq for WebhookContext
impl PartialEq for WebhookContext
impl StructuralPartialEq for WebhookContext
Auto Trait Implementations§
impl Freeze for WebhookContext
impl RefUnwindSafe for WebhookContext
impl Send for WebhookContext
impl Sync for WebhookContext
impl Unpin for WebhookContext
impl UnwindSafe for WebhookContext
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