Stripe payment
Create a Stripe Checkout Session, pay with a test card on the test checkout page, and handle Stripe's signed webhook.
Try it in the demo.
The situation: your app takes payments with Stripe Checkout. You want to run the whole flow (your page, Stripe's page, back to yours, the webhook) without a Stripe account, internet or a tunnel.
You need: your app's Stripe client pointing at http://127.0.0.1:8026 (Stripe SDKs accept a base URL), and your webhook handler's URL.
Steps
- In Payments > Gateways, edit Stripe. On Merchant, set the Notification endpoint to an endpoint for your handler (create it in Webhooks > Endpoints first). Its
whsec_secret is the one your app verifiesStripe-Signaturewith. - In your app, start a checkout. Stripe's answer sends the browser to SendMock's checkout page.
- Pay with
4242 4242 4242 4242, any future expiry and any CVC. - The page shows where it sends the browser (your
success_urlwithsession_id) and Return to Acme Shop. Follow it. - Your handler receives
checkout.session.completed, signed withStripe-Signature, sostripe.webhooks.constructEventaccepts it.
Now try the other paths: 4000 0000 0000 0002 (declined), 4000 0025 0000 3155 (3-D Secure), or Simulate > Refund... on the payment.
In your code
A test that starts a Stripe checkout, pays with the 4242 test card and waits for the payment to succeed.
The examples call SendMock's REST API with each language's usual HTTP client and test framework. JavaScript, Go, Java, Rust, Ruby and C# use the small call helper shown under Test helper on their page in Connect your app.
payment=$(sendmock payments checkout create --provider stripe --amount-minor 1999 --currency USD --json)
sendmock payments checkout complete "$(jq -r '.id' <<<"$payment")" pay --method-key card --card '{"number":"4242424242424242","exp_month":12,"exp_year":2030,"cvc":"123","holder_name":"Sam Tester"}'
paid=$(sendmock payments wait --provider stripe --status succeeded --timeout 10s --json)
jq -e '.status == "succeeded"' <<<"$paid" >/dev/nullWhat you should see
The payment Succeeded in Payments, its timeline with the redirect and the notification, and the notification in Webhooks > Deliveries.
Try it in the demo
- Open Payments > Gateways and press Edit Stripe.
- On the Checkout tab, press Open a test checkout.
- Fill Card number
4242 4242 4242 4242, Expiry (MM/YY)12/34, CVC123, and press the Pay button (it shows the amount). - The result says "Payment successful".