Skip to main content

JavaScript Checkout SDK

Curacel Pay provides a JavaScript SDK that businesses can integrate into their websites to easily accept payments.

Step 1: Generate API Keys

To start using the SDK, you'll need to generate API keys for your account.

  1. Go to Settings > API Configuration on your Curacel Pay dashboard.
  2. Copy your public API key (Note: do not use your secret API key, which is intended for server-side use).

Step 2: Embed the SDK

Add the following script to the <head> section of your webpage to load the Curacel Pay SDK:

For the production environment:

<script src="https://pay.curacel.co/sdk/collect.js"></script>

For the sandbox environment:

<script src="https://sandbox.pay.curacel.co/sdk/collect.js"></script>

Step 3: Initialize the Payment

You can now initiate the payment process using the SDK by adding this JavaScript code:

<script>
const payment = CuracelPay.setup({
apiKey: "CUR_PK_YOUR_PUBLIC_KEY",
amount: "5000",
description: "Subscription for new service",
email: "hulk@avengers.com",
currency: "NGN",
reference: "YOUR_UNIQUE_REFERENCE",
metadata: {
ip_address: "127.0.0.1",
},
callback: function (payment) {
console.log(payment);
},
});

payment.pay(); // Trigger the payment process
</script>

Field Descriptions:

  • apiKey: This is your public API key that you obtained from the API Configuration page. It's required for authenticating the request.
  • amount: The total amount to charge the customer in the currency of initiation. (e.g 5000 for 5000 NGN)
  • description: A brief description of the payment.
  • email: The email address of the customer making the payment.
  • currency: The currency for the transaction. Use the standard 3-letter currency codes (e.g., NGN for Naira, USD for US Dollar). Note that an error will be returned if your account isn't authorized to receive payments in this currency
  • reference: A unique payment reference generated by your system. This helps in identifying each transaction.
  • metadata: (Optional) An object to include any additional data related to the payment (e.g., customer ID, order ID).
  • callback: A function that is triggered after the payment is completed. The payment object passed to this function contains the details of the payment.
note

Make sure the script is added after your page's content to ensure it loads properly, and your API key is handled securely.