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: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:Step 2: Load the Payment Form
Load the payment form into a container element on your page:Step 3: Process the Payment
When the customer submits the form, callauthorize 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: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 keyconfig.environment(string, required):'sandbox'or'live'
Cheqpay.Checkout.load(options)
Loads the payment form into the specified container.
Parameters:
options.container(string, required): CSS selector for the container element
Cheqpay.Checkout.authorize(paymentDetails, callback)
Processes the payment with the provided payment details.
Parameters:
paymentDetails(object, required):amount(number): Payment amountcurrency(string): Currency code (e.g., ‘MXN’, ‘USD’)description(string, optional): Payment descriptionmerchantReference(string, optional): Your order referencecustomer(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
Cheqpay.Checkout.destroy()
Cleans up the SDK and removes all event listeners and DOM elements.
Example:
Error Handling
Always handle errors in theauthorize callback:
Best Practices
Security
Security
- Always use your public API key (starts with
pk_) in client-side code - Never expose your secret API key
- Use HTTPS in production
User Experience
User Experience
- Show loading states during initialization and payment processing
- Handle network errors gracefully
- Test the integration thoroughly in sandbox before going live
Performance
Performance
- 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
Next Steps
- Learn about the Hosted Payment Page integration
- Review Error Handling best practices
- Check the API Reference for complete API documentation