The Checkout API redirects customers to Shoppex’s hosted checkout page. The checkout is fully hosted by Shoppex for PCI compliance.
checkout
Redirects the customer to the checkout page with their cart contents.
await shoppex . checkout ();
Parameters
Automatically redirect to checkout page
Override checkout language
Example: Checkout with Coupon
const couponCode = document . getElementById ( 'coupon-input' ). value ;
if ( couponCode ) {
// Validate coupon first
const { data } = await shoppex . validateCoupon ( couponCode );
if ( ! data . valid ) {
alert ( 'Invalid coupon code' );
return ;
}
}
// Proceed to checkout
await shoppex . checkout ( couponCode );
buildCheckoutUrl
Builds the checkout URL without redirecting. Useful for opening in a new tab or iframe.
const checkoutUrl = await shoppex . buildCheckoutUrl ( 'SAVE10' , 'de' );
console . log ( checkoutUrl );
// https://yourstore.shoppex.io/checkout?coupon=SAVE10&locale=de&cart=...
Parameters
Checkout language (e.g., ‘en’, ‘de’, ‘fr’)
Example: Open Checkout in New Tab
async function openCheckoutInNewTab () {
const url = await shoppex . buildCheckoutUrl ();
window . open ( url , '_blank' );
}
buildCheckoutUrlSync
Synchronous version that uses the default domain. Does not support custom domains.
const url = shoppex . buildCheckoutUrlSync ( 'SAVE10' );
// Returns immediately, no async needed
Use buildCheckoutUrl() (async) if your store uses a custom domain. The sync version only works with .shoppex.io subdomains.
Coupons
validateCoupon
Validates a coupon code before checkout.
const { data } = await shoppex . validateCoupon ( 'SAVE10' , 'prod_abc123' );
if ( data . valid ) {
console . log ( 'Discount:' , data . discount , data . discount_type );
// 10, "percentage" → 10% off
// 5.00, "fixed" → $5 off
} else {
console . log ( 'Invalid or expired coupon' );
}
Parameters
Product ID to check product-specific coupons
Response
Whether the coupon is valid
Either “percentage” or “fixed”
< div class = "coupon-form" >
< input type = "text" id = "coupon-input" placeholder = "Enter coupon code" >
< button onclick = " applyCoupon ()" > Apply </ button >
< span id = "coupon-status" ></ span >
</ div >
< script >
let appliedCoupon = null ;
async function applyCoupon () {
const code = document . getElementById ( 'coupon-input' ). value . trim ();
const status = document . getElementById ( 'coupon-status' );
if ( ! code ) {
status . textContent = '' ;
return ;
}
const { data } = await shoppex . validateCoupon ( code );
if ( data . valid ) {
appliedCoupon = code ;
if ( data . discount_type === 'percentage' ) {
status . textContent = ` ${ data . discount } % off applied!` ;
} else {
status . textContent = `$ ${ data . discount } off applied!` ;
}
status . className = 'success' ;
} else {
appliedCoupon = null ;
status . textContent = 'Invalid coupon' ;
status . className = 'error' ;
}
}
async function goToCheckout () {
await shoppex . checkout ( appliedCoupon );
}
</ script >
Checkout Flow
┌─────────────────────────────────────────────────────────────────┐
│ Your Website │
├─────────────────────────────────────────────────────────────────┤
│ 1. Customer browses products │
│ 2. Adds items to cart (SDK stores in localStorage) │
│ 3. Clicks "Checkout" │
│ 4. SDK calls shoppex.checkout() │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Shoppex Checkout │
│ (yourstore.shoppex.io) │
├─────────────────────────────────────────────────────────────────┤
│ 5. Customer enters email, billing info │
│ 6. Selects payment method (Stripe, PayPal, Crypto) │
│ 7. Completes payment │
│ 8. Receives confirmation + delivery │
└─────────────────────────────────────────────────────────────────┘
After Checkout
After successful checkout, the cart is automatically cleared. If you need to handle the return:
// Check URL for order confirmation
const urlParams = new URLSearchParams ( window . location . search );
const orderId = urlParams . get ( 'order' );
if ( orderId ) {
// Customer returned from successful checkout
showOrderConfirmation ( orderId );
}