Untitled
3 years ago in Plain Text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Title</title>
</head>
<body onload="check()">
<button onclick="pay()">Pay</button>
</body>
<script>
function check() {
/**
* PaymentRequest API is only available in the modern browsers which
* have Promise API.
*/
try {
new PaymentRequest(
[
{
supportedMethods: ['https://cred.club/checkout/pay'],
},
],
{
total: {
label: '_',
amount: { currency: 'INR', value: '10.00' },
},
}
)
.canMakePayment()
.then(isAvailable => {
if (isAvailable) {
alert('available');
} else {
alert('not available');
}
})
/* jshint ignore:start */
.catch(e => {
window.console.log('rejected', e);
alert('not available');
});
/* jshint ignore:end */
} catch (e) {
window.console.log('caught', e);
alert('not available');
}
}
function pay() {
const supportedInstruments = [
{
supportedMethods: ['https://cred.club/checkout/pay'],
data: {
url:
'credpay://checkout?ref_id=76cac2d9-0477-47e7-a75c-e71a604720cf&is_collect=false',
},
},
];
const details = {
total: {
label: 'Payment',
amount: {
currency: 'INR',
value: '10.00',
},
},
};
new PaymentRequest(supportedInstruments, details)
.show()
.then(() => alert('success'))
.catch(e => {
console.dir(e);
alert('failure');
});
}
</script>