After you integrate with Flex Checkout or create a Payment Link to take your customers to a payment form, you need a notification to fulfill their order after a successful payment.

In this guide, you’ll learn how to use webhooks to fulfill orders after a payment.

Fulfillment guide

1

Select webhook events

Choose the webhook events that are relevant to your checkout session.

  • customer.created — When a customer record is created in Flex.
  • payment_intent.created — As soon as the customer begins entering payment info.
  • payment_intent.succeeded — After a successful payment (fires twice on split carts).
  • customer.subscription.created — For subscription sessions, when a subscription is first created.
  • customer.subscription.updated — For subscription sessions, when status changes (e.g., incomplete → active).
  • checkout_session.completed — Sent after a checkout session has fully completed.
2

Create an event handler

Set up an HTTP endpoint to receive and log incoming events. For local testing, use ngrok or webhook.site.

// Using Express
const app = require("express")();
const bodyParser = require("body-parser");

app.post(
  "/webhook",
  bodyParser.raw({ type: "application/json" }),
  (req, res) => {
    console.log("Got payload:", req.body);
    res.status(200).end();
  }
);

app.listen(4242, () => console.log("Running on port 4242"));
3

Create a webhook endpoint

Register your handler’s public URL in Flex. Here we listen for checkout.session.completed:

curl --request POST \
  --url https://api.withflex.com/v1/webhooks \
  --header 'authorization: Bearer fsk_test_…' \
  --header 'content-type: application/json' \
  --data '{
    "webhook": {
      "url": "https://withflex.com/handle_events",
      "events": ["checkout.session.completed"]
    }
  }'
4

Create a checkout session

Trigger a session to confirm your handler receives events:

curl --request POST \
  --url https://api.withflex.com/v1/checkout/sessions \
  --header 'authorization: Bearer fsk_test_…' \
  --header 'content-type: application/json' \
  --data '{
    "checkout_session": {
      "line_items": [{"price": "fprice_…","quantity": 1}],
      "success_url": "https://withflex.com/thank-you?success=true",
      "cancel_url": "https://withflex.com/thank-you?canceled=true",
      "mode": "payment"
    }
  }'

Then go through checkout:

  1. Enter contact info
  2. Fill any intake form
  3. Use card number 4242 4242 4242 4242, future expiry, any CVV, and postal code 90210
  4. Click Pay

You should see an event payload like:

{
  "event_type": "checkout.session.completed",
  "object": {
    "checkout_session": {
      "status": "complete",
      "redirect_url": "https://checkout.withflex.com/pay/…",

    }
  }
}
5

Verify events came from Flex

Confirm the signature on incoming requests before processing. See Verifying webhooks.

6

Fulfill order

Handle checkout.session.completed to:

  • Save the order to your database
  • Send a receipt email
  • Update inventory via the Line Items API:
curl --request GET \
  --url https://api.withflex.com/v1/checkout/sessions/fcs_…/line_items \
  --header 'authorization: Bearer fsk_test_…'
7

Go live in production

Once deployed, register your production webhook URL in Flex.