stripe-cli icon indicating copy to clipboard operation
stripe-cli copied to clipboard

Calling webhook twice and URI path

Open nirpur opened this issue 3 years ago • 4 comments

Hello I downloaded the Stripe CLI recently to test the webhook on my localhost and registered the webhook using the steps below.

  1. Open my command prompt and cd to the folder where Stripe CLI exe is present.

$stripe login $stripe listen --load-from-webhooks-api --forward-to http://localhost/endpoints/stripeWrapper/stripe-callback.php --events checkout.session.completed

While in listening mode, I could trigger my webhook using the test payment link through my browser. It ran fine few days back, and then I stopped the listener and closed the command prompt at day-end.

Two problems/ helps required:

  1. Though it triggered the webhook PHP correctly and I didn't get a functional error, the logged URI path shows the PHP path concatenated twice in same log statement (see two php paths in same statement). Did I do something wrong here?
  2. I wanted to retest after few days and followed the same steps above to login and registered stripe listener. I see that on every event, it is now triggering my web-hook twice (see two statements below), and thereby initiating two orders. How do I stop the duplicate one? There is only one entry for my laptop as listener on the Stripe Dashboard.

2022-06-14 17:25:12 --> checkout.session.completed [evt_1LAhEaIgs4fJ7Y89noVtTTye] 2022-06-14 17:25:13 <-- [200] POST http://localhost/endpoints/stripeWrapper/stripe-callback.php/endpoints/stripeWrapper/stripe-callback.php [evt_1LAhEaIgs4fJ7Y89noVtTTye] 2022-06-14 17:25:13 <-- [200] POST http://localhost/endpoints/stripeWrapper/stripe-callback.php/endpoints/stripeWrapper/stripe-callback.php [evt_1LAhEaIgs4fJ7Y89noVtTTye]

Thanks

nirpur avatar Jun 17 '22 16:06 nirpur

Hi @nirpur thanks for reporting this, and I'm sorry that this confusing behaviour is happening! If you're still able to reproduce, would you mind running the same stripe listen flow with --log-level=trace as an additional flag, and supply the resulting terminal output after triggering an event or two? Feel free to redact your signing secret and account id, etc.

suz-stripe avatar Jun 17 '22 17:06 suz-stripe

Hello @etsai-stripe These two URLs are our other sandbox environments and they are receiving the calls correctly (only once). They have been setup since long. This is the first time I am using a localhost listener to test. Though I don't know whether they see php names twice in the single URI (the problem#2).

Hello @suz-stripe,
Here is the output I see with the log-level trace on. Hope I have obscured the right keys, it has just too many hashed ids. It has reproduced both the problems I had listed. Let me know if you need additional details. I am away for few days, but hopefully I will be able to sneak in few test-runs.

stripe-cli log trace 06-20-22.txt

Thanks for your assistance. PS: Am not sure if my "Close with Comment" will close the issue, but I dont intend to close it. The issue still persists as seen in the log.

nirpur avatar Jun 21 '22 00:06 nirpur

I believe, I can guess what's happening:

  1. The stripe listen command takes the URI from existing webhook listeners and appends to the "--forward-to" server parameter. And hence I see the "php name" twice in the single log. Potential fix: I should provide only "--forward-to" localhost and not the entire path.
  2. It forwards once for every webhook listener configured. Because I have two existing webhooks, it is triggering my PHP twice. Let me know if there is a way to override that behavior.

nirpur avatar Jun 21 '22 13:06 nirpur

thanks for the extra info. this looks like will require more investigation.

etsai-stripe avatar Jun 21 '22 18:06 etsai-stripe