The Anypay Web3 Checkout is a Javascript library that enables developers to easily integrate cryptocurrency payments into their web applications. This produces a browser payment pop-up.
To get started with Anypay Web3 Checkout, follow these steps:
anypay.js
and web3-checkout.js
scripts in your HTML file.anypayCheckout.init()
function with your API key and secret.Include the Anypay.js browser SDK in your website.
<script src="https://anypayinc.s3.amazonaws.com/anypay.0.2.0.min.js"></script>
Then request payment to one or more recipients, for one or more coins including BTC, BCH, BSV, LTC, DASH. Your app will be automatically notified when payment is complete.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Anypay Web3 Checkout Example</title>
<script src="https://cdn.anypayinc.com/anypay.js"></script>
<script src="web3-checkout.js"></script>
</head>
<body>
<button id="checkout-button">Pay with Anypay</button>
<script>
anypayCheckout.init({
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET',
});
</script>
</body>
</html>
The Anypay Web3 Checkout library provides the following functions and methods:
anypayCheckout.init(options)
Initializes the Anypay Web3 Checkout with the specified API key and secret.
anypayCheckout.openCheckout(options)
Opens the Anypay Web3 Checkout dialog with the specified options.
anypayCheckout.closeCheckout()
Closes the Anypay Web3 Checkout dialog.
anypayCheckout.setCheckoutCallback(callback)
Sets the callback function to be called after a payment has been made.
Here are some examples of how to use the Anypay Web3 Checkout library:
anypayCheckout.openCheckout({
amount: 100,
currency: 'USD',
description: 'Test payment',
cryptoCurrency: 'BTC',
successUrl: 'https://example.com/success',
cancelUrl: 'https://example.com/cancel',
});
anypayCheckout.setCheckoutCallback(function(payment) {
console.log('Payment made:', payment);
});
anypay.collectPayment({
accountId: '1177',
amount: 2.00
})
.once('paid', () => {
console.log('Invoice paid');
setTimeout(() => {
anypay.close();
}, 2000);
})
If you already have created an invoice using the Anypay Payments API you can provide its uid to the Anypay.js Web SDK to display the pop up user interface to the user like so:
// modeal display QR code payment screen to user
anypay.showInvoice(INVOICE_UID).on('paid', console.log)
<script>
let invoice = anypay.newPayment({
template: [{
currency: 'DASH',
to: [{
currency: 'USD',
amount: 150,
address: 'XhEh7yEzbJtViSrmJEiJ73CVp1C37j8eW7'
}, {
currency: 'USD',
amount: 10,
address: 'XnEw2KjfLVAy1hSXMFWLCcod5X7rLM581p'
}]
}],
options: {
webhook: 'https://paypow.com/anypay/webhooks/payments',
redirect: 'https://paypow.com/anypay//payments'
}
})
invoice.once('paid', paidInvoice => {
// the invoice was paid, guaranteed perfectly correct!
anypay.close() // close iframe popup
})
</script>
If you have any questions or issues with the Anypay Web3 Checkout, please visit the Anypay support page at https://anypayx.com/faq or create a Github issue at https://github.com/anypay/web3-checkout/issues.
The Anypay Web3 Checkout library is open source software released under the MIT License. See the LICENSE file for more details.