Checkout Widget
The Checkout widget in Zoho Payments provides a streamlined and secure way to facilitate payments directly on your website. Use the Checkout Widget APIs to embed the widget on your website and collect payments.
Prerequisites
- An active Zoho Payments account.
- An API Key. You can generate one under
Zoho Payments > Settings > Developer Space
.
Note : Only users with Account Owner, Admin, or Developer roles in Zoho Payments can generate and view API keys.
Integrate Widget
To use Zoho Payments' checkout widget in your application, add this script to your webpage.
<script src="https://static.zohocdn.com/zpay/zpay-js/v1/zpayments.js"></script>
Instance Creation
Create an instance for Zoho Payments using the following parameters:
config parameter
US
).
let config = {
"account_id": "23137556",
"domain": "US",
"otherOptions" : {
"api_key": "1000.41d9xxxxxxxxxxxxxxxxxxxxxxxxc2d1.8fccxxxxxxxxxxxxxxxxxxxxxxxx125f"
}
}
let instance = new window.ZPayments(config);
Initiate Payment
Initiate a payment using the following code.
options parameter
add
or payment
.
USD
).Show list of supported currencies
$
.
card
or ach_debit
. If no payment method is provided, payment methods that are enabled for your Zoho Payments account will be displayed.response
After initiating the payment successfully, the checkout widget will return a response with the payment_id
Refer to our developer documentation for detailed instructions on integrating the checkout widget.
async function initiatePayment()
{
try {
let options = {
"amount": "100.5",
"transaction_type": "payment",
"currency_code": "USD",
"payments_session_id": "2000000012001",
"currency_symbol": "$",
"business": "Zylker",
"description": "Purchase of Zylker electronics.",
"invoice_number": "INV-12345",
"address": {
"name": "Canon",
"email": "canonbolt@zylker.com",
"phone": "98XXXXXXXX"
}
};
let data = await instance.requestPaymentMethod(options);
} catch (err) {
if (err.code != 'widget_closed') {
// Handle Error
}
} finally {
await instance.close();
}
}
initiatePayment();
{
"payment_id": "2299000000189035",
"message": "Payment successful!"
}
{
"code": "error",
"message": "Payment failed!"
}
Save Payment Method
Save a payment method using the following code.
options parameter
card
or ach_debit
.
add
or payment
.
name
field.email
field.address_line1
field.address_line2
field.city
field.state
field.country
field.postal_code
field.response
After initiating the payment successfully, the checkout widget will return a response with the payment_method_id
Refer to our developer documentation for detailed instructions on integrating the checkout widget.
async function saveCard()
{
try {
let options = {
"payment_method": "card",
"transaction_type": "add",
"customer_id": '12345678',
"payment_method_session_id": "2000000012001",
"address": {
"name": "Canon",
"email": "canonbolt@zylker.com",
"address_line1": "Address Line 1",
"address_line2": "Address Line 2",
"city": "City",
"state": "State",
"country": "Country",
"postal_code": "123456"
}
};
let data = await instance.requestPaymentMethod(options);
} catch (err) {
if (err.code != 'widget_closed') {
// Handle Error
}
} finally {
await instance.close();
}
}
saveCard();
async function saveBankAccount()
{
try {
let options = {
"payment_method": "ach_debit",
"transaction_type": "add",
"customer_id": '12345678',
"payment_method_session_id": "2000000012001"
};
let data = await instance.requestPaymentMethod(options);
} catch (err) {
if (err.code != 'widget_closed') {
// Handle Error
}
} finally {
await instance.close();
}
}
saveBankAccount();
{
"payment_method_id": "2299000000189035",
"message": "Payment method added successfully!"
}
{
"code": "error",
"message": "Error while adding payment method!"
}