Skip to main content
Redirect users to a confirmation or thank you page after a successful payment.

Recipe

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

How it works

  1. Listen for the primer:payment-success event on the checkout element
  2. Extract the payment object from event.detail
  3. Use window.location.href to redirect to your confirmation page
  4. Pass the orderId as a query parameter so your confirmation page can display order details

Variations

Redirect with payment ID

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

Redirect to different pages based on payment method

checkout.addEventListener('primer:payment-success', (event) => {
  const { payment, paymentMethodType } = event.detail;

  const redirectUrls = {
    PAYMENT_CARD: '/confirmation/card',
    PAYPAL: '/confirmation/paypal',
    default: '/confirmation',
  };

  const url = redirectUrls[paymentMethodType] || redirectUrls.default;
  window.location.href = `${url}?id=${payment.orderId}`;
});

See also

Show custom success message

Display a branded success state after payment

Track payment in analytics

Send payment events to your analytics platform