devmohy / laravel-budpay
Laravel 的 budpay 包
1.0.0
2023-06-18 06:46 UTC
README
Laravel Budpay 是一个为 Laravel 应用程序提供 Budpay 支付网关集成的包。
安装
您可以通过运行以下命令使用 Composer 安装 Laravel Budpay 包
composer require devmohy/laravel-budpay
配置
安装包后,您需要发布配置文件。运行以下命令
php artisan vendor:publish --provider="Devmohy\Budpay\BudpayServiceProvider"
这将在您的 Laravel 应用程序的 config 目录中创建一个 budpay.php 配置文件。打开该文件并设置您的 Budpay 密钥
<?php return [ /** * Public Key From Budpay Dashboard * */ 'publicKey' => getenv('BUDPAY_PUBLIC_KEY'), /** * Secret Key From Budpay Dashboard * */ 'secretKey' => getenv('BUDPAY_SECRET_KEY'), /** * Paystack Payment URL * */ 'paymentUrl' => env('BUDPAY_PAYMENT_URL'), ];
使用方法
打开您的 .env 文件并添加您的公钥、私钥和支付 URL,如下所示
BUDPAY_PUBLIC_KEY=xxxxxxxxxxxxx BUDPAY_SECRET_KEY=xxxxxxxxxxxxx BUDPAY_PAYMENT_URL=https://api.budpay.com/api
设置路由和控制器方法如下
Route::post('/pay', [App\Http\Controllers\PaymentController::class, 'redirectToGateway'])->name('pay'); Route::get('/payment/callback', [App\Http\Controllers\PaymentController::class, 'handleGatewayCallback']);
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Redirect; use Budpay; class PaymentController extends Controller { /** * Redirect the User to Budpay Payment Page * @return Url */ public function redirectToGateway() { try{ return Budpay::getAuthorizationUrl()->redirectNow(); }catch(\Exception $e) { return Redirect::back()->withMessage(['msg'=>'The budpay token has expired. Please refresh the page and try again.', 'type'=>'error']); } } /** * Obtain Budpay payment information * @return void */ public function handleGatewayCallback() { $paymentDetails = Budpay::getPaymentData(); dd($paymentDetails); // Now you have the payment details, // you can then redirect or do whatever you want } }
Laravel Budpay 包提供了几种方法,以简化 Laravel 应用程序中与 Budpay 支付网关的集成。以下是该包提供的关键方法
- 接受支付
/* * This convenient method handles the behind-the-scenes tasks of sending a POST request with the * form data to the Budpay API. It takes care of all the necessary steps, including obtaining * the authorization URL and redirecting the user to the Budpay Payment Page. We've abstracted * away all the complexities, allowing you to focus on your coding tasks without worrying about * these implementation details. So go ahead, enjoy your coding journey while we handle the rest! */ Budpay::getAuthorizationUrl()->redirectNow(); /** * This method gets all the transactions that have occurred * @returns array */ Budpay::getAllTransactions(); /** * This method Initiate a payment request using Budpay Standard Checkout * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::standardCheckout(); /** * This method Initiate a payment request using Budpay Server To Server Bank Transfer Checkout * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::serverToServerBankTransferCheckout(); /** * This method Initiate a payment request to Budpay using server to server v2 * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::serverToServerV2(); /** * This method Fetch transaction using transaction ID * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::fetchTransaction();
示例表单看起来像这样
<form method="POST" action="{{ route('pay') }}" accept-charset="UTF-8" class="form-horizontal" role="form"> <div class="row" style="margin-bottom:40px;"> <div class="col-md-8 col-md-offset-2"> <p> <div> Donjazzy's Burger ₦ 2,400 </div> </p> <input type="hidden" name="email" value="yayahmohammed@gmail.com"> {{-- required --}} <input type="hidden" name="orderID" value="ORD123"> <input type="hidden" name="amount" value="800"> {{-- required in kobo --}} <input type="hidden" name="quantity" value="3"> <input type="hidden" name="currency" value="NGN"> <p> <button class="btn btn-success btn-lg btn-block" type="submit" value="Pay Now!"> <i class="fa fa-plus-circle fa-lg"></i> Pay Now! </button> </p> </div> </div> </form>
- 支付功能
/** * Initiate a payment request to Budpay * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::requestPayment(); /** * This method Create customer on budpay * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::createCustomer(); /** * This method Create a dedicated virtual account and assign to a customer * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::createDedicatedVirtualAccount(); /** * This method List dedicated virtual accounts * @returns array */ Budpay::listDedicatedVirtualAccount(); /** * This method Fetch Dedicated Virtual Account By ID * @returns array */ Budpay::fetchDedicatedVirtualAccountById(); /** * This method Create Payment Link * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::createPaymentLink(); /** * This method Fetch Settlements * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::getSettlements(); /** * This method Fetch Settlements By Batch ID * @returns array */ Budpay::getSettlementsByBatch(); /** * This method Create Refund * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::createRefund(); /** * This method Fetch Refunds * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::listRefunds(); /** * This method Fetch refund by Reference * @returns array */ Budpay::fetchRefund();
- 支付结算
/** * This method Fetch Banks * @returns array */ Budpay::bankLists(); /** * This method Initiate Transfer * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::singlePayout(); /** * This method Initiate Bulk Transfer * "currency": "NGN", * "transfers": [ * { * "amount": "200", * "bank_code": "000013", * "bank_name": "GUARANTY TRUST BANK", * "account_number": "0050883605", * "narration": "January Salary" * }, * { * "amount": "100", * "bank_code": "000013", * "bank_name": "GUARANTY TRUST BANK", * "account_number": "0050883605", * "narration": "February Salary" * }, * ] * @returns array */ Budpay::bulkPayout( ["currency" => "NGN", "transfers" => [ { "amount" => "200", "bank_code" => "000013", "bank_name" => "GUARANTY TRUST BANK", "account_number" => "0050883605", "narration" => "January Salary" }, { "amount" => "100", "bank_code" => "000013", "bank_name" => "GUARANTY TRUST BANK", "account_number" => "0050883605", "narration" => "February Salary" }, { "amount" => "100", "bank_code" => "000013", "bank_name" => "GUARANTY TRUST BANK", "account_number" => "0050883605", "narration" => "March Salary" } ]] ); /** * This method Fetch a payout record using payout reference. * @param $ref * @returns array */ Budpay::verifyPayout($ref); /** * This method return Payout Fee (Bank Transfer Fee) * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::payoutFee(); /** * This method return Wallet balance by Currency * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::walletBalance(); /** * This Wallet transactions method allows you fetch all your wallet transaction history. * @returns array */ Budpay::walletTransactions();
- 账单支付
/** * This method Fetch all available Airtime Providers * @returns array */ Budpay::airtimeProviders(); /** * This method Buy Airtime * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::airtimeTopUp(); /** * This method FFetch all available Internet Providers. * @returns array */ Budpay::internetProviders(); /** * This method Get all available Internet Data Plans * @returns array */ Budpay::internetDataPlans(); /** * This method Initiate a Internet Data Purchase Transaction * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::internetDataPurchase(); /** * This method Get all available Tv Packages (Bouquet) of a Provider * @returns array */ Budpay::tvProviders(); /** * This method Get all available Tv Packages (Bouquet) of a Provider * @param string $provider * @returns array */ Budpay::tvProviderPackages(); /** * This method Perform a Tv UIC Number Validation * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::tvValidate(); /** * This method Initiate a Tv Subscription Payment * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::tvSubscription(); /** * This method Get all available Electricity Providers * @returns array */ Budpay::electricityProviders(); /** * This method Perform a Electricity Meter Number Validation * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::electricityValidate(); /** * This method Initiate a Electricity Recharge Payment * Included the option to pass the payload to this method for situations * when the payload is built on the fly (not passed to the controller from a view) * @returns array */ Budpay::electricityRecharge();
贡献
请随意 fork 此包,并通过提交拉取请求来增强功能。
如何感谢您?
为什么不 star github 仓库?我非常希望得到关注!为什么不分享此仓库的链接到 Twitter 或 HackerNews?传播消息!
别忘了 在 Twitter 上关注我!
谢谢!
Mohammed Yayah.
许可
Laravel Budpay 是开源软件,根据 MIT 许可证 (MIT) 许可 许可文件