Skip to main content

Overview

The Cart API allows you to manage customer shopping carts, including retrieving cart contents, adding products, clearing the cart, and creating checkout sessions from cart contents.
All cart operations require a customer token for authentication.

Get Cart

Retrieves the current customer’s shopping cart with all line items and pricing.
storefront.cart.getCart(config?)

Parameters

config
object
Configuration object for the request

Returns

Returns a CartDto object containing:
store_id
string
The store’s unique identifier
customer_id
string
The customer’s unique identifier
lines
CartLineDto[]
Array of line items in the cart
total
number
The total price of all items in the cart in the smallest currency unit (e.g., cents)
currency
string
The currency code (e.g., usd, eur, gbp)

Example

import { createStorefrontClient } from '@paynow-gg/sdk';

const storefront = createStorefrontClient('store-id', 'customer-token');

// Get cart with default currency
const { data: cart } = await storefront.cart.getCart();

console.log(`Cart total: ${cart.total} ${cart.currency}`);
console.log(`Items in cart: ${cart.lines.length}`);

// Get cart with specific currency
const { data: cartEur } = await storefront.cart.getCart({
  params: { currency: 'eur' }
});

// Get cart with customer IP for accurate VAT calculation
const { data: cartWithVat } = await storefront.cart.getCart({
  headers: {
    'x-paynow-customer-ip': '203.0.113.42',
    'x-paynow-customer-countrycode': 'DE'
  }
});

Add Line

Adds a product to the cart or updates the quantity of an existing product.
storefront.cart.addLine(config)

Parameters

config
object
required
Configuration object for the request

Returns

Returns 204 No Content on success.

Example

// Add a product to cart (set quantity to 1)
await storefront.cart.addLine({
  params: {
    product_id: '411486491630370816',
    quantity: 1
  }
});

// Increment quantity (add 2 more)
await storefront.cart.addLine({
  params: {
    product_id: '411486491630370816',
    quantity: 2,
    increment: 'true'
  }
});

// Add subscription product
await storefront.cart.addLine({
  params: {
    product_id: '411486491630370816',
    quantity: 1,
    subscription: 'true'
  }
});

// Add product with custom variables
await storefront.cart.addLine({
  params: {
    product_id: '411486491630370816',
    quantity: 1,
    custom_variables: {
      'player-name': 'JohnDoe',
      'server-region': 'us-east'
    }
  }
});

// Add product as a gift
await storefront.cart.addLine({
  params: {
    product_id: '411486491630370816',
    quantity: 1,
    'gift_to.platform': 'steam',
    'gift_to.id': '76561198152492642'
  }
});

// Add product with game server selection
await storefront.cart.addLine({
  params: {
    product_id: '411486491630370816',
    quantity: 1,
    gameserver_id: '411486491630370820'
  }
});

Clear Cart

Clears all items from the customer’s shopping cart.
storefront.cart.clearCart(config?)

Parameters

config
object
Configuration object for the request

Returns

Returns 204 No Content on success.

Example

// Clear the cart
await storefront.cart.clearCart();

console.log('Cart cleared successfully');

Create Cart Checkout

Creates a checkout session from the contents of the cart. After creating the checkout session, redirect the customer to the returned URL.
storefront.cart.createCartCheckout(config?)

Parameters

config
object
Configuration object for the request

Returns

Returns a checkout session object:
id
string
The checkout session ID
token
string
The token for the checkout session
url
string
The URL to redirect the customer to complete checkout

Example

// Create basic checkout from cart
const { data: checkout } = await storefront.cart.createCartCheckout();

console.log('Checkout URL:', checkout.url);
// Redirect customer to checkout.url
window.location.href = checkout.url;

// Create checkout with coupon
const { data: checkoutWithCoupon } = await storefront.cart.createCartCheckout({
  data: {
    coupon_id: '411486491630370817'
  }
});

// Create checkout with return URLs
const { data: checkoutWithUrls } = await storefront.cart.createCartCheckout({
  data: {
    return_url: 'https://example.com/success',
    cancel_url: 'https://example.com/cancel',
    auto_redirect: true
  }
});

// Create checkout with affiliate tracking
const { data: checkoutWithAffiliate } = await storefront.cart.createCartCheckout({
  data: {
    affiliate_code: 'PARTNER123',
    return_url: 'https://example.com/success'
  }
});

Cart Line Items

Each cart line item (CartLineDto) contains:
line_key
string
The unique key for this line item
product_id
string
The product ID
name
string
The name of the product
slug
string
The slug of the product
price
number
The price of the product in the smallest currency unit (e.g., cents)
quantity
number
The quantity of this product in the cart
subscription
boolean
Indicates whether this line item is a subscription
trial
boolean
Indicates whether this line will be trialed by the customer
image_url
string
The URL to the product image
selected_gameserver_id
string
The selected game server ID
pricing
object
Detailed pricing information including sales and VAT
custom_variables
array
Selected custom variables for this cart line
gift_to_customer_id
string
The customer ID this line is a gift for

Best Practices

When making server-side requests, always include the customer’s IP address to ensure accurate VAT calculation and regional pricing:
await storefront.cart.getCart({
  headers: {
    'x-paynow-customer-ip': customerIp,
    'x-paynow-customer-countrycode': customerCountry
  }
});
When updating quantities, use the increment parameter to add to existing quantities rather than replacing them:
// Add 2 more items
await storefront.cart.addLine({
  params: {
    product_id: 'product-id',
    quantity: 2,
    increment: 'true'
  }
});
When products have custom variables, ensure you provide all required variables:
await storefront.cart.addLine({
  params: {
    product_id: 'product-id',
    custom_variables: {
      'required-variable': 'value',
      'optional-variable': 'value'
    }
  }
});
After creating a checkout session, always redirect the customer to the returned URL:
const { data } = await storefront.cart.createCartCheckout();
window.location.href = data.url;

Build docs developers (and LLMs) love