jowusu837 / laravelhubtelmerchantaccount
此包已被废弃且不再维护。未建议替代包。
Laravel 的 Hubtel 商户账户集成
1.1.2
2018-02-02 16:29 UTC
Requires
- guzzlehttp/guzzle: ^6.3
This package is not auto-updated.
Last update: 2022-05-04 17:46:13 UTC
README
基于 https://developers.hubtel.com/documentations/merchant-account-api
关于
laravel-hubtel-merchant-account
包允许您直接在 Laravel 应用程序中使用 Hubtel 商户账户 API 接收和处理支付。
功能
- 接收移动货币
- 发送移动货币
- 检查交易状态
- 在线结账
安装
在您的 composer.json
中要求 jowusu837/laravelhubtelmerchantaccount
包并更新您的依赖项
$ composer require jowusu837/laravelhubtelmerchantaccount
如果您使用的是 Laravel 5.5,这就足够了。
如果您仍在使用较旧的 Laravel 版本,您需要进行的最后一步是添加包的服务提供者和别名。为此,打开您的 config/app.php
文件。
将 HubtelMerchantAccount\ServiceProvider
添加到您的 providers
数组中
Jowusu837\HubtelMerchantAccount\ServiceProvider::class,
并在 aliases
数组中添加一行新内容
'aliases' => [ ... 'HubtelMerchantAccount' => Jowusu837\HubtelMerchantAccount\HubtelMerchantAccountFacade::class, ... ]
使用在线结账功能
假设您是从控制器方法中使用此功能,您可以这样做
namespace App\Http\Controllers; use Jowusu837\HubtelMerchantAccount\OnlineCheckout\Item; use HubtelMerchantAccount; use App\Order; use Illuminate\Http\Request; class CheckoutController extends Controller { ... public function payOnline(Request $request) { $order = Order::where('session_id', $request->session()->getId())->latest()->first(); if (!$order) { abort(404, 'Invalid order!'); } // Initiate online checkout $ocRequest = new \Jowusu837\HubtelMerchantAccount\OnlineCheckout\Request(); $ocRequest->invoice->description = "Invoice description"; $ocRequest->invoice->total_amount = $order->total; $ocRequest->store->name = "My Shop"; $ocRequest->store->logo_url = asset('/img/logo.png'); $ocRequest->store->phone = "0243XXXXXX"; $ocRequest->store->postal_address = "P. O. Box 123456"; $ocRequest->store->tagline = "Best online shop ever"; $ocRequest->store->website_url = env('APP_URL'); $ocRequest->actions->cancel_url = url('/checkout/done'); $ocRequest->actions->return_url = url('/checkout/done'); foreach ($order->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 Jowusu837\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 = "General payment"; $request->PrimaryCallbackURL = "https://my-application.com/handle" . $this->transaction->id; $request->SecondaryCallbackURL = "https://my-application.com/handle/" . $this->transaction->id; $response = HubtelMerchantAccount::receiveMobileMoney($request); }
配置
默认值设置在 config/hubtelmerchantaccount.php
中。将此文件复制到您的配置目录以修改值。您可以使用此命令发布配置
$ php artisan vendor:publish --provider="Jowusu837\HubtelMerchantAccount\ServiceProvider"
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') ], /** * Store details */ "store" => [ "name" => env('APP_NAME') ] ];
许可证
在 MIT 许可证下发布,请参阅 LICENSE。