Stripe webhook not including subfolder, Subscription not being updated after payment success

Hi,

I am having an issue with members paid subscription. My checkout process works well and payment is processed in my stripe account, and after I am redirected to home page with Success notification.
But when I open account tab, It still shows me “Currently, you’re not a subscriber” message. When I see webhook links for stripe payment events, it shows me webhooks with links like this -
http://my_site/members/webhooks/stripe,
but my site is in subfolder and I access it using

http://my_site/subfolder/

So probably it shlould be something like this -
http://my_site/subfolder/members/webhooks/stripe

Is this reason why webhooks are failing and not updating subscribers payment data on my site.
If yes how can I update these webhooks to include my subfolder (actual url).

Hi @digitalswim,

you’re absolutely right with your proposed URL.
Without the right webhook, stripe can’t communicate with ghost properly.
You can add the valid webhook url in your Stripe Dashboard - Developers - Webhooks - +Add endpoint

Following endpoint events should be selected:

  • checkout.session.completed
  • customer.subscription.deleted
  • customer.subscription.updated
  • invoice.payment_succeeded
  • invoice.payment_failed

Thanks,

I updated some webhooks in the list before with updated url and resent webhooks to process ( Using Resend button). My site did show updated subscription, I even tried cancelling/continue subscription which was working on site and reflected on account page.
But then I wanted to try it from scratch.again.
I deleted all failed webhooks from stripe dashboard, I created new webhook as you mentioned. Then I deleted my member and added it again to test checkout process.
This time it did not work, I am attaching screen shots here.

As you can see failed attempts with unauthorized code, My stripe account is not activated and I am using Test Mode, It is connected on my site dashboard.


The webhook is definitely reachable.

Live and Testmode use their own api keys and webhooks.
So make sure you entered the test api keys, if you use test enviroment and vice versa

EDIT: oh and restart ghost, when you changed your settings

Even after adding webhook, it is auto generating new webhooks with wrong url.

I have used test API keys which they provide at the end of Stripe connection process, restarted ghost too, still same.But I does work when I update failed webhooks and resend it.

Could you open the failed webhook attempt and copy
Request POST body
Response body

Does the url value in your config file include the subfolder? If not you need to add it so that Ghost knows where it lives then the correct webhooks will be automatically created after restarting.

1 Like

These are from config.production.json -

“url”: “http://ghost.digitalswim.in/beats/”,
“server”: {
“port”: 2368,
“host”: “127.0.0.1”
},

This is request body from failed webhook -

{
“id”: “evt_1H0a7fGjmMprSRqs9k6jrGBS”,
“object”: “event”,
“api_version”: “2019-09-09”,
“created”: 1593725950,
“data”: {
“object”: {
“id”: “cs_test_HXw1OQ3jutC0ORMLhPHBzmdgNeIyKavEeG4AOMG6XBV4KC7wio0rdmCO”,

“object”: “checkout.session”,
“billing_address_collection”: null,
“cancel_url”: “http://ghost.digitalswim.in/beats/?stripe=cancel”,
“client_reference_id”: null,
“customer”: “cus_HZircLytkDPris”,

“customer_email”: null,
“display_items”: [
{
“amount”: 500,
“currency”: “usd”,
“plan”: {
“id”: “7d6c89c0289ca1731226e86b95b5a162085b8561ca0d10d3a4f03afd3e3e6ba6”,
“object”: “plan”,
“active”: true,
“aggregate_usage”: null,
“amount”: 500,
“amount_decimal”: “500”,
“billing_scheme”: “per_unit”,
“created”: 1593619187,
“currency”: “usd”,
“interval”: “month”,
“interval_count”: 1,
“livemode”: false,
“metadata”: {
},
“nickname”: “Monthly”,
“product”: “109c85c734fb9992e7bc30a26af66c22f5c94d8dc62e0a33cb797be902c06b2d”,
“tiers”: null,
“tiers_mode”: null,
“transform_usage”: null,
“trial_period_days”: null,
“usage_type”: “licensed”
},
“quantity”: 1,
“type”: “plan”
}
],
“livemode”: false,
“locale”: null,
“metadata”: {
},
“mode”: “subscription”,
“payment_intent”: null,
“payment_method_types”: [
“card”
],
“setup_intent”: null,
“shipping”: null,
“shipping_address_collection”: null,
“submit_type”: null,
“subscription”: “sub_HZjakJL6di5w6h”,
“success_url”: “http://ghost.digitalswim.in/beats/?stripe=success
}
},
“livemode”: false,
“pending_webhooks”: 2,
“request”: {
“id”: “req_b7qm0BjaL8JC3n”,
“idempotency_key”: null
},
“type”: “checkout.session.completed”
}

Okay I have tested following scenarios -

Scenario - 1

  1. Deleted all webhooks through Stripe dashboard
  2. Checkout process for member

Outcome -

  • No webhook is generated
  • No webhook events are fired from Stripe server
  • Subscription Failed with Success Notification

Scenario - 2

  1. Deleted all webhooks .
  2. Deleted member then added again.
  3. Created new webhook on Stripe with correct URL
  4. Tried checkout process.

Outcome -

  • Displays Success Notification
  • Does not update subscription
  • Gives Unothorized Error ( I think because I manually created webhook).

Scenario 3

  1. Deleted all webhooks
  2. Deleted and added member
  3. Disconnect Strip and Connect Again.
  4. Checkout subscription

Outcome -

  • Success Notification
  • Webhooks are generated as soon as I Connect Stripe from my site dashboard,
  • Wrong URL in webhook.
  • Subscription does not work
  • Webhook events fired, but with failure notice

Scenario 4

  1. After scenario 3, I updated URL of one of the webhook generated ( it was generated after connecting Stripe)
  2. Tried subscription again from my site

Outcome -
This time it worked, with Success message.

I checked members.js file code, It does show correct URL with post/delete/put events.

What I have figured out is this, webhooks are generated at the completion of Stripe Connection process through Ghost Site Dashboard. Manually adding them does not work. While generating webhooks it is not taking correct URL with subfolers,. but If i fix these auto generated webhooks on Stipe dashboard, it works.

Hi Guys,

Were you able to reproduce this? Is this only at my end probably due to some configuration issue.

Thanks

Everytime I update webhook on stripe dashboard and restart ghost site, it generates new webhook with wrong Url, so i need to update it back again.