gitpod
gitpod copied to clipboard
[UBP] Connect Stripe webhook to `FinalizeInvoice` RPC
Description
Do the necessary plumbing to connect the Stripe webhook (https://github.com/gitpod-io/gitpod/pull/11806) to the FinalizeInvoice RPC (https://github.com/gitpod-io/gitpod/pull/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 https://github.com/gitpod-io/gitpod/issues/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-serverHTTP port pod in the preview environment:
kubectl port-forward svc/public-api-server 9002:9002
- Download the Stripe CLI and 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
usagepod 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
/hold because it's based on https://github.com/gitpod-io/gitpod/pull/11985
/werft run
:+1: started the job as gitpod-build-af-invoke-finalize-invoice-rpc-from-webhook.23
(with .werft/ from main)
/unhold