Skip to content

Commit

Permalink
wip #21 document webhooks setup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Aug 6, 2021
1 parent cf3c2d5 commit f5dc673
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Recieve connect webhooks from Stripe & forward them to the correct shop

### What does this do?

When events happen at Stripe (e.g. a user completes a payment),
Then, if you have configured webhook endpoint in Stripe) will send
*the events you ask for*, to you webhook endpoint.

e.g.


### Install

Expand All @@ -26,6 +34,76 @@ flask run

See apache example config & wsgi config example in repo. (assumes mod wsgi is installed & enabled on apache)

### Create webhook endpoints in Stripe

1. Check the webhook is *not* already created https://dashboard.stripe.com/webhooks (do you already see the endpoint?)
There should be two, one endpoint for connect accounts in testmode, and one for test accounts in live mode.

e.g. my-api-live.example.com/stripe_webhooks and my-api-test.example.com/stripe_webhooks

> Note: Stripe livemode is *always* true for Stripe connect. Why?
Because Stripe connect accounts can either be in live or test mode so
the live/test mode config is moved to each Stipe connect account (and
they can change their account to be in live or test mode).


2. If not, create it:

Use `create_stripe_connect_webhook.py` in this repo:

```
. venv/bin/activate
python create_stripe_connect_webhook.py
Stripe secret api key:sk_live_abc123
Webhook url:https://testing-example.com
{
"api_version": null,
"application": "ca_",
"created": ,
"description": null,
"enabled_events": [
"checkout.session.completed",
"payment_intent.succeeded"
],
"id": "we_",
"livemode": true,
"metadata": {},
"object": "webhook_endpoint",
"secret": "whsec_ndisofndio23iono",
"status": "enabled",
"url": "https://testing-example.com"
}
```
3. Copy the `secret` from the output, this app needs the secret to verify the events come from Stripe.
4. Set the dokku app secret:
```
dokku config:set testing-stripe-connect-webhook-endpoint-router STRIPE_WEBHOOK_SECRET=<secret>
```
<img src="./stripe-webhook-created-testing.png" />

###

It it not possible or desireable to create Stripe webhooks endpoints in 'test mode' using the UI, they are all live by default. We must use the api for that.

https://testing-stripe-connect-webhook-endpoint-router.pcpink.co.uk


- test mode, is where all shops in test mode Stripe sends events to *including* our GithubAction playwright tests , they are in test mode too



Event types
checkout.session.completed
payment_intent.succeeded

Mode


Signing secret



## Smoke test

```
Expand Down
8 changes: 7 additions & 1 deletion create_stripe_connect_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
the events required.
Returns the endpoint secret, needed for Stripe webhook validation
Note: Stripe livemode is *always* true for Stripe connect. Why?
Because Stripe connect accounts can either be in live or test mode so
the live/test mode config is moved to each Stipe connect account (and
they can change their account to be in live or test mode).
"""

import stripe

stripe_api_key = input("Stripe api key:")
stripe_api_key = input("Stripe secret api key:")
endpoint_url = input("Webhook url:")

stripe.api_key = stripe_api_key
Expand Down
Binary file added stripe-webhook-created-testing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f5dc673

Please sign in to comment.