Skip to main content

Checkout Flow

The checkout module manages the full session lifecycle — load a session, update the cart, apply promo codes, and handle shipping.

Load a Checkout Session

A checkout session is typically created by the Node SDK on your server, then the token is passed to the frontend via URL parameter.
// Token from URL: /checkout?checkoutToken=ct_abc123
const token = new URLSearchParams(window.location.search).get('checkoutToken');
const session = await tagada.checkout.loadSession(token);

// session.id          -- session ID (use for all subsequent calls)
// session.items       -- line items in the cart
// session.totals      -- subtotal, discount, shipping, tax, total
// session.customer    -- customer info if available
// session.currency    -- session currency (USD, EUR, etc.)

Create a Checkout Session (Client-Side)

You can also create a session directly from the browser:
const session = await tagada.checkout.createSession({
  items: [{ variantId: 'var_xxx', quantity: 1 }],
  currency: 'USD',
  checkoutUrl: 'https://mystore.com/checkout',
});

// session.redirectUrl -- URL to redirect the customer to
// session.checkoutToken -- token to use with loadSession()

Update Cart

const updated = await tagada.checkout.updateCart(session.id, [
  { variantId: 'var_xxx', quantity: 2 },
  { variantId: 'var_yyy', quantity: 1 },
]);
// updated.totals reflects the new cart

Promo Codes

// Apply
const updated = await tagada.checkout.applyPromoCode(session.id, 'SAVE20');
console.log(updated.totals.discount); // discount amount in cents

// Remove
const reset = await tagada.checkout.removePromoCode(session.id);

Shipping

// Get available rates
const rates = await tagada.checkout.getShippingRates(session.id);
// [{ id: 'rate_xxx', name: 'Standard', amount: 499, estimatedDays: 5 }]

// Select a rate
const updated = await tagada.checkout.selectShippingRate(session.id, rates[0].id);

Customer & Address

// Update customer info
await tagada.checkout.updateCustomer(session.id, {
  email: 'jane@example.com',
  firstName: 'Jane',
});

// Update address
await tagada.checkout.updateAddress(session.id, {
  shippingAddress: {
    line1: '123 Main St',
    city: 'San Francisco',
    state: 'CA',
    postalCode: '94102',
    country: 'US',
  },
});