Skip to content

Accept Ethereum, Bitcoin, Bitcoin Cash, Bitcoin Gold, Litecoin, Dash and Ethereum Classic on your website

Notifications You must be signed in to change notification settings

rexleonem/paybear-samples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PayBear.io API

This API allows to accept Ethereum, Bitcoin, Bitcoin Cash, Bitcoin Gold, Litecoin, Dash and Ethereum Classic payments. More details can be found on our website: https://www.paybear.io

Important note for APIv1 users

API Keys

In order to use the system you need an API key. Getting a key is free and easy, sign up here: https://www.paybear.io

Multiple Currencies

Once registered, you can manage the currencies you want to integrate in the Membership area / Currencies. Please enable the currencies there before using this API.

Get Currencies

Get a list of enabled currencies with this GET request:

GET https://api.paybear.io/v2/currencies?token={token}

Parameters:

token API Secret Key

Create payment request

Use GET query to create payment request:

GET https://api.paybear.io/v2/{crypto}/payment/{callback_url}?token={token}

Parameters:

crypto Crypto currency to accept (eth, btc, bch, ltc, dash, btg, etc)
token API Secret Key

Optional parameters:

callback_url Your server callback url (urlencoded)

Example request URL:

https://api.paybear.io/v2/eth/payment/http%3A%2F%2Fputsreq.com%2FUv8u7ofxXDWVoaVawDWd/?token=YOURSECRET

Response:

The API always responds with a JSON string. [data] collection contains the important values: [address] is the payment address to show to the customer [invoice] is our inner payment identifier, keep it in a safe place and never disclose to your clients.

Response example:

{
    "success": true,
    "data": {
        "invoice": "d1ddf6e3767030b08032cf2eae403600",
        "address": "0x2073eb3be1a41908e0353427da7f16412a01ae71"
    }
}

PHP example:

More examples: Node.js, Ruby on Rails
$orderId = 12345;
$apiSecret = 'YOURSECRET'; //your api key
$callbackUrl = 'http://CHANGEME.com/callback.php?id='.$orderId;

$url = sprintf('https://api.paybear.io/v2/eth/payment/%s?token=%s', urlencode($callbackUrl), $apiSecret);
if ($response = file_get_contents($url)) {
    $response = json_decode($response);
    if (isset($response->data->address)) {
        echo $response->data->address;
        //save $response->data->invoice and keep it secret
    }
}

Callback

A callback is sent every time a new block is mined. To stop further callbacks, reply with the invoice ID. See code sample below.

Callback example:

{
    "invoice": "7e691214bebe31eaa4b813c59825391b",
    "confirmations": 2,
    "maxConfirmations": 4,
    "blockchain": "eth",
    "block": {
        "number": 4316966,  
        "hash": "0xf80718e3021cc6c226a01ea69b98131cd9b03fa5a0cac1f2469cc32d0f09e110"
    },
    "inTransaction": {
        "hash": "0x7e29e165d15ec1c6fc0b71eed944471308c10d0450fe7e768843241f944bdfde",
        "exp": 18,
        "amount": 21000000000000
    }
}

PHP example:

More examples: Node.js, Ruby on Rails
const CONFIRMATIONS = 3;

$orderId = $_GET['id'];
$data = file_get_contents('php://input');
if ($data) {
    $params = json_decode($data);
    $invoice = $params->invoice;
    $amount = $params->inTransaction->amount
    if ($params->confirmations>=$params->maxConfirmations) {
        //compare $amount with order total
        //compare $invoice with one saved in the database to ensure callback is legitimate
        //mark the order as paid
        echo $invoice; //stop further callbacks
    } else {
        die("waiting for confirmations");
    }
}

Get Market Rate

Use GET query to obtain the current average market rates:

GET https://api.paybear.io/v2/exchange/{fiat}/rate

Parameters:

fiat Fiat currency (usd, eur, cad, rub etc)

Response:

The API returns a JSON string containing the rates from several online exchanges, as well as the average rate. It is recommended to cache the rates for 10-15 minutes.

Response example:

{
    "success": true,
    "data": {
        "ltc": {
            "poloniex": 340.986909455,
            "hitbtc": 340.568,
            "bittrex": 340.25,
            "bitfinex": 341.295,
            "mid": 340.77497736375
        },
        "eth": {
            "poloniex": 804.580989955,
            "hitbtc": 805.88,
            "bittrex": 803.47641155,
            "bitfinex": 805.125,
            "mid": 804.76560037625
        },
        "dash": {
            "poloniex": 1129.8512215,
            "hitbtc": 1130.145,
            "bittrex": 1134.1035001,
            "mid": 1131.3665738666666
        },
        "btg": {
            "hitbtc": 320.485,
            "bittrex": 317.90500002,
            "bitfinex": 320.46500003,
            "mid": 319.61833334
        },
        "btc": {
            "poloniex": 17348.94643245,
            "hitbtc": 17322.91,
            "bittrex": 17347.05,
            "bitfinex": 17355.5,
            "mid": 17343.6016081125
        },
        "bch": {
            "poloniex": 2595.49999996,
            "hitbtc": 2600.6334100004,
            "bitfinex": 2591.55,
            "mid": 2595.8944699866665
        }
    }
}

Exchange rates for one currency*:

*If you are using more than one currency, we recommend usng the call above to get all rates with one request.
GET https://api.paybear.io/v2/{crypto}/exchange/{fiat}/rate

Parameters:

crypto Crypto currency (eth, btc, bch, ltc, dash, btg)
fiat Fiat currency (usd, eur, cad, rub etc)

Response:

The API returns a JSON string containing the rates from several online exchanges, as well as the average rate. It is recommended to cache the rates for 10-15 minutes.

Response example:

{
    "success": true,
    "data": {
        "poloniex": 301.71905,
        "bittrex": 302.05,
        "bitfinex": 301.53499,
        "mid": 301.76807
    }
}

PHP example:

More examples: Node.js, Ruby on Rails
$url = "https://api.paybear.io/v2/eth/exchange/usd/rate";

if ($response = file_get_contents($url)) {
    $response = json_decode($response);
    if ($response->success) {
        echo $response->data->mid;
    }
}

Request Limit

The system is designed to process thousands of transactions per second, so we do not limit the number of payments you can process. However, for DDoS protection reasons, the API calls are limited to 1000 per minute from one IP.

What to use as a payout address?

You will need payout addresses for all crypto currencies you want to accept. Only you will have access to your payout wallets. You can use any online wallet, service or exchange of your choice. If you don't have one, consider reading our Wallet Guide

About

Accept Ethereum, Bitcoin, Bitcoin Cash, Bitcoin Gold, Litecoin, Dash and Ethereum Classic on your website

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 54.3%
  • HTML 39.0%
  • PHP 3.6%
  • Ruby 3.1%