Simple Steps To Integrate Cubits Payment Gateway in NodeJS

Posted By : Abhishek Saini | 10-Apr-2017

 

Cubits invoices are the convenient way to accepts bitcoins . Before integrating cubits you must sure that the merchant account should be verify.

This is how you can simply implement cubits payement gateway by creating invoice in your node js application.

First you need to generate cubits_key and cubits_secret from your merchant account.To use the cubits api you need three things:cubits_Key,cubits_Nonce and cubits_signature .

 

Cubits_key : This is your merchant account cubits_key.
Cubits_Nonce:This is a unique number you must generate for each request.You can use timestamp for this.
Cubits_signature :The signature is derived from the cubits_key ,cubits_nonce and the requested body.

 

Now simply create hash for cubits_signature like :


var key = "XYZ"   //your merchant key
    var secret = "ABC"  // your merchant secret;
    var nonce = new Date().getTime();
    var uriPath = "/api/v1/invoices";

    var price = "12.00";

    var bodyJson = JSON.stringify({
        currency: EUR,
        price: price,
        description: "Testing",
        callback_url: "http://callback url",
        success_url: "http://sucessurl",
        cancel_url: "http://cancelUrl"
    });


    var hash = crypto.createHash('sha256').update(bodyJson, 'utf8').digest('hex');  //use crypto

    var msg = uriPath + nonce + hash;

    var signature = crypto.createHmac('sha512', secret).update(msg).digest('hex');

 

Now simply request cubits create invoice api like :


 var options = {
        url: 'https://api.cubits.com/api/v1/invoices',
        method: "POST",
        headers: {
            'X-Cubits-Key': key,
            'X-Cubits-Nonce': nonce,
            'X-Cubits-Signature': signature,
            'Content-type': 'application/vnd.api+json',
            'Accept': 'application/vnd.api+json'
        },
        body: bodyJson
    };

    request(options, function(error, response, body) {
        console.log("invoice created", response.body);
  }) 

 

The above request will return invoice url and more details related to that invoice.You can simply hit this invoice url in browser and accept bitcoins.You have to create different invoice for each payment request.

 

Hope this will help.

Thanks

 

About Author

Author Image
Abhishek Saini

Abhishek is bright Lead developer with skills in AngularJS and Java. He loves to learn new technologies.

Request for Proposal

Name is required

Comment is required

Sending message..