Shopping cart API

Modern, cross platform, persistent cart and checkout logic for websites and applications from our centralized backend.

Powerful cart interaction

Whether you’re inserting or removing items from the cart, retrieving the contents, applying discounts and more, it’s as simple as an API call.

// Add a product to a cart
async function addToCart() {
  try {
    // Get all products in your store
    const products = await Moltin.Products.All();
    const product = products.data[0];
    
    // Add the first product to the cart
    return Moltin.Cart().AddProduct(product.id);
  } catch (e) {
  	e.errors.forEach(err => {
    	throw new Error(err.detail);
    });
  };
};
function addToCart() {
    try {
      // Get all products
      $products = $moltin->products->all();
      $product = $products->data()[0];

      // Add the first product to the cart
      return $moltin->cart()->addProduct($product->id);
    } catch (Exception $e) {
      echo 'An exception occurred calling the Moltin API';
    }
  }

Streamlined checkout

Use the cart’s API as a single service or combine with our orders service through the simple checkout API.

// Checkout the cart and pay for the order
async function checkoutCart() {
  const address = {
    first_name: 'Jon',
    last_name: 'Doe',
    line_1: '123 Sunny Street',
    postcode: 'CA94040',
    county: 'California',
    country: 'US'
  };

  const customer = {
    email: 'john@doe.co',
    name: 'John Doe'
  };

  try {
    // Checkout the cart and create an order
    const order = await Moltin.Cart().Checkout(customer, address);

    // Pay for the order using Stripe
    return Moltin.Orders.Payment(order.data.id, {
      gateway: 'stripe',
      method: 'purchase',
      first_name: 'John',
      last_name: 'Doe',
      number: '4242424242424242',
      month: '02',
      year: '2020',
      verification_value: '123'
    });
  } catch (e) {
    e.errors.forEach(err => {
      throw new Error(err.detail);
    });
  };
};
function checkoutCart() {
        $address = [
          'first_name' => 'Jon',
          'last_name' => 'Doe',
          'line_1' => '123 Sunny Street',
          'postcode' => 'CA94040',
          'county' => 'California',
          'country' => 'US'
        ];
      
        try {
          // Checkout the cart and create an order
          $order = $moltin->cart->checkout(
            'customer' => [
                'name' => 'John Doe',
                'email' => 'john@doe.co'
            ],
            'billing_address' => $address,
            'shipping_address' => $address
          );
      
          // Pay for the order using Stripe
          return $order->pay(
            'stripe',
            'purchase',
            [
              'first_name' => 'John',
              'last_name' => 'Doe',
              'number' => '4242424242424242',
              'month' => '02',
              'year' => '2020',
              'verification_value' => '123'
            ]
          );
        } catch (Exception e) {
          echo 'An exception occurred calling the Moltin API';
        }
      } 
shopping-cart

Cross-platform carts

Provide a seamless shopping experience with our persistent cloud based carts that are accessible from any device.

defined
Pre-defined products
Securely create Moltin products and quickly add these to carts with one API call.
custom
Custom line items
Add products from a third party system, static HTML or let your customers define them.

Payment processing

When you’re ready to take payments for orders, let us do the heavy lifting for the most popular payment gateways through gateway aggregation.

Learn More
invite-orange
Introduce your developer
Developers love Moltin for its flexibility and simplicity. Send them a link to this page - trust us, they'll be grateful for it. Share a link 
talk-orange
Talk to a Moltin expert
For product inquiries or to chat to a member of our team directly, send us an email and we'll get back to you. Contact us

Let's build something amazing with Moltin

It always starts with a conversation.