

Write the workflow
nelkap/workflows/fulfill-order.ts
- It draws a random claim ID. The ID is saved, so every call of this run has the same one.
- It claims the order with that ID. If another run already claimed it, this run stops here: the order is in good hands.
- It books the shipment, and saves the tracking link.
- It emails the tracking link to the customer.
- It sleeps for 14 days, then asks for a review.
lib with your own. claimOrder is the one that keeps an order from shipping twice. It writes the claim ID on the order only if the order has none yet, and returns whether the order now carries this ID:
Receive Stripe’s webhook
Register the workflow with the event that starts it:nelkap/index.ts
client_reference_id. Then add a route for Stripe’s webhook. It checks Stripe’s signature, and emits order.paid for each completed checkout:
app/api/stripe/route.ts
checkout.session.completed event, and set its signing secret as STRIPE_WEBHOOK_SECRET.
The route answers Stripe once the event is emitted. If emit throws, the route answers with an error, and Stripe sends the webhook again later. See Stripe’s guide to webhooks.
See it run
Each paid order shows in your project’s runs. Open one to see the claim, the shipment with its tracking link, and the email, then the sleep. Two weeks later, the review email goes out, and the run completes. If Stripe sent the same payment twice, you’ll see a second run for it that stopped after the claim, without shipping anything.Ideas to extend it
- Tag each run with the order’s ID, to find an order’s runs in one search.
- Wait for your carrier’s delivery event with
step.wait, and ask for the review a few days after delivery instead. - Listen for
order.paidin another workflow, for example to update your stock, without touching this one.