Skip to content

Instantly share code, notes, and snippets.

@yemel
Last active August 29, 2015 14:06
Show Gist options
  • Save yemel/bf96d98b323cbf222f40 to your computer and use it in GitHub Desktop.
Save yemel/bf96d98b323cbf222f40 to your computer and use it in GitHub Desktop.
SDK Feedback

Invoice:

  • I don't like setting the token and server info every time I create an invoice.
  • The server host and port are hardcoded to use 'test' or 'live', however on the RPCClient you have to set them explicitly. That is inconsistent and confusing for the user developer.
  • I have mixed feelings about the create method.
  • +1 on payment events.

RPC Client:

  • RPC call capabilities are useless without proper documentation, we should point to a clean documentation of the available methods.
  • Even with RPC documentation we should offer native methods that wraps the call for the most common calls. RPC it's an implementation detail, calling a method by an string argument it's a hack, not a best practice.

Enhancement proposal:

  • I would like to centralize the interface in one class called BitPay, it would be much easier to understand for the user developer. Remember that the developers may not be familiar with BitPay's architecture and API flow.
  • The class will be created with server info (server:port or 'live'/'test') and token (not required for making public calls).
  • This class will handle the life cycle of Invoices and offer wrappers to the most common RPC calls.

Authenticated Calls:

var BitPay = cordova.require('com.bitpay.sdk.cordova.BitPay');
var bitpay = new BitPay({
  server: 'test', // default: 'live'
  token: '71273..'
});

// Create an invoice
bitpay.createInvoice({
  price: 12.3,
  currency: "USD"
}, function onCreate(err, invoice) {
  if (err) throw err;
  
  console.log('Invoice created:', invoice);
  invoice.on('payment', function(){ ... });
});

Public Calls:

var BitPay = cordova.require('com.bitpay.sdk.cordova.BitPay');
var bitpay = new BitPay({
  server: 'test' // default: live
});
    
// Get current invoice state
bitpay.getInvoice(<invoiceId>, function onResult(err, invoice) {
  if (err) throw err;
  
  console.log('Invoice info:', invoice);
  invoice.on('payment', function(){ ... });
});

// Get the current exchange rates (updated every minute)
bitpay.getRates(function onResult(err, rates) {
  if (err) throw err;
    
  console.log('Rates: ', rates);
});

RPC Calls:

For advanced usage, the SDK offers an RPC interface to interact with BitPay's API. Check the documentation for more details about RPC capabilities.

var BitPay = cordova.require('com.bitpay.sdk.cordova.BitPay');
var bitpay = new BitPay({
  server: 'test' // default: live
  token: '71273..'
});

bitpay.call(<methodName>, <arguments>, function onResult(err, res) {
    if (err) throw err;
    console.log('Response:', res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment