Skip to main content
You’ve installed the SDK. You’re ready to accept payments.

The default payment flow

When a customer reaches your checkout, here’s what happens:
  1. Your server creates a client session and returns a clientToken
  2. The SDK initializes and loads available payment methods
  3. Customer selects a method and enters their details
  4. Customer submits and the SDK processes the payment
  5. Your app receives the result via events

Create a Client Session (Server-Side)

Create a client session on your server using the Client Session API. This returns a clientToken that you pass to your client.
curl -X POST https://api.primer.io/client-session \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": "order-123",
    "currencyCode": "USD",
    "amount": 1000,
    "order": {
      "lineItems": [{
        "itemId": "item-1",
        "description": "Widget",
        "amount": 1000,
        "quantity": 1
      }]
    }
  }'

Initialize and Show Checkout

<primer-checkout client-token="your-client-token"></primer-checkout>
Listen for payment results:
const checkout = document.querySelector('primer-checkout');

checkout.addEventListener('primer:ready', (event) => {
  const primer = event.detail;

  primer.onPaymentSuccess = ({ payment }) => {
    window.location.href = `/confirmation?order=${payment.orderId}`;
  };

  primer.onPaymentFailure = ({ error }) => {
    console.error('Payment failed:', error.diagnosticsId);
  };
});

What Primer handles for you

Out of the box, Primer Checkout manages:
ConcernWhat Primer Does
ValidationReal-time input validation with inline error messages
Error displayPayment failures shown automatically in the UI
Redirects3DS challenges, bank redirects, and wallet flows
Loading statesVisual feedback during processing
Payment method logicEach method’s specific requirements and flows
You don’t need to write code for any of these behaviors.

Listening for results

To react to payment outcomes, listen for payment events:
const checkout = document.querySelector('primer-checkout');

checkout.addEventListener('primer:payment-success', (event) => {
  const { payment } = event.detail;
  window.location.href = `/confirmation?order=${payment.orderId}`;
});

checkout.addEventListener('primer:payment-failure', (event) => {
  const { error } = event.detail;
  // Error is already displayed in the checkout UI
  console.error('Payment failed:', error.diagnosticsId);
});

Testing in sandbox

Use these test cards to verify your integration:
Card NumberResult
4111 1111 1111 1111Success
4000 0000 0000 0002Declined
Use any future expiry date and any 3-digit CVV. Try the Web SDK example in your browser: Try it in Stackblitz

See also

Styling

Match the checkout to your brand

Layout

Control the structure of checkout components

Core Concepts

Understand the architecture

Track in Analytics

Send events to your analytics platform