Skip to main content

Web Payment

Payment API:

async function doPaymentRequest() {
try {
// new PaymentRequest(paymentMethods, paymentDetails);
const request = new PaymentRequest(
[
{
supportedMethods: 'https://bobpay.xyz/pay',
},
],
{
total: {
label: 'total',
amount: { value: '10', currency: 'USD' },
},
}
)
const response = await request.show()
await validateResponse(response)
} catch (err) {
// AbortError, SecurityError
console.error(err)
}
}

async function validateResponse(response) {
try {
const errors = await checkAllValuesAreGood(response)

if (errors.length) {
await response.retry(errors)
return validateResponse(response)
}

await response.complete('success')
} catch (err) {
// Something went wrong…
await response.complete('fail')
}
}

doPaymentRequest()

Web Payment Workflow