Photo by Yosuke Ota on Unsplash

On this page

This chapter follows Stripe beyond payments. For context, start with What is Stripe?.

Stripe CLI

Command Purpose
stripe login Authenticate CLI to your account
stripe listen --forward-to localhost:4242/webhook Forward webhooks locally
stripe trigger checkout.session.completed Fire a test event
stripe trigger invoice.payment_failed Simulate failed invoice
stripe customers list --limit 3 Quick API sanity check
stripe logs tail Stream API request logs

Install: npm i -g @stripe/cli or see Stripe CLI install.

Key prefixes

Prefix Kind
pk_test_ / pk_live_ Publishable
sk_test_ / sk_live_ Secret
rk_test_ / rk_live_ Restricted
whsec_ Webhook signing secret
cus_ Customer
price_ Price
pi_ PaymentIntent
sub_ Subscription

Test cards (card payments)

Number Result
4242 4242 4242 4242 Success
4000 0025 0000 3155 Requires authentication (3DS)
4000 0000 0000 9995 Declined

Use any future expiry, any CVC, any postal code unless testing specific validations.

stripe-node snippets

stripe-client.js
import Stripe from 'stripe';
export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
apiVersion: '2026-09-30.endive',
});
Task Call
Create Customer stripe.customers.create({ email })
Create Product + Price stripe.products.create then stripe.prices.create
Checkout (payment) stripe.checkout.sessions.create({ mode: 'payment', line_items, success_url, cancel_url })
Checkout (subscription) Same with mode: 'subscription'
PaymentIntent stripe.paymentIntents.create({ amount, currency, automatic_payment_methods: { enabled: true } })
Verify webhook stripe.webhooks.constructEvent(rawBody, sig, whsec)
Portal stripe.billingPortal.sessions.create({ customer, return_url })

Webhook events to handle first

Event Action
checkout.session.completed Fulfill one-time or start subscription
checkout.session.async_payment_succeeded Fulfill async Checkout
payment_intent.succeeded Fulfill Payment Element flow
invoice.paid Extend subscription period
invoice.payment_failed Dunning
customer.subscription.deleted Revoke access

See Webhooks in Stripe.

Next: Stripe glossary.

Search articles

Type a word to search published articles.

Open the search page