Payment gateway for NANO
accept-btco-client is a JavaScript package that helps you to communicate with accept-btco for receiving NANO payments easily in your client-side applications.
npm install accept-btco
yarn add accept-btco
import * as acceptBtco from 'accept-btco'
const acceptBtco = require('accept-btco')
After the accept-btco-client script is loaded there will be a global variable called acceptBtco, which you can access via window.acceptBtco
<html>
<head>
...
<script src="https://unpkg.com/accept-btco@2"></script>
</head>
...
</html>
To be able to initiate the payment process, you must create a new payment session.
// 1- create a new payment session
type CreateSessionParams = {
apiHost: string // host of your Accept NANO server, without protocol
pollInterval?: number // time interval (ms) to re-check for verification of a payment (default: 3s)
debug?: boolean // enables debug mode and prints some useful stuff to console
}
const session = acceptBtco.createSession({
apiHost: 'accept-btco-demo.put.io',
})
// 2- register event listeners to shape-up your logic based on session events.
type PaymentSessionEvents = {
start: () => void
end: (error: PaymentError | null, payment: AcceptBtcoPayment | null) => void
}
session.on('start', () => {
myApp.paymentStarted()
})
session.on('end', (error, payment) => {
if (error) {
return myApp.paymentFailed({ reason: error.reason })
}
return myApp.paymentSucceeded({
amount: payment.amount,
state: payment.state,
})
})
After creating your session and attaching the event listeners, you can follow one of those options to proceed with the payment flow.
If you want to create and verify an accept-btco payment in your client application, you can use this option.
After the payment is created, accept-btco-client will automatically proceed to the verification step.
type CreatePaymentParams = {
amount: string // stringified number
currency: 'NANO' | 'USD'
state?: string // payload to share between your client and server, will be embedded into the payment object
}
session.createPayment({
amount: '1',
currency: 'USD',
state: '{userId:7}',
})
If you create an accept-btco payment in another context (such as your application's backend), you can use this option to perform the verification in your client application.
type VerifyPaymentParams = {
token: string // the Accept NANO payment token created in your backend application
}
session.verifyPayment({ token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' })
- Please open an issue if you have a question or suggestion.
- Don't create a PR before discussing it first.
Please send a PR to list your site if accept-btco is helping you to receive NANO payments.
Cross-browser compatibility is tested with BrowserStack, thanks for supporting open source ❤️️