<script>
document.addEventListener('DOMContentLoaded', () => {
fetch('/create-payment-session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: 5000, currency: 'USD' })
})
.then(response => response.json())
.then(data => {
const securepay = SecurePay('YOUR_PUBLIC_KEY');
securepay.init({
sessionId: data.sessionId,
containerId: 'payment-form',
onSuccess: (response) => {
// Handle successful payment
console.log(response);
},
onFailure: (error) => {
// Handle payment failure
console.error(error);
}
});
});
});
</script>