Code Monkey home page Code Monkey logo

cordova-sdk's Introduction

BitPay Cordova SDK

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!

Installing

Install the SDK as a plugin to your Cordova project.

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

Setup Credentials

1. Create a BitPay Account

Please go to https://bitpay.com to create an account. You can also create a development account at https://test.bitpay.com.

2. Generate an Application Token

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.

Sample Code and Usage

Creating a BitPay Client

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
    });

Creating a New Invoice

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
  });
});

Get an Invoice

bitpay.getInvoice({
    id: 'RyNzmZEbGwACpmNg8X6jGN'
}, function(error, invoice){
  if (error) throw error;

  // do something with the invoice

});

Check if a Bitcoin Wallet is Available

bitpay.isWalletAvailable(function(available) {
    // e.g. enable open wallet button.
});

Advance Usage

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.

More Samples and Documentation

Sample Project

Take a look at this project where an integration with a mock application is shown.

BitPay's API docs

To read more about invoices refer to the included API documentation.

Troubleshooting

Contact support via our official helpdesk or ask the community.

License

Code released under the MIT license.

cordova-sdk's People

Contributors

braydonf avatar jameswalpole avatar yemel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-sdk's Issues

Unable to install

When i try to run the command cordova plugin add https://github.com/bitpay/cordova-sdk.git as the readme states, i get an error

Can't install SDK on Ionic3

Hello,
Trying to install cordova pluing in ionic3 project, but unable to install CanOpen plugin

Anyone can recommend how to install it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.