overtrue / laravel-payment
Laravel 的 Omnipay ServiceProvider。
3.0.0
2020-12-02 15:32 UTC
Requires
- php: >=7.0
- laravel/framework: ~5.0||~6.0||~7.0 || ^8.0
- league/omnipay: ^3.0
- php-http/guzzle7-adapter: ^0.1
Requires (Dev)
- mockery/mockery: ^0.9.9 || ^1.0.0
- overtrue/phplint: dev-master
- phpunit/phpunit: ~6.5 || ^7.0
This package is auto-updated.
Last update: 2024-08-29 04:37:11 UTC
README
💳 Omnipay ServiceProvider for Laravel。
安装
$ composer require overtrue/laravel-payment -v
更新 composer 后,如果您使用的是 laravel 版本 < 5.5,则需要注册服务提供者
// config/app.php 'providers' => [ //... Overtrue\LaravelPayment\ServiceProvider::class, ],
并发布配置文件
$ php artisan vendor:publish --provider=Overtrue\\LaravelPayment\\ServiceProvider
如果您想使用外观模式,可以注册一个您想要使用的名称,例如 LaravelPayment
// config/app.php 'aliases' => [ 'LaravelPayment' => Overtrue\LaravelPayment\Facade::class, // This is default in laravel 5.5 ],
配置
// config/payments.php // The default gateway name which configured in `gateways` section. 'default_gateway' => 'paypal', // The default options for every gateways. 'default_options' => [ 'test_mode' => true, // ... ], /* * The gateways, you can config option by camel case or snake_case name. * * the option name is followed from gateway class, for example: * * $gateway->setMchId('overtrue'); * * you can configured as: * 'mch_id' => 'overtrue', * or: * 'mchId' => 'overtrue', */ 'gateways' => [ 'paypal' => [ 'driver' => 'PayPal_Express', 'options' => [ 'username' => env('PAYPAL_USERNAME'), 'password' => env('PAYPAL_PASSWORD'), 'signature' => env('PAYPAL_SIGNATURE'), 'test_mode' => env('PAYPAL_TEST_MODE'), ], ], // other gateways ],
安装支付网关
您需要安装您想要使用的网关: omnipay#payment-gateways
用法
网关实例
LaravelPayment::gateway('GATEWAY NAME'); // GATEWAY NAME is key name of `gateways` configuration. LaravelPayment::gateway('alipay'); LaravelPayment::gateway('paypal');
使用默认网关
LaravelPayment::purchase(...);
示例
$formData = [ 'number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2030', 'cvv' => '123' ]; $response = LaravelPayment::purchase([ 'amount' => '10.00', 'currency' => 'USD', 'card' => $formData, ))->send(); if ($response->isRedirect()) { // redirect to offsite payment gateway $response->redirect(); } elseif ($response->isSuccessful()) { // payment was successful: update database print_r($response); } else { // payment failed: display message to customer echo $response->getMessage(); }
有关Omnipay的更多用法,请参阅Omnipay官方主页
PHP 扩展包开发
想知道如何从零开始构建 PHP 扩展包吗?
请关注我的实战课程,我将在该课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
许可协议
MIT