1. Go to this page and download the library: Download prevailexcel/laravel-bani 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/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PrevailExcel\Bani\Facades\Bani;
class PaymentController extends Controller
{
/**
* You collect data from your blade form
* and this returns the Bani Pop Widget
*/
public function createPayment()
{
try {
return Bani::payWithwidget();
} catch (\Exception $e) {
return redirect()->back()->withMessage(['msg' => $e->getMessage(), 'type' => 'error']);
}
}
public function handleGatewayCallback()
{
// verify transaction and get data
$data = bani()->getPaymentData();
// Do anything you want
dd($data);
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PrevailExcel\Bani\Facades\Bani;
class PaymentController extends Controller
{
/**
* You collect data from your blade form
* and this returns the Account details for payment
*/
public function createPayment()
{
try {
$data = [
"pay_amount" => 10000,
"holder_account_type" => "temporary",
"customer_ref" => "MC-69941173958782368244",
"custom_data" => ["id" => 1, "color" => "white"],
];
// You can use the global helper bani()>method() or the Facade Bani:: method().
return bani()->bankTransfer($data);
} catch (\Exception $e) {
return redirect()->back()->withMessage(['msg' => $e->getMessage(), 'type' => 'error']);
}
}
public function handleWebhook()
{
// verify webhook and get data
bani()->getWebhookData()->proccessData(function ($data) {
// Do something with $data
logger($data);
// If you have heavy operations, dispatch your queued jobs for them here
// OrderJob::dispatch($data);
});
// Acknowledge you received the response
return http_response_code(200);
}
}
protected $except = [
'bani/webhook',
];
// For all methods, you can get data from request()
/**
* Check if the customer already exist
* @returns array
*/
Bani::customer(?string $phone, ?string $ref);
// Or
request()->phone;
bani()->customer();
/**
* Create a customer object
* @returns array
*/
Bani::createCustomer();
// Or
bani()->createCustomer();
/**
* Update a customer object
* @returns array
*/
Bani::updateCustomer();
// Or
bani()->updateCustomer();
/**
* Fetch your customer delivery/billing address(es).
*/
Bani::listBillingAddress();
// Or
bani()->listBillingAddress();
/**
* Add customer delivery/billing address(es)
* @returns array
*/
Bani::addBillingAddress();
// Or
bani()->addBillingAddress();
/**
* Uupdate customer's delivery/billing address
* @returns array
*/
Bani::updateBillingAddress();
// Or
bani()->updateBillingAddress();
/**
* Delete customer's delivery/billing address
* @returns array
*/
Bani::deleteBillingAddress();
// Or
bani()->deleteBillingAddress();
/**
* Accept payments from customers via bank transfer
* @returns array
*/
Bani::bankTransfer();
/**
* Accept payments via mobile money from customers
* @returns array
*/
Bani::mobileMoney();
/**
* Accept payments from customers via crypto and get settled in fiat
* @returns array
*/
Bani::payWithCrypto();
/**
* generate a deposit address to accept strictly DLT payments
* and get settled with the same currency
*/
Bani::getWalletAddress();
/**
* Accept one-click payment from customers via bani shopper wallet
* @returns array
*/
Bani::startPayWithBaniShopper();
/**
* Complete 2nd step in payment from customers via bani shopper wallet
* @returns array
*/
Bani::completePayWithBaniShopper();
/**
* The fastest and most secure way to verify mobile numbers using USSD instead of SMS OTPs.
* @returns array
*/
Bani::verifyPhone(?string $phone);
/**
* This endpoint is used to confirmed if the customer phone number has been verified
* @returns array
*/
Bani::checkUssdStatus(?string $verification_reference);
/**
* This endpoint can be used to carry out a lookup on customer account
* @returns array
*/
Bani::confirmEwallet($wallet, $tag, ?string $type);