PHP code example of prevailexcel / laravel-coinremitter

1. Go to this page and download the library: Download prevailexcel/laravel-coinremitter 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/ */

    

prevailexcel / laravel-coinremitter example snippets


'providers' => [
    ...
    PrevailExcel\Coinremitter\CoinremitterServiceProvider::class,
    ...
]

'aliases' => [
    ...
    'Coinremitter' => PrevailExcel\Coinremitter\Facades\Coinremitter::class,
    ...
]



return [

    'coins' => [

        'BTC' => [
            'api_key' => 'API_KEY_FROM_WEBSITE',
            'password' => 'PASSWORD',
        ],

        'LTC' => [
            'api_key' => 'API_KEY_FROM_WEBSITE',
            'password' => 'PASSWORD',
        ],
    ],
];

use PrevailExcel\Coinremitter\Coinremitter;

$coinremitter = new Coinremitter('COIN');
$coinremitter->balance();

// Laravel 5.1.17 and above
Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay');

Route::post('/pay', [
    'uses' => 'PaymentController@redirectToGateway',
    'as' => 'pay'
]);

// Laravel 8 & 9
Route::post('/pay', [App\Http\Controllers\PaymentController::class, 'redirectToGateway'])->name('pay');



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use PrevailExcel\Coinremitter\Facades\Coinremitter;

class PaymentController extends Controller
{
    
    public function __construct()
    {
        if(!request()->coin)
            request()->coin = 'BTC'; //set a default coin
    }

    /**
     * Collect Order data and Redirect user to Payment gateway
     */
    public function redirectToGateway()
    {
        try{
            //You should collect the details you need from a form

           return Coinremitter::redirectToGateway();

           // or alternatively use the helper
           return coinremitter()->redirectToGateway();
            
        }catch(\Exception $e) {
            return Redirect::back()->withMessage(['msg'=>"There's an error in the data", 'type'=>'error']);
        }        
    }
}

/**
 *  In the case where you need to pass the data from your 
 *  controller instead of a form
 *  Make sure to send:
 *  a = array(
            'amount' => 500, //invoice will expire in 20 minutes. 
            'notify_url'=>'https://yourdomain.com/notify-url', //optional,url on which you wants to receive notification
            'fail_url' => 'https://yourdomain.com/fail-url', //optional,url on which user will be redirect if user cancel invoice,
            'suceess_url' => 'https://yourdomain.com/success-url', //optional,url on which user will be redirect when invoice paid,    
            'description' => '',
            'custom_data1' => '',
            'custom_data2' => '',
        );

return Coinremitter::redirectToGateway($data);

// or alternatively use the helper
return coinremitter()->redirectToGateway($data);


// Laravel 5.1.17 and above
Route::post('/get-invoice', 'PaymentController@createCryptoPayment')->name('get.invoice');

Route::post('/get-invoice', [
    'uses' => 'PaymentController@createCryptoPayment',
    'as' => 'get.invoice'
]);

// Laravel 8 & 9
Route::post('/get-invoice', [App\Http\Controllers\PaymentController::class, 'createCryptoPayment'])->name('get.invoice');



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use PrevailExcel\Coinremitter\Facades\Coinremitter;

class PaymentController extends Controller
{
    
    public function __construct()
    {
        if(!request()->coin)
            request()->coin = 'BTC'; //set a default coin
    }

    /**
     * Collect Order data and Redirect user to Payment gateway
     */
    public function createCryptoPayment()
    {
        try{
            //You should collect the details you need from a form

            $invoiceDetails = Coinremitter::createInvoice();

            // or alternatively use the helper
            $invoiceDetails = coinremitter()->createInvoice();


            dd($invoiceDetails);
            // Now you have the payment details,
            // you can store the authorization_code in your db to allow for recurrent subscriptions
            // you can then redirect or do whatever you want

            
        }catch(\Exception $e) {
            return Redirect::back()->withMessage(['msg'=>"There's an error in the data", 'type'=>'error']);
        }        
    }
}

/**
 *  In the case where you need to pass the data from your 
 *  controller instead of a form
 *  Make sure to send:
 *  a = array(
            'amount' => 500, //invoice will expire in 20 minutes. 
            'notify_url'=>'https://yourdomain.com/notify-url', //optional,url on which you wants to receive notification
            'fail_url' => 'https://yourdomain.com/fail-url', //optional,url on which user will be redirect if user cancel invoice,
            'suceess_url' => 'https://yourdomain.com/success-url', //optional,url on which user will be redirect when invoice paid,    
            'description' => '',
            'custom_data1' => '',
            'custom_data2' => '',
        );

$invoiceDetails = Coinremitter::createInvoice($data);

// or alternatively use the helper
$invoiceDetails = coinremitter()->createInvoice($data);


dd($invoiceDetails);
// Now you have the payment details,
// you can store the authorization_code in your db to allow for recurrent subscriptions
// you can then redirect or do whatever you want



/**
 * This is the method to create an inoice. You need to provide your data as an array.
 * @returns array
 */
Coinremitter::createInvoice();

/**
 * Alternatively, use the helper.
 */
coinremitter()->createInvoice();


/**
 * This is the method to create an inoice and redirct user to payment gateway.
 * @returns array
 */
Coinremitter::redirectToGateway();

/**
 * Alternatively, use the helper.
 */
coinremitter()->redirectToGateway();


/**
 * Get balance of specified coin.
 * @returns array
 */
Coinremitter::balance();

/**
 * Alternatively, use the helper.
 */
coinremitter()->balance();


/**
 * Get crypto rate of given fiat_symbol and fiat_amount
 * @returns array
 */
Coinremitter::getRateFromFiat();

/**
 * Alternatively, use the helper.
 */
coinremitter()->getRateFromFiat();


/**
 * Get invoice details of given invoice id
 * @returns array
 */
Coinremitter::getInvoice()

/**
 * Alternatively, use the helper.
 */
coinremitter()->getInvoice();


/**
 * Get transaction details of given transaction address.
 */
Coinremitter::getTransactionByAddress();

/**
 * Alternatively, use the helper.
 */
coinremitter()->getTransactionByAddress();


/**
 *   Get transaction details of given transaction id.
 */
Coinremitter::getTransaction();

/**
 * Alternatively, use the helper.
 */
coinremitter()->getTransaction();


/**
 * Withdraw coin to specific address.
 * @returns array
 */
Coinremitter::withdraw();
/**
 * Alternatively, use the helper.
 */
coinremitter()->withdraw();


/**
 * Get new address for specified coin
 * @returns array
 */
Coinremitter::createAddress();
/**
 * Alternatively, use the helper.
 */
coinremitter()->createAddress();


/**
 * Validate address for specified coin.
 * @returns array
 */
Coinremitter::validateAddress();
/**
 * Alternatively, use the helper.
 */
coinremitter()->validateAddress();


/**
 *  Get all coins usd rate.
 * @returns array
 */
Coinremitter::getRates();
/**
 * Alternatively, use the helper.
 */
coinremitter()->getRates();
bash
php artisan vendor:publish --provider="PrevailExcel\Coinremitter\CoinremitterServiceProvider"