Docs / Testing against real providers
Docs / Testing against real providers v0.1.0-alpha.1

Testing against real providers

What the repository's tests prove, what they cannot, and how to run the adapters against Stripe's test mode one payment method at a time.

Four layers

LayerCommandTalks to the providerProves
Unit and cross-provider testspnpm testNo. The stripe and @polar-sh/sdk packages are mocked.The library does what its authors believe the provider does
The example in a browserpnpm test:journeyNo. It pays through the demo provider.The documented walkthrough really happens: routing in the browser, no amount in the request, the server’s price, a webhook and a lookup that agree
Webhook signature testspnpm testNo, but nothing is mocked: signatures are made and checked with the providers’ own codeA genuine webhook verifies; a forged, altered or stale one does not
Live suitepnpm test:liveYes, Stripe test modeWhat Stripe actually does for each payment method

All but the live suite run in CI. The live suite needs a key and is run by hand.

The live suite

STRIPE_TEST_SECRET_KEY=sk_test_... pnpm test:live

The test payment method ids and IBANs in the table were written from memory of Stripe’s documentation. If a row fails on the confirm call instead of on the status check, its test data is the first thing to compare against the docs.

It refuses any key that does not start with sk_test_ or rk_test_, and is skipped without one. It creates real test-mode objects, which appear in your Stripe test dashboard and cost nothing.

e2e/live/stripe.live.ts is a table. Each row takes one payment method to one outcome and checks the status Tenderlane reports:

CaseExpected status
Card, paid at oncecomplete
Card, declinedfailed
Card, 3D Secure requiredopen
Card, authorised with manual captureprocessing
SEPA debit that will succeedprocessing, then complete
SEPA debit that will bounceprocessing, then failed
Hosted checkout: created, read back, expiredopen, then expired

No browser is needed for the inline cases. The adapter creates the PaymentIntent, the test confirms it server-side with one of Stripe’s test payment methods (which is what the Payment Element does for the customer), and the adapter’s retrieve reads the result. Hosted Checkout cannot be paid without a browser, so only its creation, lookup and expiry are covered.

Adding a payment method

  1. Enable the method in the Stripe test-mode dashboard.
  2. Find its test data in Stripe’s documentation: the testing page for cards, and the method’s own page for bank debits, redirects and vouchers. Most have one value that succeeds and one that fails, and some that do so after a delay.
  3. Add a row to CASES: the currency, the Tenderlane method id, the confirm parameters, and the status you expect at once and after it settles.

Redirect methods (iDEAL, PayPal, Alipay) stop at open after confirmation, with a URL the customer would be sent to. In test mode that URL is a Stripe page with an authorise and a fail button, which needs a browser; the live suite does not drive it.

Webhooks from a real provider

The signature tests cover verification. To see real events arrive at the example, use the Stripe CLI, which forwards them to localhost and prints the signing secret to use:

stripe listen --forward-to localhost:3000/api/webhooks/stripe
# put the printed whsec_... in .env.local as STRIPE_WEBHOOK_SECRET, restart, then:
stripe trigger payment_intent.succeeded

These commands are from memory of the Stripe CLI and were not run here; check stripe listen --help if they differ.

What not to use

stripe-mock is a stateless server that returns fixed, type-correct responses. By its own description it does not reproduce Stripe’s behaviour: a payment never changes status and errors cannot be provoked. It can check that a request is well formed and nothing about the questions on this page.

Polar

There is no live suite for Polar yet. Its sandbox (sandbox.polar.sh) has separate credentials; the adapter’s server: 'sandbox' selects it. Two things in the Polar adapter rest on reading the SDK and have not been confirmed against the sandbox: that confirmed means a payment in progress, and that checkout.updated is delivered for each status change.