Getting Started

Quickstart

Stand up an end-to-end checkout in five minutes. We will create a product, generate a Checkout Session, and verify the payment with a webhook.

Prerequisites

You will need a free ExpressPayments account, Node.js 20+, and a public URL to receive webhook events. We recommend using ngrok or cloudflared in development.

1. Create a product

product.ts
const product = await ep.products.create({
  name: "Pro Plan",
  default_price_data: {
    currency: "usd",
    unit_amount: 2900,
  },
});

2. Create a Checkout Session

A Checkout Session is a hosted, conversion-optimized payment page that handles cards, wallets, and local methods automatically.

checkout.ts
const session = await ep.checkout.sessions.create({
  mode: "payment",
  line_items: [{ price: product.default_price, quantity: 1 }],
  success_url: "https://app.example.com/success?id={CHECKOUT_SESSION_ID}",
  cancel_url: "https://app.example.com/cart",
});

return Response.redirect(session.url, 303);

3. Listen for the webhook

webhook.ts
app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => {
  const event = ep.webhooks.constructEvent(
    req.body,
    req.headers["ep-signature"],
    process.env.EP_WEBHOOK_SECRET,
  );

  if (event.type === "checkout.session.completed") {
    fulfillOrder(event.data.object.id);
  }

  res.json({ received: true });
});

Common event types

EventWhen it fires
checkout.session.completedCustomer finished checkout
payment_intent.succeededFunds were captured
charge.refundedA refund was issued
invoice.paidAn invoice was successfully paid

Testing

Use card 4242 4242 4242 4242 with any future expiry and any CVC to simulate a successful payment in test mode.