PAYMENTS / LESSON 04
Stripe Webhooks and Testing.
Webhooks, the dashboard, test payments, pricing and built-in security

Loading the lesson…
Loading activities…
PAYMENTS / LESSON 04
Webhooks, the dashboard, test payments, pricing and built-in security

Loading the lesson…
Loading activities…
So how does your app find out a payment happened? Stripe uses "webhooks," which just means Stripe sends a message to your server.
Here's the catch though. ANYONE can send a fake message to your webhook URL pretending to be Stripe. So before you trust it, you check the signature Stripe puts on every webhook, using the signing secret (it starts with whsec_) from your webhook settings.
Install the two libraries first with npm install express stripe. fulfillOrder is your own function, the spot where you mark the order paid in your database and give access.
A couple of things Stripe's docs are serious about. Stripe can send the same event more than once, so fulfillOrder should check whether that order was already handled before it does anything. And answer fast, then do slow work afterward, or Stripe thinks the delivery failed and tries again. While you're building, the Stripe CLI command stripe listen --forward-to localhost:4242/webhook sends test events to your laptop and prints the signing secret to use.
Webhooks tell you about all kinds of things.
Stripe gives you a powerful dashboard where you can do all of this.
Stripe has test environments, which its docs now call sandboxes (you'll also still hear people say test mode), plus fake card numbers to use in them. You can build and test your whole payment flow without spending a single real dollar (your bank account says thanks).
Here are the test card numbers.
4242 4242 4242 4242 - Always succeeds4000 0000 0000 0002 - Always declines4000 0000 0000 9995 - Fails with "insufficient funds"Use any future date for expiry and any 3 digits for CVC.
Stripe takes a fee on each successful payment, and subscriptions run through Stripe Billing, which has its own pricing on top. The exact numbers depend on your country, the payment method and the product, and they change. Like the payments intro said, don't trust fee numbers from a tutorial... and yes, that includes this one.
Check stripe.com/pricing for payment fees and stripe.com/billing/pricing for subscription fees BEFORE you set your prices.
Just by using Stripe, you automatically get all of this.