When we designed Kill Bill, we always thought of it as a billing platform, rather than simply a subscription billing system. We wanted to make it flexible enough to support much more than simple monthly credit cards payments. We see Kill Bill as your company’s financial toolbox.
The ultimate test to validate our architecture was to experiment with a Bitcoin integration. Digital currencies offer a completely different environment compared to traditional payment gateways: the vast majority of concepts don’t apply anymore (e.g. chargebacks) and due to the push nature of transactions, recurring payments are still an open problem.
As a proof of concept Kill Bill, we prototyped an integration with Coinbase, allowing customers to pay their subscriptions automatically using their Coinbase wallet (the merchant account being in Coinbase or not). Note that we are simply using Coinbase as a payment gateway, we do not use Coinbase’s recurring payments offering (invoices and payments are driven by Kill Bill).
The integration mainly consisted in writing a payment plugin. Similar to, for example, the Stripe or the PayPal plugins, the Coinbase one registers itself at startup. Accounts can then have Coinbase payment methods. When an invoice is generated, an event is posted on the event bus. The payment subsystem will react to it, fetch the default payment method associated with the account, and, if it is of type killbill-coinbase, Kill Bill will delegate the actual payment call to it.
A nice feature of the Coinbase API is that it handles currency conversions automatically. Regardless of the default currency on the account (USD, EUR, BTC, …), Kill Bill can simply pass the original amount to Coinbase which will handle the transaction in bitcoins transparently. An account in USD which has been historically using a credit card can simply have its default payment method switched to a Coinbase one to start paying in bitcoins (invoices will still be in dollars). Note that other Kill Bill payment plugins, such as the Stripe and the PayPal ones, also support currency conversions through the currency plugin which we will update to support Bitcoin. This means that an account in BTC can have a backup credit card on file, and, if the Coinbase transaction doesn’t go through, the payment could be attempted on the credit card, charged for instance in USD after conversion.
Regarding the merchant account, if it is in Coinbase as well, the flow is actually very similar to a credit card purchase: transactions between Coinbase accounts are handled outside of the main blockchain and confirmed directly. However, if the merchant wallet is not in Coinbase, the confirmation is then asynchronous. In this case, the payment is marked as PENDING in Kill Bill and will be confirmed later.
There are two ways to make the payment transition from PENDING to PROCESSED. If you want to trust Coinbase and don’t need to configure the level of confirmation, you can configure the plugin to poll Coinbase for the status of the transaction. When it transitions to complete, the plugin will call back Kill Bill to mark the payment as processed. For more complex scenarii (e.g. if you need to configure the confirmation depth), you can instead use our Simplified Payment Verification (SPV) Bitcoin plugin, which we will describe
in another article here.
A couple of notes regarding the actual implementation. First, we decided to write it in Ruby to leverage the official Coinbase Ruby library. It has been working great for us, we only wished we could have access to a Testnet3 sandbox for testing.
Also, for our prototype, users need to provide their Coinbase API key. Future versions will leverage OAuth2 instead. [API key access as well as OAuth2 are now supported]. Finally, in order to process refunds, the merchant wallet needs to be in Coinbase (if it isn’t, instead of refunding a transaction, you can still credit back the Kill Bill account).
While our Coinbase experiment offers one solution to the recurring payments problem, we continue to investigate how a Kill Bill integration with other wallets may look like. For example, we recently experimented with Hive and prototyped an app for it. We are also considering experimenting with the newly released Coinbase Android SDK. Stay tuned!