PHP code example of ptuchik / omnipay-binancepay

1. Go to this page and download the library: Download ptuchik/omnipay-binancepay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ptuchik / omnipay-binancepay example snippets


    use Omnipay\Omnipay;


    $gateway = Omnipay::create('BinancePay');
    $gateway->setApiKey(env('API_KEY'));
    $gateway->setSecret(env('SECRET'));



    $purchase = $gateway->purchase();
    $purchase->setCryptoCurrency('USDT'); // Currenctly supports only USDT
    $purchase->setNonce(\Str::random(32));
    $purchase->setAmount(10); // Amount to charge
    $purchase->setDescription(XXXX); // Some description about the items you sell
    $purchase->setReturnUrl(XXXX); // Set the URL where the customer will be directed after successful payment
    $purchase->setCancelUrl(XXXX); // Set the URL where the customer will be directed on failed or cancelled payment
    
    $purchase->send()->redirect();



    $gateway = Omnipay::create('BinancePay');
    $gateway->setApiKey(env('API_KEY'));
    $gateway->setSecret(env('SECRET'));
    
    $request = $gateway->completePurchase()
    $request->setNonce(\Str::random(32));
    $request->setTransactionId(XXXX); // Transaction ID from your system
    
    $purchase = $request->send();
    
    // Do the rest with $purchase and response with 'OK'
    if ($purchase->isSuccessful()) {
        
        // Your logic
        
    }
    
    return \Response::json([
            'returnCode'    => 'SUCCESS',
            'returnMessage' => null
        ]);