Note: The {checkoutId} is the identifier for the checkout, which you have created in the previous step.
Embedded widget has a fixed width of 392px
3. Define JavaScript callback [optional]
Provide a JavaScript function to receive checkout status updates and adjust your frontend accordingly.
// Define callback function
function handleCheckoutStatusChange(event) {
const checkoutId = event.detail.id;
const status = event.detail.status;
console.log(`Callback Invoked: checkoutId=${checkoutId}, status=${status}`);
// Handle the status change according to your business logic
if (status === 'SUCCESS') {
// Payment was successful, update the frontend accordingly
} else if (status === 'CONFLICT') {
// Payment is in conflict, update the frontend accordingly
}
}
// Wait for the widget to load
document.addEventListener('DOMContentLoaded', function() {
const widget = document.querySelector('app-widget');
// Register "handleCheckoutStatusChange()" for receiving callbacks
if (widget) {
widget.addEventListener('statusChanged', handleCheckoutStatusChange);
}
});
In this example, the handleCheckoutStatusChange function is called whenever the status of the checkout changes. The checkoutId and status are then extracted from the event.details object and used to update the frontend according to the business logic of the merchant.
The widget variable is initialized to the app-widget element which represents the crypto widget. An event listener is then added to the widget that listens for status changes. When a status change occurs, the handleCheckoutStatusChange function is called with the event object as an argument.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payment Widget Test Page</title>
<script src="https://paycrypto.inqud.com/widget.js" defer></script>
</head>
<body>
<h1>Payment Widget Test</h1>
<app-widget id="YOUR_CHECKOUT_ID"></app-widget>
<script>
// Define callback function
function handleCheckoutStatusChange(event) {
const checkoutId = event.detail.id;
const status = event.detail.status;
console.log(`Callback Invoked: checkoutId=${checkoutId}, status=${status}`);
// Handle the status change according to your business logic
if (status === 'SUCCESS') {
// Payment was successful, update the frontend accordingly
console.log('Payment Successful');
} else if (status === 'CONFLICT') {
// Payment is in conflict, update the frontend accordingly
console.log('Payment Conflict');
}
}
// Wait for the widget to load
document.addEventListener('DOMContentLoaded', function() {
const widget = document.querySelector('app-widget');
// Register "handleCheckoutStatusChange()" for receiving callbacks
if (widget) {
widget.addEventListener('statusChanged', handleCheckoutStatusChange);
}
});
</script>
</body>
</html>
4. Receive a web-hook notification related to the checkout
Visit the to learn more about the various checkout statuses.
The response example provided is a shortened version and does not include the full set of fields. For the complete response body details, please refer to the full .
The response example provided is a shortened version and does not include the full set of fields. For the complete response body details, please refer to the full .
come from the widget settings and cannot be changed via REST API requests.
The response example provided is a shortened version and does not include the full set of fields. For the complete response body details, please refer to the full .