---
title: "Comment by Hayrullah Kar on \"How to Test Payment Webhooks From the CLI Before a Real Customer Finds the Bug\" | Hashnode"
description: "Making \"fire the same COMPLETED event twice\" a named test step is something I rarely see in webhook guides, and the note about a unique constraint behind insert"
url: "https://hashnode.com/posts/how-to-test-payment-webhooks-from-the-cli-before-a-real-customer-finds-the-bug/6af6fd0acaa99e7879255ec1/comment/6af97b58fa6bf7041d0d14ef"
---

[Discussion](https://hashnode.com/posts/how-to-test-payment-webhooks-from-the-cli-before-a-real-customer-finds-the-bug/6af6fd0acaa99e7879255ec1)

Comment [How to Test Payment Webhooks From the CLI Before a Real Customer Finds the Bug](https://hashnode.com/posts/how-to-test-payment-webhooks-from-the-cli-before-a-real-customer-finds-the-bug/6af6fd0acaa99e7879255ec1)

[Hayrullah Kar](https://hashnode.com/@magesheet)

[15h ago](https://hashnode.com/posts/how-to-test-payment-webhooks-from-the-cli-before-a-real-customer-finds-the-bug/6af6fd0acaa99e7879255ec1/comment/6af97b58fa6bf7041d0d14ef)

Making "fire the same COMPLETED event twice" a named test step is something I rarely see in webhook guides, and the note about a unique constraint behind insertIfAbsent saves people a race condition. Two things in handlePaymentEvent can still lose or misapply an event. First, the key is recorded before the work runs. If markPaid throws, the provider retries, the key already exists, and the order is never marked paid. Writing the key in the same database transaction as the order update, or only after it succeeds, closes that. Second, the key stops duplicates but not ordering. A delayed FAILED from an earlier attempt can arrive after COMPLETED and release stock on an order that is already paid. Checking the order's current state before acting, for example only releasing stock while it is still pending, covers it, and it makes a good seventh CLI test: trigger COMPLETED, then FAILED, for the same orderId.
