Skip to content

[UBP] Use a realistic event payload in Stripe webhook automated tests #11985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 10, 2022

Conversation

andrew-farries
Copy link
Contributor

Description

When Stripe invoices finalize, the webhook is POSTed to with an invoice.finalized payload indicating the invoice id that was finalized. The exact shape of the payload for each event type is described in the Stripe docs.

This PR make the Stripe webhook extract the invoice id from the event payload. Most of the changes are to the test code that exercises the webhook to ensure that a realistic payload is attached to the invoice.finalized event.

Related Issue(s)

Part of #10937

How to test

Automated tests for the webhook handler.

For an end to end test:

  • Run the webhook handler locally:
cd components/public-api-server/
go run . run
stripe listen --skip-verify --forward-to localhost:9002/stripe/invoices/webhook
  • Trigger some Stripe events:
stripe trigger invoice.finalized

This should start a series of Stripe events (setting up a customer and payment methods), the last of which (the invoice.finalized event) should receive a 200 OK response.

  • You should see the following in the public api server logs:
{"level":"info","message":"finalizing invoice for invoice id: in_1LUlkzGadRXm50o3jqXq7mgh","serviceContext":{"service":"public-api-server","version":""},"severity":"INFO","time":"2022-08-09T06:17:39Z"}

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview

Andrew Farries added 3 commits August 9, 2022 05:49
Add a minimal Stripe event payload for an `invoice.finalized` event.

Ensure all tests send event payloads. The only event type of interest
for the webhook is `invoice.finalized` so other event types can have
empty payloads.
@andrew-farries andrew-farries requested a review from a team August 9, 2022 06:20
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Aug 9, 2022
@roboquat roboquat added the size/M label Aug 9, 2022
@andrew-farries
Copy link
Contributor Author

/hold because it's based on #11949

Base automatically changed from af/placeholder-finalize-invoice-impl to main August 10, 2022 12:48
@andrew-farries
Copy link
Contributor Author

/unhold

@roboquat roboquat merged commit 5ae8777 into main Aug 10, 2022
@roboquat roboquat deleted the af/webhook-unpack-event-payloads branch August 10, 2022 13:25
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production release-note-none size/M team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants