<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paysight Widget Example</title>
<!-- Add the Paysight Widget SDK -->
<script src="https://payment.paysight.io/widget-sdk.js"></script>
<style>
.container {
max-width: 600px;
margin: 40px auto;
padding: 20px;
}
.widget-container {
border: 1px solid #e5e7eb;
border-radius: 8px;
padding: 20px;
}
.status {
padding: 12px;
border-radius: 6px;
margin-bottom: 16px;
display: none;
}
.error {
background-color: #fee2e2;
border: 1px solid #ef4444;
color: #b91c1c;
}
.success {
background-color: #dcfce7;
border: 1px solid #22c55e;
color: #15803d;
}
</style>
</head>
<body>
<div class="container">
<div id="success-message" class="status success"></div>
<div id="error-message" class="status error"></div>
<div id="widget-container" class="widget-container"></div>
</div>
<script>
// Initialize widget
const widget = PaysightSDK.createWidget({
targetId: 'widget-container',
config: {
// Required parameters
productId: 7900, // replace with your actual product ID
sessionId: new Date().getTime().toString(),
environment: 'sandbox',
amount: 1.00,
// Pre-filled customer data
customer: {
email: 'customer@example.com',
firstName: 'John',
lastName: 'Doe',
state: 'CA',
country: 'US'
},
fields: [
{
label: 'Email Address',
placeholder: 'Enter your email',
fieldType: 'email',
position: 'above',
size: 'full',
},
{
label: 'Full Name',
placeholder: 'Enter your full name',
fieldType: 'name',
position: 'above',
size: 'full'
},
{
label: 'Country',
placeholder: 'Select your country',
fieldType: 'country',
position: 'above',
size: 'half'
},
{
label: 'State/Province',
placeholder: 'Enter your state',
fieldType: 'state',
position: 'above',
size: 'half'
}
],
// Optional parameters
threeDSRequired: false,
currency: 'USD',
locale: 'en-US',
buttonText: 'Pay Now',
// Additional data for tracking
data: {
clickId: 'campaign-123',
gclid: 'CjwKCAiAzc2tBhA4EiwA5gFXtqxZQn8H9XdF9jKm',
wbraid: 'CLjQ5oGVqvsCFQiNaAodgM4PqA',
gbraid: 'CLjQ5oGVqvsCFQiNaAodgM4PqA'
}
},
onReady: () => {
console.log('Widget is ready');
},
onError: (error) => {
const errorElement = document.getElementById('error-message');
errorElement.textContent = error.message;
errorElement.style.display = 'block';
console.error('Widget error:', error);
},
onMessage: (message) => {
switch (message.type) {
case 'PAYMENT_SUCCESS':
const successElement = document.getElementById('success-message');
successElement.textContent = `Payment successful! Transaction ID: ${message.payload.transactionId}`;
successElement.style.display = 'block';
break;
case 'PAYMENT_ERROR':
const errorElement = document.getElementById('error-message');
errorElement.textContent = message.payload.message;
errorElement.style.display = 'block';
break;
}
}
});
// Example of updating customer data later
function updateCustomerData() {
widget.update({
customer: {
email: 'updated@example.com',
firstName: 'Jane',
lastName: 'Smith',
phone: '+1234567890',
address: '123 Main St',
city: 'Anytown',
state: 'NY',
zip: '00000',
country: 'US'
}
});
}
</script>
</body>
</html>