This SDK allows your application to quickly create an invoice, show the user an option to pay you, and track the status of the payment. Accept bitcoins in your app with 10 lines of code!
Install the SDK as a plugin to your Cordova project.
$ cordova plugin add https://github.com/bitpay/cordova-sdk.git
Please go to https://bitpay.com to create an account. You can also create a development account at https://test.bitpay.com.
Go to My Account > API Tokens section. Click on the Add New Token button and make a token with the Point-of-Sale
capability without client authentication. You can then include this token with your application for distribution.
var Bitpay = cordova.require('com.bitpay.sdk.cordova.Bitpay');
var bitpay = new Bitpay({
host: 'bitpay.com', // or 'test.bitpay.com'
port: 443,
token: '70163c90f...' // as retrieved from above
});
bitpay.createInvoice({
price: 314.15,
currency: 'USD'
}, function(error, invoice){
if (error) throw error;
// subscribe to events
invoice.on('payment', function(e){
// do something on payment
var paid = invoice.data.btcPaid;
})
// open a native wallet with a signed payment request
invoice.openWallet();
// get the invoice url
var url = invoice.data.url;
// generate a qrcode
invoice.getQrCode({format: 'BIP72'}, function(elm){
// do something with the qrcode elm
});
});
bitpay.getInvoice({
id: 'RyNzmZEbGwACpmNg8X6jGN'
}, function(error, invoice){
if (error) throw error;
// do something with the invoice
});
bitpay.isWalletAvailable(function(available) {
// e.g. enable open wallet button.
});
Under the hood, the SDK works thanks to a powerful RPC client that you can also use. To use more of the advanced capabilities, such as the merchant facade, you'll need to pair the client. You can also use the included command line tool to explore more of the API.
var Client = cordova.require('com.bitpay.sdk.cordova.RPCClient')
var client = new Client({
host: 'test.bitpay.com',
port: 443,
token: '70163c90f...' // any type of token
});
client.callMethod(..., function(error, data){
...
});
To read more about the RPC client go to the advanced usage section.
Take a look at this project where an integration with a mock application is shown.
To read more about invoices refer to the included API documentation.
Contact support via our official helpdesk or ask the community.
Code released under the MIT license.