Empower Your App with BitPay's Mobile SDK

A few months ago we announced the release of the new BitPay API , with many new capabilities and improved security using the same cryptographic authentication as Bitcoin through BitAuth. Today we're extending the API with an initial release of our mobile SDKs, including a plugin for Cordova (Android and iOS platforms), plus a native Android toolkit.

As a part of BitPay's core mission to make it easy to accept bitcoin, we're introducing a way to distribute a mobile application that can accept bitcoin payments into your local currency with zero server-side work. At the press of a button your application can open a mobile bitcoin wallet with a signed payment request. If you're integrating bitcoin into an application that accepts payments in-person, you can present a standard QR code that can be scanned by another device.

Cordova Example

Screenshots from the Cordova Sample Application and a Bitcoin Wallet

Example code with how to quickly accept a bitcoin payment in Cordova:

var BitPay = cordova.require('com.bitpay.sdk.cordova.Bitpay');

var bitpay = new BitPay({  
  host: 'bitpay.com', // or 'test.bitpay.com'
  port: 443,
  token: '70163c90f...' // point-of-sale token without client authentication
});

bitpay.createInvoice({  
    price: 314.15,
    currency: 'USD'
}, function(error, invoice){

  // open a native wallet with a signed payment request
  invoice.openWallet();

  // subscribe to events
  invoice.on('payment', function(e){
    // do something on payment
    var paid = invoice.data.btcPaid;
  })

});


Android Example

Regarding the Android SDK: it contains a couple of useful classes around the BitPay Java client. Models are parcelables, there are some AsyncTask wrappers for the network calls, and an Activity to show the status of an Invoice. You can check the project out here: GitHub project.

A simple payment can be requested in an event handler as follows:

final String TOKEN = "2dQQcdssUY...";  
// This can take a while, you should show a Dialog here while this gets created...
new BitPayAndroid(new Token(TOKEN)).createNewInvoice(  
    new Invoice(total, "USD")).then(new InvoicePromiseCallback() {
        public void onSuccess(Invoice invoice) {
            Intent invoiceIntent = new Intent();
            invoiceIntent.putExtra(InvoiceActivity.INVOICE, invoice);
            startActivity(invoiceIntent);
        }

        public void onError(BitPayException e) {
            // Your error handling code here...
        }
    }
);

The InvoiceActivity will finish when the payment is received in our servers. Check the return code for the activity to display your own message to the user.

Creating and managing invoices has never been easier. We take care of all the networking, confirming payments, and even provide you with a drop-in user interface. Need more? Beneath the hood, a powerful client gives you access to the full BitPay API.

To get started, download the Cordova SDK Plugin and Android SDK from our Git repositories, check out the documentation, and for inspiration, take a look at the Cordova sample application and native Android sample application. We're very excited to see all of the many ways to accept bitcoin. As always, please don't hesitate to open an issue or send a pull request.

-- Mobile SDK Team


Mobile phone sketch templates by interfacesketch.com and available under a Creative Commons Attribution 4.0 International License

Get the latest updates to your inbox