yzh52521 / think-omnipay
Integrates Omnipay with thinkphp and provides an easy configuration.
Requires
- php: ^7.2.5|^8.0
- guzzlehttp/guzzle: ^6.0|^7.0
- omnipay/common: ^3.0
- topthink/framework: ^6.0|^8.0
README
Integrates the Omnipay PHP library with Laravel to make Configuring multiple payment tunnels a breeze!
Installation
Include the laravel-omnipay package as a dependency in your composer.json
:
composer require yzh52521/think-omnipay
Note: You don't need to include the omnipay/common
in your composer.json - it has already been included think-omnipay
.
Install Required Providers
Now just include each gateway as you require, to included PayPal for example:
composer require omnipay/paypal "3.*"
Alternatively you can include every gateway by the following:
composer require omnipay/omnipay "3.*"
Note: this requires a large amount of composer work as it needs to fetch each seperate repository. This is not recommended.
Configuration
PayPal Express Example
Here is an example of how to configure password, username and, signature with paypal express checkout driver
... 'gateways' => [ 'paypal' => [ 'driver' => 'PayPal_Express', 'options' => [ 'username' => 'coolusername', 'password' => 'strongpassword', 'signature' => '', 'solutionType' => '', 'landingPage' => '', 'headerImageUrl' => '', 'brandName' => 'Your app name', 'testMode' => true ] ], ] ...
Usage
$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());
This will use the gateway specified in the config as default
.
However, you can also specify a gateway to use.
\ThinkOmnipay\Facade::setGateway('paypal'); $response = \ThinkOmnipay\Facade::purchase([ 'amount' => '100.00', 'card' => $cardInput ])->send(); dd($response->getMessage());
In addition you can make an instance of the gateway.
$gateway = \ThinkOmnipay\Facade::gateway('paypal');
License
This package is open-sourced software licensed under the MIT license.