Skip to main content

Checkout SDK - Your page. COPE payments. Seamlessly connected.

The COPE Checkout SDK is a browser SDK (a library that simplifies integrating COPE into your project) for buyer checkout flows. It gives you control over the product page and shopping experience, while COPE handles payment collection, tax calculation, and order creation.

Use the SDK when your site owns the product and shopping experience - and COPE owns the rest.

📄 Full documentation: [Checkout SDK overview - COPE]


Installation

bash

npm install @copecart/sdk

ts

import { CopeCart } from "@copecart/sdk"  const cope = new CopeCart({   publishableKey: "cope_pk_live_...", })

Without a bundler – global build:

html

<script src="https://unpkg.com/@copecart/sdk@latest/dist/index.global.js"></script> <script>   const cope = new CopeCart.CopeCart({     publishableKey: "cope_pk_live_...",   }) </script>

The SDK requires HTTPS – except for http://localhost during development.


Configuration

Option

Required

Default

Notes

publishableKey

Yes

Starts with cope_pk_, safe to use in browser code

baseUrl

No

COPE production API

Override only when COPE support instructs you to

checkoutBaseUrl

No

Origin of baseUrl

Used to validate checkout URLs returned by the API


Typical flow

ts

const product = await cope.getProduct("prd_...") const cart = await cope.createCart({ currency: product.currency })  await cope.addLine(cart.id, {   product_id: product.id,   plan_id: product.payment_plans[0].id,   quantity: 1, })  await cope.setBuyerIdentity(cart.id, {   email: "buyer@example.com",   tax_location: { country: "DE", postal_code: "10115" }, })  await cope.reprice(cart.id)  const checkout = await cope.checkout(cart.id, {   success_url: "https://your-site.example/thank-you",   cancel_url: "https://your-site.example/cart",   consents: [{ type: "buyer_tos" }], })  cope.redirectToCheckout(checkout)

After successful payment, COPE redirects to success_url with order_id appended:

https://your-site.example/thank-you?order_id=ord_...

Core methods

Method

Purpose

getProduct(productId)

Fetch product details and payment plans

createCart(payload)

Create a cart and store the checkout credential

addLine(cartId, payload)

Add a product, plan, and quantity

setBuyerIdentity(cartId, payload)

Set buyer location and contact data for tax and checkout

reprice(cartId)

Calculate taxes, discounts, and final totals

checkout(cartId, payload)

Create a hosted checkout session

redirectToCheckout(checkout)

Navigate the browser to hosted checkout

cancelCheckout(checkoutId)

Cancel an open checkout session


Error handling

ts

import {   CopeApiError,   CopeCartExpiredError,   CopeNetworkError, } from "@copecart/sdk"  try {   await cope.reprice(cart.id) } catch (error) {   if (error instanceof CopeApiError) {     console.log(error.status, error.code, error.errors)   }   if (error instanceof CopeCartExpiredError) {     const replacement = await cope.createCart({ currency: "EUR" })   }   if (error instanceof CopeNetworkError) {     console.log("Retry later")   } }

Treat 4xx errors as permanent – fix the payload and retry with a new request. The SDK automatically retries selected transient network or server failures with backoff.


Use cases

Custom product page
You build the UI, COPE handles payment collection, tax calculation, and order creation. Ideal when you want full control over the buying experience without building your own payment backend.

Multi-plan products
Dynamically fetch payment plans from COPE and present them to the buyer – monthly, annual, one-time. The SDK returns all available plans directly with the product.

Payment links
Create a checkout session server-side and send the hosted_checkout_url via email, WhatsApp, or CRM – no custom checkout UI needed.

Fast go-live
Quick integration without a custom payment backend. COPE handles PCI compliance, tax logic, and the entire payment flow.

Did this answer your question?