Skip to main content

Overview

The Cheqpay Checkout SDK allows you to embed a payment form directly into your website, giving you control over the checkout experience while Cheqpay handles the secure payment processing.
The SDK provides a seamless, embedded checkout experience without redirecting customers away from your site.

Installation

Include the Cheqpay Checkout SDK in your HTML page by adding the script tag:
The SDK will be available globally as Cheqpay after the script loads.

Quick Start

Here’s a minimal example to get you started:

Integration Steps

Step 1: Initialize the SDK

Before using any SDK methods, you must initialize it with your API key and environment:
Always use your public API key (starts with pk_) in the SDK. Never expose your secret API key in client-side code.

Step 2: Load the Payment Form

Load the payment form into a container element on your page:
The SDK will render a fully functional payment form inside the specified container.

Step 3: Process the Payment

When the customer submits the form, call authorize to process the payment:

Step 4: Clean Up (Optional)

When you’re done with the checkout (e.g., after payment completion or page navigation), clean up the SDK:
This removes all event listeners and DOM elements created by the SDK.

Complete Example

Here’s a complete example with error handling and user feedback:

API Reference

Cheqpay.Checkout.init(config)

Initializes the SDK with your API key and environment. Parameters:
  • config.apiKey (string, required): Your public API key
  • config.environment (string, required): 'sandbox' or 'live'
Returns: Promise Example:

Cheqpay.Checkout.load(options)

Loads the payment form into the specified container. Parameters:
  • options.container (string, required): CSS selector for the container element
Returns: Promise Example:

Cheqpay.Checkout.authorize(paymentDetails, callback)

Processes the payment with the provided payment details. Parameters:
  • paymentDetails (object, required):
    • amount (number): Payment amount
    • currency (string): Currency code (e.g., ‘MXN’, ‘USD’)
    • description (string, optional): Payment description
    • merchantReference (string, optional): Your order reference
    • customer (object, required):
      • firstName (string, required)
      • lastName (string, optional)
      • email (string, required)
      • phone (string, optional)
    • billingAddress (object, required):
      • addressLine1 (string, required)
      • addressLine2 (string, optional)
      • city (string, required)
      • state (string, optional)
      • postalCode (string, optional)
      • country (string, required)
  • callback (function, required): Callback function (error, orderData) => void
Example:

Cheqpay.Checkout.destroy()

Cleans up the SDK and removes all event listeners and DOM elements. Example:

Error Handling

Always handle errors in the authorize callback:

Best Practices

  • Always use your public API key (starts with pk_) in client-side code
  • Never expose your secret API key
  • Use HTTPS in production
  • Show loading states during initialization and payment processing
  • Handle network errors gracefully
  • Test the integration thoroughly in sandbox before going live
  • Load the SDK asynchronously to avoid blocking page render
  • Clean up the SDK when navigating away from the checkout page
  • Consider lazy loading the SDK only when needed
Test cards and scenarios are available in the Testing Guide.

Next Steps