yzh52521 / think-omnipay
将 Omnipay 集成到 thinkphp 中,并提供简单的配置。
v1.0.5
2023-06-21 07:19 UTC
Requires
- php: ^7.2.5|^8.0
- guzzlehttp/guzzle: ^6.0|^7.0
- omnipay/common: ^3.0
- topthink/framework: ^6.0|^8.0
README
将 Omnipay PHP 库集成到 Laravel 中,使配置多个支付通道变得简单!
安装
在您的 composer.json
中将 laravel-omnipay 包作为依赖项包含
composer require yzh52521/think-omnipay
注意:您不需要在 composer.json 中包含 omnipay/common
- 它已经被 think-omnipay
包含了。
安装所需提供者
现在只需包含您需要的每个网关,例如要包含 PayPal,
composer require omnipay/paypal "3.*"
或者您可以通过以下方式包含所有网关
composer require omnipay/omnipay "3.*"
注意:这需要大量的 composer 工作,因为它需要获取每个单独的存储库。这不建议。
配置
PayPal Express 示例
以下是如何使用 PayPal Express 检查驱动程序配置密码、用户名和签名的示例。
... 'gateways' => [ 'paypal' => [ 'driver' => 'PayPal_Express', 'options' => [ 'username' => 'coolusername', 'password' => 'strongpassword', 'signature' => '', 'solutionType' => '', 'landingPage' => '', 'headerImageUrl' => '', 'brandName' => 'Your app name', 'testMode' => true ] ], ] ...
使用方法
$cardInput = [ 'number' => '4444333322221111', 'firstName' => 'MR. WALTER WHITE', 'expiryMonth' => '03', 'expiryYear' => '16', 'cvv' => '333', ]; $card = \ThinkOmnipay\Facade::creditCard($cardInput); $response = \ThinkOmnipay\Facade::purchase([ 'amount' => '100.00', 'returnUrl' => 'http://bobjones.com/payment/return', 'cancelUrl' => 'http://bobjones.com/payment/cancel', 'card' => $cardInput ])->send(); dd($response->getMessage());
这将使用配置中指定的网关作为 default
。
但是,您也可以指定要使用的网关。
\ThinkOmnipay\Facade::setGateway('paypal'); $response = \ThinkOmnipay\Facade::purchase([ 'amount' => '100.00', 'card' => $cardInput ])->send(); dd($response->getMessage());
此外,您还可以创建网关的一个实例。
$gateway = \ThinkOmnipay\Facade::gateway('paypal');
许可证
此软件包是开源软件,许可协议为 MIT 许可证。