- 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 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.
- 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.
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(){ ... });
});
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);
});
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);
});