inbitcoin SDK for JavaScript

The inbitcoin SDK for JavaScript provides a set of client-side functionality that enables you to accept bitcoin as a payment method.

The SDK work on both desktop and mobile web browsers.

This quickstart will show you how to setup the SDK.

Basic Setup

Include the integration code in your HTML on each page you want to load the SDK, directly after the opening <body> tag.

<script>
(function(c, o, i, n) {
    var js, fjs = c.getElementsByTagName(o)[0];
    if (c.getElementById(i)) return;js = c.createElement(o); js.id = i;
    js.src = "https://inbitcoin.it/static/sdk/v.2/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
    js.onload=function () {INBIT.init(this, n);}
  }(document, 'script', 'inbitcoin-jssdk', {clientid:'your-client-id'}));
</script>

The code will asynchronously load the SDK. The async load means that it does not block loading other elements of your page.

Making a standard HTML payment button

Inbitcoin SDK detect and handle automatically tags with className = "inbit-btnpay".

<a href="#" data-price="10" data-currency="EUR"
    class="inbit-btnpay"
    title="Pay in bitcoin">
    <img src="https://inbitcoin.it/static/img/btnpay.png"
        width="96" height="48" />
</a>
Try it now:

Order-id and onpaid-url

You can add a data-order-id parameter to track order.

After payment send user to a “thank you” page with data-onpaid-url.

<a href="#" class="inbit-btnpay"
    data-price="10" data-currency="EUR"
    data-order-id="1"
    data-onpaid-url="/thankyou.html">Pay in bitcoin</a>

Making a Javascript payment button

<a href="#" id="button_pay">Pay in bitcoin</a>

<script>
window.inbitAsyncInit = function() {
    document.getElementById("button_pay").onclick(function (e) {
        e.preventDefault();
        INBIT.showInvoice({price:5,currency:"EUR",order_id:"2"})
    })
};
</script>

Handling events

<a href="#" id="button_pay" title="Pay in bitcoin">
    <img src="/static/img/btnpay.png" width="96" height="48" />
</a>
<div id="invoice_info"></div>
<div id="invoice_result"></div>
<script>
window.inbitAsyncInit = function() {
    var info=document.getElementById("invoice_info")
    var result=document.getElementById("invoice_result")
    document.getElementById("button_pay").onclick=function (e) {
        e.preventDefault();
        var _this=this
        INBIT.showInvoice({
            price:5,currency:"EUR",order_id:"3",
            onshow:function (invoice) {
                info.innerHTML=
                     'Invoice id: '+invoice.id+'<br/>'
                    +'BTC price: '+invoice.btcPrice+'<br/>'
                    +'Rate: '+invoice.rate+'<br/>'
            },
            onpaid:function (invoice) {
                result.innerHTML="Paid"
                _this.innerHTML="Thank You!"
            },
            oncancel:function (err) {
                result.innerHTML="Canceled: "+err
            }
        })
    }
};
</script>
Try it now: