savebills / laravel-budpay
该软件包的最新版本(dev-main)没有可用的许可证信息。
Laravel 用于与 BudPay API 交互的软件包
dev-main
2024-09-07 12:09 UTC
Requires
- php: ^7.3|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/support: ^8.0|^9.0|^10.0
This package is auto-updated.
Last update: 2024-09-07 12:09:59 UTC
README
# laravel-Budpay [](https://packagist.org.cn/packages/savebills/laravel-Budpay) [](LICENSE.md) [](https://travis-ci.org/savebills/laravel-Budpay) [](https://scrutinizer-ci.com/g/savebills/laravel-Budpay) [](https://packagist.org.cn/packages/savebills/laravel-Budpay) > A Laravel Package for working with Budpay seamlessly ## Installation [PHP](https://php.ac.cn) 5.4+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org.cn) are required. To get the latest version of Laravel Budpay, simply require it ```bash composer require savebills/laravel-budpay:dev-master ``` Or add the following line to the require block of your `composer.json` file. ``` "savebills/laravel-budpay": "dev-master" ``` You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated. Once Laravel Budpay is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key. ```php 'providers' => [ ... savebills\Budpay\BudpayServiceProvider::class, ... ] ``` > If you use **Laravel >= 5.5** you can skip this step and go to [**`configuration`**](https://github.com/savebills/laravel-Budpay#configuration) * `savebills\Budpay\BudpayServiceProvider::class` Also, register the Facade like so: ```php 'aliases' => [ ... 'Budpay' => savebills\Budpay\Facades\Budpay::class, ... ] ``` ## Configuration You can publish the configuration file using this command: ```bash php artisan vendor:publish --provider="BudPay\BudPayServiceProvider" ``` A configuration-file named `Budpay.php` with some sensible defaults will be placed in your `config` directory: ``` env('BUDPAY_SECRET_KEY'), // Your BudPay API Secret Key 'signature_hmac' => env('BUDPAY_HMAC_SIGNATURE'), // Your HMAC signature for encryption ]; ``` ## General payment flow Though there are multiple ways to pay an order, most payment gateways expect you to follow the following flow in your checkout process: ### 1. The customer is redirected to the payment provider After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to the site of the payment provider. The redirection is accomplished by submitting a form with some hidden fields. The form must send a POST request to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash. The hash is calculated using the hidden form fields and a non-public secret. The hash used by the payment provider to verify if the request is valid. ### 2. The customer pays on the site of the payment provider The customer arrives on the site of the payment provider and gets to choose a payment method. All steps necessary to pay the order are taken care of by the payment provider. ### 3. The customer gets redirected back to your site After having paid the order the customer is redirected back. In the redirection request to the shop-site some values are returned. The values are usually the order id, a payment result and a hash. The hash is calculated out of some of the fields returned and a secret non-public value. This hash is used to verify if the request is valid and comes from the payment provider. It is paramount that this hash is thoroughly checked. ## Usage Open your .env file and add your public key, secret key, merchant email and payment url like so: ```php secret_key=xxxxxxxxxxxxx signature_hmac=xxxxxxxxxxxxx ``` *If you are using a hosting service like heroku, ensure to add the above details to your configuration variables.* Set up routes and controller methods like so: Note: Make sure you have `/payment/callback` registered in Budpay Dashboard [https://dashboard.Budpay.co/#/settings/developer](https://dashboard.Budpay.co/#/settings/developer) like so:  ```php // Laravel 5.1.17 and above Route::post('/pay', 'PaymentController@redirectToGateway')->name('pay'); ``` OR ```php Route::post('/pay', [ 'uses' => 'PaymentController@redirectToGateway', 'as' => 'pay' ]); ``` OR ```php // Laravel 8 & 9 Route::post('/pay', [App\Http\Controllers\PaymentController::class, 'redirectToGateway'])->name('pay'); ``` ```php Route::get('/payment/callback', 'PaymentController@handleGatewayCallback'); ``` OR ```php // Laravel 5.0 Route::get('payment/callback', [ 'uses' => 'PaymentController@handleGatewayCallback' ]); ``` OR ```php // Laravel 8 & 9 Route::get('/payment/callback', [App\Http\Controllers\PaymentController::class, 'handleGatewayCallback']); ``` ```php budPay = $budPay; } public function initializePayment(Request $request) { $amount = $request->input('amount'); $callbackUrl = route('payment.callback'); $customerName = $request->input('name'); $customerEmail = $request->input('email'); $response = $this->budPay->processPayment($amount, $callbackUrl, $customerName, $customerEmail); return response()->json($response); } public function createPaymentLink(Request $request) { $amount = $request->input('amount'); $currency = 'NGN'; $name = $request->input('name'); $description = 'Payment for service'; $redirectUrl = route('payment.success'); $response = $this->budPay->createBudPayPaymentLink($amount, $currency, $name, $description, $redirectUrl); return response()->json($response); } } ``` ```php /** * In the case where you need to pass the data from your * controller instead of a form * Make sure to send: * required: email, amount, reference, orderID(probably) * optionally: currency, description, metadata * e.g: * */ ``` Let me explain the fluent methods this package provides a bit here. ```php /** * To Make Payment */ Budpay::processPayment($amount, $callback, $customerName, $customerEmail); /** * Verify all Payment */ Budpay::verifyPayment($transactionId); /** * Create Payment Link */ Budpay::createBudPayPaymentLink($amount, $currency, $name, $description, $redirectUrl); /** * Create Bulk Payment */ Budpay::bulkBankTransfe(array $transfers); /** * Fetch Payment Status */ Budpay::fetchPayoutStatus($reference); /** * Get Wallet Balance */ Budpay::fetchWalletBalance($currency); /** * Single Payout */ Budpay::singlePayout($data); /** * Fetch Bank List */ Budpay::fetchBankList(); /** * Verify Account Number */ Budpay::fetchVerifyaccount(($bankcode,$accountnumber); /** * To Fetch Airtime Payment */ Budpay::fetchAirtimeList(); /** * To Topup Airtime Payment */ Budpay::processAirtime($provider, $number, $amount, $reference); /** * Get Internet */ Budpay::fetchDataList(); /** * Get Internet provider */ Budpay::fetchDataList($provider); /** * Get Buy Internet */ Budpay::processdata($provider, $number, $planId, $reference); /** * Get Tv */ Budpay::fetchTvList(); /** * Get Tv Provider */ Budpay::fetchTvroviderList($provider) /** * Get PayTv */ Budpay::processPaytv($provider, $number, $code, $reference) ``` ```html拉各斯 Eyo 印花T恤 2,950奈拉{{-- required --}} {{-- required in kobo --}} {{-- For other necessary things you want to add to your payload. it is optional though --}} {{-- required --}} {{-- to support transaction split. more details https://Budpay.com/docs/payments/multi-split-payments/#using-transaction-splits-with-payments --}} {{-- to support dynamic transaction split. More details https://Budpay.com/docs/payments/multi-split-payments/#dynamic-splits --}} {{ csrf_field() }} {{-- works only when using laravel 5.1, 5.2 --}} {{-- employ this in place of csrf_field only in laravel 5.0 --}}
立即支付!
``` 点击提交按钮后,客户将被重定向到 Budpay 网站。现在我们已经将客户重定向到 Budpay。客户在那里执行了一些操作(希望他们已经支付了订单)然后被重定向回到我们的商店网站。Budpay 将将客户重定向到 Budpay 控制台 Web Hooks 部分的回调 URL 中指定的路由 URL。我们必须验证重定向到我们网站的是否是有效的请求(我们不想冒名顶替者错误地放置未付款的订单)。在处理来自支付提供者的请求的控制台中,我们有 `Budpay::getPaymentData()` - 此函数调用验证方法并确保它是有效的交易,否则抛出异常。您可以使用以下这些详细信息进行测试 ```bash 卡号:4123450131001381 有效期:未来的任何日期 CVV:883 ``` ## 待办事项 * 对回头客收费 * 添加综合测试 * 实现交易仪表板以查看您的 Laravel 应用程序中的所有交易 ## 贡献 请随意将该软件包分叉并提交拉取请求以增强功能。 ## 如何感谢您?为什么不给 github 仓库点个赞?我很乐意得到关注!为什么不分享这个存储库的链接到 Twitter 或 HackerNews?传播消息!别忘了[在推特上关注我](https://twitter.com/savebills)!谢谢! Prosper Otemuyiwa。 ## 许可证 MIT 许可证(MIT)。请参阅[许可证文件](LICENSE.md)以获取更多信息。 # savebills