WooWebhook class
WooCommerce Webhook Model
Represents a webhook configuration in WooCommerce. Webhooks are HTTP callbacks that are triggered by specific events in your store, allowing you to receive real-time notifications about store activities.
Webhook Structure
A webhook consists of several key components:
- Identification: Unique ID and human-readable name
- Event Subscription: Topic that determines which events trigger the webhook
- Delivery Configuration: URL where payloads are sent and optional secret for verification
- Status Management: Control whether the webhook is active, paused, or disabled
- Timestamps: Creation and modification tracking
Webhook Lifecycle
- Creation: Webhook is created with topic and delivery URL
- Activation: Status is set to 'active' to start receiving events
- Delivery: WooCommerce sends HTTP POST requests to the delivery URL
- Verification: Optional HMAC-SHA256 signature verification using the secret
- Management: Update, pause, or delete as needed
Security Features
- Secret Key: Optional HMAC-SHA256 signature for payload verification
- HTTPS Support: Delivery URLs must use HTTP or HTTPS
- Status Control: Pause or disable webhooks without deletion
Example Usage
// Create a new webhook
final webhook = WooWebhook(
name: 'Order Updates',
topic: 'order.updated',
deliveryUrl: 'https://your-app.com/webhooks/orders',
secret: 'your-secret-key',
status: WooWebhookStatus.active,
);
// Create webhook via API
final createdWebhook = await wooCommerce.createWebhook(webhook);
// Update webhook status
webhook.status = WooWebhookStatus.paused;
await wooCommerce.updateWebhook(webhook);
// Generate fake webhook for testing
final fakeWebhook = WooWebhook.fake();
Webhook Delivery Headers
When a webhook is delivered, WooCommerce includes these headers:
X-WC-Webhook-Source: Store URLX-WC-Webhook-Topic: The topic that triggered the webhookX-WC-Webhook-Resource: Resource type (e.g., 'order', 'product')X-WC-Webhook-Event: Event type (e.g., 'created', 'updated')X-WC-Webhook-Signature: HMAC-SHA256 signature (if secret is set)X-WC-Webhook-ID: Webhook's IDX-WC-Webhook-Delivery-ID: Delivery log ID
Constructors
-
WooWebhook({required String? name, required String? topic, required String? deliveryUrl, int? id, WooWebhookStatus? status = WooWebhookStatus.active, String? resource, String? event, List<
String> ? hooks, String? secret, DateTime? dateCreated, DateTime? dateCreatedGmt, DateTime? dateModified, DateTime? dateModifiedGmt}) - Creates a new WooWebhook instance
- WooWebhook.fake()
-
Creates a fake WooWebhook instance for testing purposes
factory
-
WooWebhook.fromJson(Map<
String, dynamic> json) -
Creates a WooWebhook instance from JSON data
factory
Properties
- dateCreated → DateTime?
-
Date and time when the webhook was created (local time)
final
- dateCreatedGmt → DateTime?
-
Date and time when the webhook was created (GMT)
final
- dateModified → DateTime?
-
Date and time when the webhook was last modified (local time)
final
- dateModifiedGmt → DateTime?
-
Date and time when the webhook was last modified (GMT)
final
- deliveryUrl → String?
-
URL where webhook payloads are delivered
final
- event → String?
-
The event type for this webhook
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
hooks
→ List<
String> ? -
Array of WordPress hook names bound to this webhook
final
- id → int?
-
Unique identifier for the webhook
final
- name → String?
-
Human-readable name for the webhook
final
- resource → String?
-
The resource type for this webhook
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secret → String?
-
Optional secret key for HMAC-SHA256 signature verification
final
- status → WooWebhookStatus?
-
Current status of the webhook
final
- topic → String?
-
The event topic that triggers this webhook
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Converts the WooWebhook instance to JSON format
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited