Binance pay api php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Binance API Class and examples of how to use the API.

Mudimedia/binance-api-php

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Binance API Class and examples of how to use the API.

composer require baitercel/binance-api-php dev-master
 require 'BinanceClass.php'; $api = new Binance("API_Key","Secret");

Get latest price of a symbol

$ticker = $api->prices(); print_r($ticker); // List prices of all symbols echo "Price of BNB: $ticker['BNBBTC']> BTC.\n";

Get all of your positions, including estimated BTC value

$balances = $api->balances($ticker); print_r($balances); echo "BTC owned: ".$balances['BTC']['available']."\n"; echo "ETH owned: ".$balances['ETH']['available']."\n"; echo "Estimated Value: ".$api->btc_value." BTC\n";
$bookPrices = $api->bookPrices(); print_r($bookPrices);
$quantity = 1; $price = 0.0005; $order = $api->buy("BNBBTC", $quantity, $price);
$quantity = 1; $price = 0.0006; $order = $api->sell("BNBBTC", $quantity, $price);
$order = $api->buy("BNBBTC", $quantity, 0, "MARKET");
$order = $api->sell("BNBBTC", $quantity, 0, "MARKET");
$trades = $api->trades("BNBBTC"); print_r($trades);
$depth = $api->depth("ETHBTC"); print_r($depth);
$openorders = $api->openOrders("BNBBTC"); print_r($openorders);
$orderid pl-s">7610385"; $orderstatus = $api->orderStatus("ETHBTC", $orderid); print_r($orderstatus);
$response = $api->cancel("ETHBTC", $orderid); print_r($response);

Get all account orders; active, canceled, or filled.

$orders = $api->orders("BNBBTC"); print_r($orders);

Get Kline/candlestick data for a symbol

//Periods: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M $ticks = $api->candlesticks("BNBBTC", "5m"); print_r($ticks);

About

Binance API Class and examples of how to use the API.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Binance Pay API for PHP and Laravel — This is a simple and quick repo on how to initiate crypto payments using the Official Binance API. You can use this to initiate ecommerce payments or any other payments of your choise from your website.

Monyancha/binance-pay-api-php-laravel-curl

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Binance Pay API

Binance Pay API for PHP and Laravel using Curl

Binance Pay API for PHP and Laravel — This is a simple and quick repo on how to initiate crypto payments using the Official Binance API. You can use this to initiate ecommerce payments or any other payments of your choise from your website.

Binance Pay API: Authentication

The Binance Pay API uses API keys to authenticate requests. You can view and manage your API keys in the Binance Merchant Admin Portal.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

Apply API identity key and API secret key#

Register Merchant Account at Binance Login merchant account and create new API identity key/API secret key Binance Merchant Admin Portal.

Create order API Version 2 used for merchant/partner to initiate acquiring order.

POST /binancepay/openapi/v2/order 

Check here for all the request parameters -> Check here

 $ch = curl_init(); $timestamp = round(microtime(true) * 1000); // Request body $request = array( "env" => array( "terminalType" => "APP" ), "merchantTradeNo" => mt_rand(982538,9825382937292), "orderAmount" => 25.17, "currency" => "BUSD", "goods" => array( "goodsType" => "01", "goodsCategory" => "D000", "referenceGoodsId" => "7876763A3B", "goodsName" => "Ice Cream", "goodsDetail" => "Greentea ice cream cone" ) ); $json_request = json_encode($request); $payload = $timestamp."\n".$nonce."\n".$json_request."\n"; $binance_pay_key = "REPLACE-WITH-YOUR-BINANCE-MERCHANT-API-KEY"; $binance_pay_secret = "REPLACE-WITH-YOUR-BINANCE-MERCHANT-SCRETE-KEY"; $signature = strtoupper(hash_hmac('SHA512',$payload,$binance_pay_secret)); $headers = array(); $headers[] = "Content-Type: application/json"; $headers[] = "BinancePay-Timestamp: $timestamp"; $headers[] = "BinancePay-Nonce: $nonce"; $headers[] = "BinancePay-Certificate-SN: $binance_pay_key"; $headers[] = "BinancePay-Signature: $signature"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, "https://bpay.binanceapi.com/binancepay/openapi/v2/order"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_request); $result = curl_exec($ch); if (curl_errno($ch)) < echo 'Error:' . curl_error($ch); >curl_close ($ch); var_dump($result); //Redirect user to the payment page ?> 

Use this in your targeted controller file.

public function initiateBinancePay() < // Generate nonce string $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $nonce = ''; for($i=1; $i $ch = curl_init(); $timestamp = round(microtime(true) * 1000); // Request body $request = array( "env" => array( "terminalType" => "APP" ), "merchantTradeNo" => mt_rand(982538,9825382937292), "orderAmount" => 25.17, "currency" => "BUSD", "goods" => array( "goodsType" => "01", "goodsCategory" => "D000", "referenceGoodsId" => "7876763A3B", "goodsName" => "Ice Cream", "goodsDetail" => "Greentea ice cream cone" ) ); $json_request = json_encode($request); $payload = $timestamp."\n".$nonce."\n".$json_request."\n"; $binance_pay_key = "REPLACE-WITH-YOUR-BINANCE-MERCHANT-API-KEY"; $binance_pay_secret = "REPLACE-WITH-YOUR-BINANCE-MERCHANT-SCRETE-KEY"; $signature = strtoupper(hash_hmac('SHA512',$payload,$binance_pay_secret)); $headers = array(); $headers[] = "Content-Type: application/json"; $headers[] = "BinancePay-Timestamp: $timestamp"; $headers[] = "BinancePay-Nonce: $nonce"; $headers[] = "BinancePay-Certificate-SN: $binance_pay_key"; $headers[] = "BinancePay-Signature: $signature"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, "https://bpay.binanceapi.com/binancepay/openapi/v2/order"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_request); $result = curl_exec($ch); if (curl_errno($ch)) < echo 'Error:' . curl_error($ch); >curl_close ($ch); var_dump($result); //Redirect user to the payment page > 

Sample SUCCESS JSON Response

Binance Pay: Order Webhook Notification

###Callback Webhook Endpoints Binance Pay will send order events with final status to partner for notification. You will be able to configure webhook endpoints via the Binance Merchant Admin Portal Result of the orders that are close will be notified to you through this webhook with bizStatus = «PAY_CLOSED»

I’ll update a webhook callback usage for this soon! You’ll be able to receive the JSON responses and validate payments even storing them to your database

Binance Order Webhook Notification API and Payment Confirmation 🥳 🥳 🥳 🥳 🥳

You can now be able to confirm your client payments easily with this api. All you need to do is to set a callback url where Binance will send you a notification regarding the status of the customer payment!. Binance Pay will send order events with final status to partner for notification. You will be able to configure webhook endpoints via the Binance Merchant Admin Portal. Result of the orders that are close will be notified to you through this webhook with bizStatus = «PAY_CLOSED».

Create a file in your server to act as a callback receiver to log the binance responses. Example is below:

Create binancePayWebhookCallbackApi.php in your domain root directory

Then paste the code below

Create a Json Log file — binancePayWebhookCallbackFile.json — where the responses will be stored.

This means that once a customer pays, Binance will trigger a notification to your callback webhook url with the status of the payment. This data will be stored in your Logfile that you created.

To achive this you first need to login to your Binance Merchant account and your webhook url : https://yourdomain.com/binancePayWebhookCallbackApi.php

Follow this link to login to Binance Merchant Account and add your Webhook Url: https://merchant.binance.com/en/dashboard/developers/webhooks

If you need to store customer data and payment status then you need to create your business logic in the webhook file or create a new file for your logics.

You can get the success object from the webhook response then proceed to validate the customer data and store to your database.

If you don’t need to store the responses then just use the respose directly from binance webhook: I have given a good example below implementing the same in Laravel with only 1 Line;

 public function callbackStk (Request $request)< header("Content-Type: application/json"); //This line gets all your json response from binance when a customer makes payment $webhookResponse = $request->all(); //Now get success object directly from the response eg. //Warning: This is just example and you should not use it for your implementation. Get the exact responses from your webhook callback file! $returnCode = $webhookResponse['returnCode']; $returnMessage = $webhookResponse['returnMessage']; //Then start implementing your logic eg. if($returnCode == "SUCCESS") < //Do some logic here >> 

If you need any help regarding webhook confirmation and validation of customer payment and business logic get in touch with me with the contacts on the footer below.

  • #C2B — Create Order/Initiate binance payment 🎉
  • #Receiving webhook responses through callback url for validating and storing response to database
  • #C2C — Customer to Customer crypto funds transfer using binance API
  • #B2C — Business to Customer crypto funds transfer using binance API (Bulk/Batch Payments)
  • #Refunds — Making refunds using the Binance API
  • #Create Sub-merchant API used for merchant/partner.
  • #Wallet Balance Query API used to query wallet balance.
  • #Integrate Binance Pay with your App SDK: Android & IOS

Binance Pay Official Documentation

  • Pull requests are welcome.
  • Give us a star ⭐
  • Fork and Clone! Awesome
  • Select existing issues or create a new issue and give us a PR with your bugfix or improvement after. We love it ❤️

About

Binance Pay API for PHP and Laravel — This is a simple and quick repo on how to initiate crypto payments using the Official Binance API. You can use this to initiate ecommerce payments or any other payments of your choise from your website.

Источник

Читайте также:  Table join in php
Оцените статью