Skip to content

Add a Stripe webhook endpoint for payment processing#130

Merged
exarkun merged 48 commits intomainfrom
240.stripe-webhook-and-payment-intents
Nov 2, 2022
Merged

Add a Stripe webhook endpoint for payment processing#130
exarkun merged 48 commits intomainfrom
240.stripe-webhook-and-payment-intents

Conversation

@exarkun
Copy link
Copy Markdown
Collaborator

@exarkun exarkun commented Oct 28, 2022

This adds a handler at /v1/stripe/webhook which can be configured as a Stripe "webhook" for receiving push notifications about events related to a Stripe account. It is intended to be configured as a hook to receive checkout.session.completed events which it uses to populate the database with information about voucher payments.

A new required command-line option is introduced which must be given the "webhook secret" so that webhook request signatures can be verified to avoid use of the endpoint by parties other than Stripe.

The webhook must be configured in the correct Stripe account so that Stripe will make use of this endpoint. One way to do this is with:

curl \
    https://api.stripe.com/v1/webhook_endpoints \
    -u sk_test_yourkey: \
    -d url="https://serveraddress/v1/stripe/webhook" \
    -d "enabled_events[]"="checkout.session.completed"

The old "charge"-based endpoint is still in place but presumably it can be deleted in the near future (it seems convenient to have at least one revision where both systems are supported though).

Note that while the diff looks like it's a bit on the long side, a solid +400 of that diff are just sample Stripe JSON data.

Also note that this PR switches us to a fork of stripe-core which supports a newer version of the Stripe API. The changes in the fork are not currently suitable to be submitted upstream. Before we can satisfy further Stripe-related requirements we probably need to revisit our dependency on stripe-core (see #131 for one idea).

wuan and others added 30 commits September 15, 2022 12:28
not used now but maybe nice for reference for further dev
This is a new required CLI argument so that we can validate signatures on webhooks.
Copy link
Copy Markdown
Collaborator

@hacklschorsch hacklschorsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed to the best of my current ability, I feel this is a big improvement and should be merged & deployed (to be improved further in later change sets).

Added a few questions about semantics - where it looked to me naming didn't fit perfect to what the code does.

Comment thread nix/materialized.paymentserver/default.nix
Comment thread test/Stripe.hs Outdated
Comment thread test/Stripe.hs Outdated
Comment thread test/Stripe.hs Outdated
@hacklschorsch
Copy link
Copy Markdown
Collaborator

This includes / obsoletes #121.

@hacklschorsch
Copy link
Copy Markdown
Collaborator

hacklschorsch commented Oct 31, 2022

I like the description of this MR a lot. At least the upper half of it would be a great permanent addition the the PaymentServer documentation IMHO

@exarkun
Copy link
Copy Markdown
Collaborator Author

exarkun commented Oct 31, 2022

I'm happy enough with this now. Assuming testing on staging goes well I'll merge it without further changes.

@exarkun
Copy link
Copy Markdown
Collaborator Author

exarkun commented Nov 2, 2022

This works on staging.

@exarkun exarkun merged commit a82ccda into main Nov 2, 2022
@exarkun exarkun deleted the 240.stripe-webhook-and-payment-intents branch November 2, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants