PHP code example of prevailexcel / laravel-nowpayments
1. Go to this page and download the library: Download prevailexcel/laravel-nowpayments 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-nowpayments example snippets
return [
/**
* API Key From NOWPayments Dashboard
*
*/
'apiKey' => env('NOWPAYMENTS_API_KEY'),
/**
* IPN Secret from NOWPayments Dashboard
*/
'ipnSecret' => env('NOWPAYMENTS_IPN_SECRET'),
/**
* You enviroment can either be live or sandbox.
* Make sure to add the appropriate API key after changing the enviroment in .env
*
*/
'env' => env('NOWPAYMENTS_ENV', 'sandbox'),
/**
* NOWPayments Live URL
*
*/
'liveUrl' => env('NOWPAYMENTS_LIVE_URL', "https://api.nowpayments.io/v1"),
/**
* NOWPayments Sandbox URL
*
*/
'sandboxUrl' => env('NOWPAYMENTS_SANDBOX_URL', "https://api-sandbox.nowpayments.io/v1"),
/**
* Your callback URL
*
*/
'callbackUrl' => env('NOWPAYMENTS_CALLBACK_URL'),
/**
* Your URL Path
*
*/
'path' => 'laravel-nowpayments',
/**
* You can add your custom middleware to access the dashboard here
*
*/
'middleware' => null, // "Authorise::class",
/**
* Your Nowpayment email here
*
*/
'email' => env('NOWPAYMENTS_EMAIL'),
/**
* Your Nowpayment password here
*
*/
'password' => env('NOWPAYMENTS_PASSWORD'),
];
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use PrevailExcel\Nowpayments\Facades\Nowpayments;
class PaymentController extends Controller
{
/**
* Collect Order data and create Payment
* @return Url
*/
public function createCryptoPayment()
{
try{
$data = [
'price_amount' => request()->price_amount ?? 100,
'price_currency' => request()->price_currency ?? 'usd',
'order_id' => request()->order_id ?? uniqid(), // you can generate your order id as you wish
'pay_currency' => request()->pay_currency ?? 'btc',
'payout_currency' => request()->payout_currency ?? 'btc',
];
$paymentDetails = Nowpayments::createPayment($data);
dd($paymentDetails);
// Now you have the payment details,
// you can then redirect or do whatever you want
return Redirect::back()->with(['msg'=>"Payment created successfully", 'type'=>'success'], 'data'=>$paymentDetails);
}catch(\Exception $e) {
return Redirect::back()->withMessage(['msg'=>"There's an error in the data", 'type'=>'error']);
}
}
}
/**
* This is the method to create a payment. You need to provide your data as an array.
* @returns array
*/
Nowpayments::createPayment();
/**
* Alternatively, use the helper.
*/
nowpayments()->createPayment();
/**
* Gets the payment details of a particular transaction including the status with the paymentId
* @returns array
*/
Nowpayments::getPaymentStatus();
/**
* Alternatively, use the helper.
*/
nowpayments()->getPaymentStatus();
/**
* Get all currenices
* @returns array
*/
Nowpayments::getCurrencies()
/**
* Alternatively, use the helper.
*/
nowpayments()->getCurrencies();
/**
* Get the minimum payment amount for a specific pair.
*/
Nowpayments::getMinimumPaymentAmount();
/**
* Alternatively, use the helper.
*/
nowpayments()->getMinimumPaymentAmount();
/**
* Creates invoice with url where user can complete the payment.
* @returns array
*/
Nowpayments::createInvoice();
/**
* Alternatively, use the helper.
*/
nowpayments()->createInvoice();
/**
* This method allows you to obtain information about all the payment plans you’ve created.
* @returns array
*/
Nowpayments::getPlans();
/**
* Alternatively, use the helper.
*/
nowpayments()->getPlans();
/**
* Get information about a particular recurring payment via its ID.
* @returns array
*/
Nowpayments::getSubscription();
/**
* Alternatively, use the helper.
*/
nowpayments()->getSubscription();
/**
* This method allows you to send payment links to your customers via email.
* @returns array
*/
Nowpayments::emailSubscription();
/**
* Alternatively, use the helper.
*/
nowpayments()->emailSubscription();
/**
* Completely removes a particular payment from the recurring payment plan.
* @returns array
*/
Nowpayments::deleteSubscription();
/**
* Alternatively, use the helper.
*/
nowpayments()->deleteSubscription();
/**
* Returns the entire list of all transactions, created with certain API key.
* @returns array
*/
Nowpayments::getListOfPayments();
/**
* Alternatively, use the helper.
*/
nowpayments()->getListOfPayments();
/**
* This method gets the estitmate price of an amount in different pairs
* @return array
*/
Nowpayments::getEstimatePrice();
/**
* Alternatively, use the helper.
*/
nowpayments()->getEstimatePrice();