How it works
Pocketsflow acts as a redirect payment gateway for WooCommerce: The buyer’s WooCommerce order id travels inmetadata and is echoed back on the
order.completed webhook, which is how WooCommerce knows which order to mark
as paid.
Prerequisites
- A Pocketsflow account with at least one product.
- An API key (
pk_live_…for production,pk_test_…while developing). Create one under Developers → API keys. - A WooCommerce store you can add a small custom plugin / snippet to.
Develop against a
pk_test_… key first. Test-mode checkout sessions don’t
move real money, and you’ll receive test-mode webhooks so you can validate the
full flow end to end.Step 1 — Map WooCommerce products to Pocketsflow products
Each WooCommerce product that should be paid through Pocketsflow needs a corresponding PocketsflowproductId. Create the product in the dashboard (or
via POST /products) and store the id on the WooCommerce product, e.g. as a
custom field _pocketsflow_product_id.
Step 2 — Create a checkout session when the order is placed
Register Pocketsflow as a payment gateway and, inprocess_payment(), create a
checkout session and redirect the buyer to the returned url.
successUrl is where the buyer lands after paying — WooCommerce’s standard
“order received” page ($this->get_return_url( $order )). The cancelUrl sends
them back to the cart if they abandon checkout.
Step 3 — Register a webhook
Tell Pocketsflow where to send events. You can do this once from the dashboard (Developers → Webhooks) or via the API:Step 4 — Handle the webhook and mark the order paid
Pocketsflow signs every webhook so you can confirm it really came from us. Each delivery includes these headers:| Header | Description |
|---|---|
X-Pocketsflow-Event | The event type, e.g. order.completed. |
X-Pocketsflow-Signature | HMAC-SHA256 of the raw request body, keyed with your signing secret (hex). |
X-Pocketsflow-Timestamp | When the event was sent (ms since epoch). |
metadata.woocommerce_order_id to settle the right order:
Step 5 — Test the full flow
- Switch your gateway to use a
pk_test_…key. - Place a test order in WooCommerce and complete the hosted checkout.
- Confirm the buyer is redirected back to the WooCommerce “order received” page.
- Confirm the
order.completedwebhook arrives and the order flips to Processing / Completed.
Handling edge cases
Buyer abandons checkout
Buyer abandons checkout
They’re returned to your
cancelUrl and the WooCommerce order stays
pending. WooCommerce’s “hold stock” / cancel-unpaid-orders settings will
clean these up.Webhook missed or delayed
Webhook missed or delayed
Webhooks are the source of truth for payment. If one is missed, reconcile by
listing recent orders via
GET /orders and matching on
metadata.woocommerce_order_id. Keep your handler idempotent so a re-send is
safe.Multiple line items
Multiple line items
The example assumes one mapped product per order. For carts with several
items, create a checkout session per mapped line item, or model the cart as a
single Pocketsflow product. Mixed carts are covered as a follow-up in the
integration spec.
Reference
- Checkout session API —
POST /checkout/sessions - Webhook events
- Authentication & security
- Custom platforms — the same pattern for any store