Skip to content
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

[UBP] Connect Stripe webhook to FinalizeInvoice RPC #11987

Merged
merged 8 commits into from
Aug 10, 2022

Conversation

andrew-farries
Copy link
Contributor

Description

Do the necessary plumbing to connect the Stripe webhook (#11806) to the FinalizeInvoice RPC (#11903).

With this PR, the webhook calls the FinalizeInvoice RPC on the usage component when it receives a invoice.finalized event.

This PR also updated the usage component network policy to allow ingress from the public-api-server and adds config for the public-api-server so that it knows where the usage gRPC server is located (ie usage:9002 in-cluster).

The FinalizeInvoice RPC is still unimplemented and the webhook is not yet registered with Stripe.

Related Issue(s)

Part of #10937

How to test

The PR adds a test for the webhook to check it calls FinalizeInvoice with the expected invoice id when it receives an invoice.finalized event.

For an end-to-end test:

  • Port forward to the public-api-server HTTP port pod in the preview environment:
kubectl port-forward svc/public-api-server 9002:9002
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 usage pod logs:
{"level":"info","message":"Finalizing invoice for invoice \"in_1LUmIyGadRXm50o3x1zcBlxv\"","serviceContext":{"service":"usage","version":"commit-eb0c7b4e916b1a1da8a530fbb1a97882168eb3c5"},"severity":"INFO","time":"2022-08-09T06:52:46Z"}

This shows that the webhook called the FinalizeInvoice RPC.

Release Notes

NONE

Documentation

Werft options:

  • /werft with-preview

@andrew-farries andrew-farries requested a review from a team August 9, 2022 06:57
@andrew-farries andrew-farries requested a review from a team August 9, 2022 06:57
@github-actions github-actions bot added team: delivery Issue belongs to the self-hosted team team: webapp Issue belongs to the WebApp team labels Aug 9, 2022
@andrew-farries
Copy link
Contributor Author

/hold because it's based on #11985

Copy link
Contributor

@adrienthebo adrienthebo left a comment

Choose a reason for hiding this comment

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

LGTM!

Base automatically changed from af/webhook-unpack-event-payloads to main August 10, 2022 13:25
Andrew Farries added 8 commits August 10, 2022 13:27
The public-api-server depends on the usage component as it will invoke
RPCs on the usage component billing server.
Takes the address of the billing service gRPC server and constructs a
client.

Also add a noop version of the client for when no billingservice is
configured (such as will be the case for self-hosted installations).
Construct and pass a billingservice client to the Stripe webhook so that
it can invoke the `FinalizeInvoice` RPC when the webhook is triggered.
Allow ingress from the public api server so that the Stripe webhook can
invoke RPCs on the usage component.
`mockgen --source client.go`
TestWebhookInvokesFinalizeInvoiceRPC ensures that when the webhook is
hit with a `invoice.finalized` event, the `FinalizeInvoice` method on
the billing service is invoked with the invoice id from the event
payload.
@andrew-farries andrew-farries force-pushed the af/invoke-finalize-invoice-rpc-from-webhook branch from 8132ebf to b0b331b Compare August 10, 2022 13:29
@andrew-farries
Copy link
Contributor Author

andrew-farries commented Aug 10, 2022

/werft run

👍 started the job as gitpod-build-af-invoke-finalize-invoice-rpc-from-webhook.23
(with .werft/ from main)

@andrew-farries
Copy link
Contributor Author

/unhold

@roboquat roboquat merged commit aba684f into main Aug 10, 2022
@roboquat roboquat deleted the af/invoke-finalize-invoice-rpc-from-webhook branch August 10, 2022 13:55
@roboquat roboquat added the deployed: webapp Meta team change is running in production label 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 release-note-none size/L team: delivery Issue belongs to the self-hosted team team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants