PHP code example of nanatty32 / laravelhubtelmerchantaccountcedibet
1. Go to this page and download the library: Download nanatty32/laravelhubtelmerchantaccountcedibet 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/ */
nanatty32 / laravelhubtelmerchantaccountcedibet example snippets
Nanatty32\HubtelMerchantAccount\ServiceProvider::class,
'aliases' => [
...
'HubtelMerchantAccount' => Nanatty32\HubtelMerchantAccount\HubtelMerchantAccountFacade::class,
...
]
namespace App\Http\Controllers;
use Nanatty32\HubtelMerchantAccount\OnlineCheckout\Item;
use HubtelMerchantAccount;
use App\Stake;
use Illuminate\Http\Request;
class CheckoutController extends Controller
{
...
public function payOnline(Request $request)
{
$stake = Stake::where('session_id', $request->session()->getId())->latest()->first();
if (!$stake) {
abort(404, 'Invalid stake!');
}
// Initiate online checkout
$ocRequest = new \Nanatty32\HubtelMerchantAccount\OnlineCheckout\Request();
$ocRequest->invoice->description = "Invoice description";
$ocRequest->invoice->total_amount = $stake->total;
$ocRequest->business->name = "CediBet";
$ocRequest->business->logo_url = asset('/img/logo.png');// Can be changed by developers
$ocRequest->business->phone = "0243XXXXXX";
$ocRequest->business->postal_address = "P. O. Box ******";
$ocRequest->business->tagline = "Best online Betting Company In Ghana";
$ocRequest->business->website_url = env('APP_URL');
$ocRequest->actions->cancel_url = url('/checkout/done');
$ocRequest->actions->return_url = url('/checkout/done');
foreach ($stake->items as $item) {
$invoiceItem = new Item();
$invoiceItem->name = $item->product_name;
$invoiceItem->description = "";
$invoiceItem->quantity = $item->quantity;
$invoiceItem->unit_price = $item->price;
$invoiceItem->total_price = $item->price * $item->quantity;
$ocRequest->invoice->addItem($invoiceItem);
}
HubtelMerchantAccount::onlineCheckout($ocRequest);
}
namespace App\Http\Controllers;
use HubtelMerchantAccount;
use Nanatty32\HubtelMerchantAccount\MobileMoney\Receive\Request as ReceiveMobileMoneyRequest;
class CheckoutController extends Controller
{
...
public function payOnline(Request $request)
{
$request = new ReceiveMobileMoneyRequest();
$request->Amount = $this->transaction->amount;
$request->Channel = $this->transaction->channel;
$request->CustomerMsisdn = $this->transaction->mobile_wallet_number;
$request->CustomerName = "N/A";
$request->Description = "Bet Amount";
$request->PrimaryCallbackURL = "https://my-application.com/handle" . $this->transaction->id;
$request->SecondaryCallbackURL = "https://my-application.com/handle/" . $this->transaction->id;
$response = HubtelMerchantAccount::receiveMobileMoney($request);
}
return [
/**
* Merchant account number
*/
"account_number" => env('HUBTEL_MERCHANT_ACCOUNT_NUMBER'),
/**
* Login credentials for hubtel api
*
*/
"api_key" => [
"client_id" => env('HUBTEL_MERCHANT_ACCOUNT_CLIENT_ID'),
"client_secret" => env('HUBTEL_MERCHANT_ACCOUNT_CLIENT_SECRET')
],
/**
* business details
*/
"business" => [
"name" => env('APP_NAME')
]
];