recca0120 / laravel-payum
为 Laravel 框架提供丰富的支付解决方案。Paypal、payex、authorize.net、be2bill、omnipay、周期性支付、即时通知等
v1.1.5
2017-03-05 17:14 UTC
Requires
- php: >=5.5.9
- illuminate/database: ^5.1
- illuminate/events: ^5.1
- illuminate/filesystem: ^5.1
- illuminate/routing: ^5.1
- illuminate/session: ^5.1
- illuminate/support: ^5.1
- illuminate/view: ^5.1
- payum/core: ^1.3
- php-http/guzzle6-adapter: ^1.1
Requires (Dev)
- mockery/mockery: ~0.9.4
- nesbot/carbon: ~1.20
- phpunit/phpunit: ~4.8|~5.4
Suggests
- payum-tw/allpay: If you want to use allpay gateways
- payum-tw/esunbank: If you want to use esunbank gateways
- payum-tw/mypay: If you want to use mypay gateways
- payum/authorize-net-aim: If you want to use authorize.net gateway
- payum/be2bill: If you want to use be2bill gateway
- payum/omnipay-bridge: If you want to use omnipay provided gateways
- payum/payex: If you want to use payex gateway
- payum/paypal-express-checkout-nvp: If you want to use paypal express checkout nvp gateway
- payum/paypal-pro-checkout-nvp: If you want to use paypal pro checkout nvp gateway
- payum/stripe: If you want to use stripe gateways
README
安装
要获取 Laravel 异常的最新版本,只需使用 Composer 引入项目。
composer require recca0120/laravel-payum
当然,您也可以手动更新 require 块并运行 composer update
。
{ "require": { "recca0120/laravel-payum": "^1.0.6" } }
在 config/app.php
中包含服务提供者。服务提供者对于 artisan 命令生成器是必需的。
'providers' => [ ... Recca0120\LaravelPayum\LaravelPayumServiceProvider::class, ... ];
配置
return [ 'route' => [ 'prefix' => 'payment', 'as' => 'payment.', 'middleware' => ['web'], ], 'storage' => [ // options: eloquent, filesystem 'token' => 'filesystem', // options: eloquent, filesystem 'gatewayConfig' => 'filesystem', ], 'gatewayConfigs' => [ // 'customFactoryName' => [ // 'factory' => 'FactoryClass', // 'username' => 'username', // 'password' => 'password', // 'sandbox' => false // ], ], ];
VerifyCsrfToken
namespace App\Http\Middleware; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; class VerifyCsrfToken extends BaseVerifier { /** * The URIs that should be excluded from CSRF verification. * * @var array */ protected $except = [ 'payment/*' ]; }
控制器
namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Payum\Core\GatewayInterface; use Payum\Core\Model\PaymentInterface; use Payum\Core\Payum; use Payum\Core\Request\GetHumanStatus; use Payum\Core\Security\TokenInterface; use Payum\Core\Storage\StorageInterface; use Recca0120\LaravelPayum\Service\PayumService; class PaymentController extends BaseController { public function capture(PayumService $payumService) { return $payumService->capture('allpay', function ( PaymentInterface $payment, $gatewayName, StorageInterface $storage, Payum $payum ) { $payment->setNumber(uniqid()); $payment->setCurrencyCode('TWD'); $payment->setTotalAmount(2000); $payment->setDescription('A description'); $payment->setClientId('anId'); $payment->setClientEmail('foo@example.com'); $payment->setDetails([ 'Items' => [ [ 'Name' => '歐付寶黑芝麻豆漿', 'Price' => (int) '2000', 'Currency' => '元', 'Quantity' => (int) '1', 'URL' => 'dedwed', ], ], ]); }); } public function done(PayumService $payumService, $payumToken) { return $payumService->done($payumToken, function ( GetHumanStatus $status, PaymentInterface $payment, GatewayInterface $gateway, TokenInterface $token ) { return response()->json([ 'status' => $status->getValue(), 'client' => [ 'id' => $payment->getClientId(), 'email' => $payment->getClientEmail(), ], 'number' => $payment->getNumber(), 'description' => $payment->getCurrencyCode(), 'total_amount' => $payment->getTotalAmount(), 'currency_code' => $payment->getCurrencyCode(), 'details' => $payment->getDetails(), ]); }); } }
路由器
Route::get('payment', [ 'as' => 'payment', 'uses' => 'PaymentController@capture', ]); Route::any('payment/done/{payumToken}', [ 'as' => 'payment.done', 'uses' => 'PaymentController@done', ]);
Eloquent
如果您想使用 Eloquent,需要更改 config.php 并创建数据库。
迁移
发布供应商
artisan vendor:publish --provider="Recca0120\LaravelPayum\LaravelPayumServiceProvider"
迁移
artisan migrate
修改配置
return [ 'route' => [ 'prefix' => 'payment', 'as' => 'payment.', 'middleware' => ['web'], ], 'storage' => [ // options: eloquent, eloquent 'token' => 'filesystem', // options: eloquent, filesystem 'gatewayConfig' => 'filesystem', ], // 'customFactoryName' => [ // 'factory' => 'FactoryClass', // 'username' => 'username', // 'password' => 'password', // 'sandbox' => false // ], 'gatewayConfigs' => [ 'offline' => [] ], ];