Skip to content

Instantly share code, notes, and snippets.

@unusualbob
Forked from yemel/SKD.md
Last active August 29, 2015 14:06
Show Gist options
  • Save unusualbob/b0c5f4a837d0d6fd9035 to your computer and use it in GitHub Desktop.
Save unusualbob/b0c5f4a837d0d6fd9035 to your computer and use it in GitHub Desktop.

Cordova SDK

Please go to http://test.bitpay.com to create an account. After registration, depending on the kind of application you are building you may need to go through a pairing process.

Install the SDK plugin

$ cordova plugin add https://github.com/bitpay/cordova-skd.git

Generate Application Key

Use case: Generating and tracking invoices.

Go to My Account > API Tokens section. Under Tokens create a new token with label mobile and facade Point-of-Sale.

Open the sdk folder and excecute the pairing utility using the created token.

$ cd plugins/com.bitpay.skd/bin
$ ./createClientKey <token>
Your client key is:
70163c90f18df866d7a4ec3b8f7215f0013e3f81749f6222938a1f4d9ce3e97e

Now copy that client key and distribute it with the consumer app. It will be used to instantiate the bitpay client as follows:

var CLIENT_KEY = '70163c90f...';
var bitpay = new Bitpay({
    key: CLIENT_KEY,
    server: 'http://test.bitpay.com',
    port: 443
});

Using the SDK

Now your app is ready to generate invoices and track their state:

// Create Invoice
bitpay.createInvoice({
    price: 123.5,
    currency: "USD"
}, logInvoice);

// Track their state    
bitpay.getInvoice('the-invoice-id', logInvoice);

function logInvoice(error, invoice) {
    if (error) throw error;
    console.log(invoice);
    // Invoice {
    //   id: 'the-invoice-id'
    //   url: 'http://test.bitpay.com/payment/the-invoice-id'
    //   status: 'new'
    //   btcPrice: 0.123
    // }
}

To read more about invoices refer to the BitPay's API documentation

Sample Application

You can check a sample music store app using the SDK here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment