abdallahmohammed / urway-laravel
为Laravel的URWAY REST API包
1.2.3
2023-07-31 00:23 UTC
Requires
- php: ^7.4|8.*
- guzzlehttp/guzzle: >=6.0
- illuminate/support: ^5.2|^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ~3.0|^4.0|^5.0
- phpunit/phpunit: ^5.3|~6.0|~8.0
README
安装
composer require abdallahmohammed/urway-laravel
在Laravel 6.x版本及以上,服务提供者会自动注册。在框架的旧版本中,只需在config/app.php
文件中添加服务提供者。
'providers' => [ // ... URWay\URWayServiceProvider::class, ],
您可以选择在config/app.php
中注册门面。
'facades' => [ // ... 'URWay' => URWay\Facade\URWay::class, ],
您可以使用以下命令发布:
php artisan vendor:publish --provider="URWay\URWayServiceProvider"
发布后,config/urway.php
配置文件将包含:
<?php return [ 'mode' => env('URWAY_MODE', 'test'), 'auth' => [ 'terminal_id' => env('URWAY_TERMINAL_ID'), 'password' => env('URWAY_PASSWORD'), 'merchant_key' => env('URWAY_MERCHANT_KEY'), ], ];
使用方法
use URWay\Client; // Create clint instance. $client = new Client(); $client->setTrackId('YOUR_TRAKING_ID') ->setCustomerEmail('...') ->setCustomerIp('...') ->setCurrency('USD') ->setCountry('EG') ->setAmount(5) ->setRedirectUrl('...'); // Replace presented attributes with the given array. $client->setAttributes([ '...' => '...' ]); // Merge presented attributes the given array. $client->mergeAttributes([ '...' => '...' ]); // Replace one of presented attributes with the new value. $client->setAttribute('...', '...'); // Remove one of attributes. $client->removeAttribute('...'); // Determine whether an attribute exists. $client->hasAttribute('...'); // returns boolean (true, or false) $redirect_url = $client->pay(); return redirect()->url($redirect_url);
并在回调中处理响应,请放置以下代码
use URWay\Client; // Create clint instance. $client = new Client(); $response = $client->find('TRANSACTION_ID'); if ($response->isSuccess()) { // } if ($response->isFailure()) { // } // To dump all payment details. dd($response);
生产环境
要在生产模式下使用此包,只需将config/urway.php
文件中的mode
值更新为production
。