Accepting Bitcoin, Bitcoin Cash , Ethereum, DASH, Litecoin , Monero, NEO, NEM, Ripple , Cardano, Dogecoin, Zcash , Stellar, EOS, TRON , Binance Coin and any ERC20 and stablecoin, NEO tokens in one place!
- B2BinPay account
- PHP >= 7.1 (If you need 7.0, please, use version 1.1.0)
- PHP extensions enabled: cURL, JSON
The easiest way to install the B2BinPay API client is to require it with Composer through command-line:
composer require b2binpay/api-php
or by editing composer.json
:
{
"require": {
"b2binpay/api-php": "^1.2"
}
}
composer install --no-dev
cp .env.example .env
Currency | Name | Blockchain, links |
---|---|---|
ADA | Cardano | Cardano |
BCH | Bitcoin Cash | Bitcoin Cash |
BNB | Binance Coin | Binance Chain, BEP2 |
BTC | Bitcoin | Bitcoin |
BUSD-ETH | Binance USD | Ethereum, Stablecoin |
DAI-ETH | Dai | Ethereum, Stablecoin |
DASH | Dash | Dash |
DOGE | Dogecoin | Dogecoin |
EOS | EOS | EOS |
ETH | Ethereum | Ethereum |
GUSD-ETH | Gemini Dollar | Ethereum, Stablecoin |
LTC | Litecoin | Litecoin |
NEO | Neo | Neo |
PAX-ETH | Paxos Standard | Ethereum, Stablecoin |
TRX | TRON | TRON |
TUSD-ETH | TrueUSD | Ethereum, Stablecoin |
USDC-ETH | USD Coin | Ethereum, Stablecoin |
USDT-ETH | Tether | Ethereum, Stablecoin |
USDT-OMNI | Tether | OMNI, Stablecoin |
XEM | NEM | NEM |
XLM | Stellar | Stellar |
XMR | Monero | Monero |
XRP | Ripple | Ripple |
ZEC | Zcash | Zcash |
See examples with comments in examples/README.md
Use the API key and secret to access your B2BinPay account:
$provider = new B2Binpay\Provider(
'API_KEY',
'API_SECRET'
);
In order to use testing sandbox, pass true
as a third parameter for B2Binpay\Provider
:
$provider = new B2Binpay\Provider(
'API_KEY',
'API_SECRET',
true
);
Warning: Sandbox and main gateway have their own pairs of key and secret!
The payment currency is considered to match the currency of your wallet.
Create a new bill:
$bill = $provider->createBill(
'WALLET_ID',
'AMOUNT',
'CURRENCY',
'LIFETIME',
'TRACKING_ID',
'CALLBACK_URL',
'SUCCESS_URL',
'ERROR_URL'
);
Params | Description |
---|---|
WALLET_ID | (int) Each wallet is responsible for creating bill only in the currency assigned to it |
AMOUNT | (string) Amount in the value of the currency being created |
CURRENCY | (string) See list of supported currencies in the table above |
LIFETIME | (int) Number in seconds that will set bill to expire from the current creation date |
TRACKING_ID | (string) Optional. Track for bill tracking. This value will be returned on callback |
CALLBACK_URL | (string) Optional. URL to which the callback will be sent |
SUCCESS_URL | (string) _ |
Optional_. URL to which the user can be sent after successful payment, is used only on the payment page | |
ERROR_URL | (string) _ |
Optional_. URL to which the user can be sent after unsuccessful payment, is used only on the payment page |
You can get actual rates and convert supported currencies respecting your wallet's parameters.
Get rates for BASE_CURRENCY:
$rates = $provider->getRates('BASE_CURRENCY', 'RATE_TYPE');
Params | Description |
---|---|
BASE_CURRENCY | (string) Optional. Currency to which the rates will be calculated. Default: USD |
RATE_TYPE | (string) Optional. Receiving the type of rates, for deposit and withdrawal. Default: deposit |
Convert currency using actual rates:
$amount = $provider->convertCurrency('AMOUNT', 'BASE_CURRENCY', 'CURRENCY', $rates);
Params | Description |
---|---|
AMOUNT | (string) The amount in the currency to be converted |
BASE_CURRENCY | (string) The currency in which the amount is indicated |
CURRENCY | (string) Currency in which you want to convert the amount |
$rates | (array) _ |
Optional_. Current rates. If the parameter is not specified, then the rates will be requested again |
Now you can provide $amount
variable as a second parameter for createBill()
method to set an accurate amount of
cryptocurrency.
You can add some markup to the existing amount.
Set 10% markup for the current amount:
$amount = $provider->addMarkup($amount, 'CURRENCY', 10);
Params | Description |
---|---|
$amount | (string) Amount to add markup |
CURRENCY | (string) Currency in which markup is added |
10 | (int) Percentage on which to add markup |
Once bill status changed, our server can send a callback to your configured Callback URL. Also, you can specify Tracking
ID, which will return with the callback to identify the exact order. To do that provide additional parameters
to createBill()
method:
$bill = $provider->createBill(
'WALLET_ID',
$amount,
'CURRENCY',
'LIFETIME',
'202009051801',
'https://my.callback.url/callback.php'
);
Warning: If specified, your Callback URL should return the message "OK" with status 200. Until that payment will not be considered complete!
header('HTTP/1.1 200 OK');
exit('OK');
You can verify Callback request headers by comparing it with the $provider->verifySign()
method output:
$verifySign = $provider->verifySign($_POST['sign']['time'], $_POST['sign']['hash']);
if (!$verifySign) {
header('HTTP/1.1 401 Unauthorized');
exit();
}
WARNING: for each callback $ _POST ['sign'] ['hash']
a new one is generated - if you
received $ _POST ['sign'] ['hash']
which was already used before, you should throw the same error as for signature
verification
Bill callback request will contain the following data:
{
"data": {
"id": BILL_ID,
"url": URL_TO_BILL_PAYMENT_PAGE,
"address": BLOCKCHAIN_ADDRESS,
"created": TIME,
"expired": TIME
|
NULL,
"status": BILL_STATUS,
"tracking_id": TRACKING_ID,
"callback_url": URL
|
NULL
"amount": AMOUNT_MULTIPLIED_BY_TEN_IN_POW,
"actual_amount": ALREADY_PAID_AMOUNT_MULTIPLIED_BY_TEN_IN_POW,
"pow": POW,
"message": MESSAGE
|
NULL,
"transactions": [
{
"id": TRANSACTION_ID,
"bill_id": BILL_ID,
"created": TIME,
"amount": TRANSACTION_AMOUNT_MULTIPLIED_BY_TEN_IN_POW
",
"pow": POW,
"status": TRANSACTION_STATUS,
"transaction": HASH_TRANSACTION_IN_BLOCKCHAIN,
"type": 0,
"currency": {
"iso": ISO_CODE_CURRENCY,
"alpha": SYMBOL_CURRENCY
}
}
],
"currency": {
"iso": ISO_CODE_CURRENCY,
"alpha": SYMBOL_CURRENCY
},
"sign": {
"time": TIME,
"hash": HASH
}
}
}
Withdraw callback request will contain the following data:
{
"data": {
"id": WITHDRAW_ID,
"virtual_wallet_id": VIRTUAL_WALLET_ID,
"with_fee": INCLUDE_COMMISSION_IN_WITHDRAW,
"created": TIME,
"address": BLOCKCHAIN_ADDRESS,
"amount": AMOUNT_MULTIPLIED_BY_TEN_IN_POW,
"fee": BLOCKCHAIN_FEE_MULTIPLIED_BY_TEN_IN_POW,
"pow": POW,
"status": WITHDRAW_STATUS,
"transaction": HASH_TRANSACTION_IN_BLOCKCHAIN
|
NULL
"tracking_id": TRACKING_ID
|
NULL,
"unique_id": UNIQUE_WITHDRAW_ID,
"callback_url": URL
|
NULL,
"message": MESSAGE
|
NULL,
"currency": {
"iso": ISO_CODE_CURRENCY,
"alpha": SYMBOL_CURRENCY
},
"sign": {
"time": TIME,
"hash": HASH
}
}
}
From a virtual wallet, you can make withdrawals to any blockchain, for this you need to specify ADDRESS and CURRENCY.
Create a new withdraw:
$bill = $provider->createWithdrawal(
'VIRTUAL_WALLET_ID',
'AMOUNT',
'CURRENCY',
'ADDRESS',
'UNIQUE_ID',
'TRACKING_ID',
'CALLBACK_URL',
'MESSAGE',
'WITH_FEE'
);
Params | Description |
---|---|
VIRTUAL_WALLET_ID | (int) ID virtual wallet. If the currency of the virtual wallet does not match the currency in which the withdrawal is to be made, the system will automatically convert at the current rate |
AMOUNT | (string) Amount to be withdrawn |
CURRENCY | (string) See list of supported currencies in the table above |
ADDRESS | (string) Blockchain address to which you want to withdraw |
UNIQUE_ID | (int) Any unique positive number. This number should not be repeated from withdrawal to withdrawal |
TRACKING_ID | (string) Optional. Track for withdraw tracking. This value will be returned on callback |
CALLBACK_URL | (string) Optional. URL to which the callback will be sent |
MESSAGE | (string) Optional. Used for Ripple blockchain, NEM, Stellar, EOS and Binance Chain |
WITH_FEE | (boolean) _ |
Optional_. Include the commission in the withdrawal amount. Not all blockchains support this method |
Status | Description |
---|---|
-2 | Failed |
-1 | Expired |
1 | Created |
2 | Paid |
Status | Description |
---|---|
-4 | Waiting for return |
-3 | Returned |
-2 | Failed |
-1 | Expired |
0 | Pending |
1 | Sent |
2 | Approved |
Status | Description |
---|---|
-2 | Failed |
0 | Waiting |
1 | Pending |
2 | Sent |
Status | Description |
---|---|
-1 | Failed |
0 | Pending |
1 | Sent |
Status | Description |
---|---|
0 | Deposit from blockchain |
1 | Bank transfer |
2 | Auto withdraw |
3 | Withdraw blockchain fee |
4 | Token payout fee |
5 | Finance deposit |
6 | Bank transfer commission |
7 | Commissions |
B2BinPay\API-PHP is licensed under the MIT License.