How integrate NANO cryptocurrency payment gateway via Brainblocks to your website?

nano logo

 

Hitsteps accepted Nano cryptocurrency (formerly known as Raiblocks) as a way of payment for it’s services since early January 2018, we are excited about cryptocurrency as whole and specially about Nano cryptocurrency. We were using RaiPay.io as our payment processor gateway however they’ve gone offline and shutdown their service.

So we moved to BrainBlocks. At time of writing this article, brainblocks.io homepage provide a simple and efficient guide on how to create an “inline” nano payment button. however there is no guide on how to create a “hosted” payment gateway page while they DO offer this service as it can be seen in their woocommerce plugin. We are happy with their transaction processing time and their service, so we decided to provide this simple guide to encourage more merchants to accept Nano.

Brainblocks team provided a simple way for Shopify shop owners to accept nano as well as a WordPress plugin for those who use WooCommerce.

In this article, we will focus on how to create a “hosted” nano cryptocurrency payment gateway. We will use PHP for this example, but you can use it with all other languages.

You need to build your URL path to redirect user to brainblocks payment gateway page.

Section A: Opening BrainBlocks Hosted payment gateway page

Your nano wallet address as:
$destination = "xrb_.............";

USD or other currency amount to be paid by user:
$total = "99.99";

Currency that you are using for total amount above:
$currency = "usd";

At time of writing, brainblocks accept aud, brl, cad, chf, clp, cny, czk, dkk, eur, gbp, hkd, huf, idr, ils, inr, jpy, krw, mxn, myr, nok, nzd, php, pkr, pln, rub, sek, sgd, thb, try, usd, twd, zar currencies for price conversion.

Return URL after a successful payment: (order_id parameter is optional, it help you to pin point to exact order generated from your service)
$returnurl = "http://website.url/thankyoupage.php?order_id=xxx";

Return URL after a failed payment: (order_id parameter is optional)
$errorurl = "http://website.url/payagain.php?order_id=xxx";

and then build your brainblock url using variables defined above:
$brainblocks_url = 'https://brainblocks.io/checkout?payment.destination='
 . $destination . '&payment.currency=' . strtolower($currency) .
'&payment.amount=' . $total . '&urls.return=' . urlencode($returnurl) .
'&urls.cancel=' . urlencode($errorurl);

and then you redirect your visitor to this generated URL:
header(“Location: “.$brainblocks_url);

Section B: Verifying payment after it’s paid by customer

In example above, we used success return URL to be thankyou.php, so this instruction is regarding thankyou.php file.

BrainBlocks redirect user to your thankyou page with parameters you’ve provided and add an extra parameter named “token”. This token parameter will be returned as GET (on URL) however there is possibility that it get returned as POST as well. so you need to check for POST if GET token is empty.

In thankyou page, we validate Payment using Token code that is provided by brainblocks as json:
$brainblocks_data=(array) json_decode(
file_get_contents("https://brainblocks.io/api/session/".
$_GET['token']."/verify"),true);

now, we check to make sure full amount is paid by customer:
if ($brainblocks_data['fulfilled']){
//payment is successful and you can go on with processing the order
}else{
//payment has been failed or not full amount has been paid
}

This section B instruction can be used together with brainblocks’s inline payment button guide as well.