https://github.com/hongyukeji/laravel-payment
https://github.com/hongyukeji/laravel-payment
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hongyukeji/laravel-payment
- Owner: hongyukeji
- Created: 2019-05-23T15:28:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-27T03:03:45.000Z (about 4 years ago)
- Last Synced: 2025-01-03T16:35:03.857Z (5 months ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel Payment
:credit_card: [Omnipay](https://github.com/thephpleague/omnipay) ServiceProvider for Laravel.
[](https://travis-ci.org/hongyukeji/laravel-payment)
[](https://packagist.org/packages/hongyukeji/laravel-payment)
[](https://packagist.org/packages/hongyukeji/laravel-payment)
[](https://packagist.org/packages/hongyukeji/laravel-payment)
[](https://packagist.org/packages/hongyukeji/laravel-payment)## Installing
```
$ composer require hongyukeji/laravel-payment
```After updated composer, if you are using laravel version < 5.5, you need to register service provider:
```
// config/app.php'providers' => [
//...
Hongyukeji\LaravelPayment\Providers\PaymentServiceProvider::class,
],
```And publish the config file:
```shell
$ php artisan vendor:publish --provider="Hongyukeji\\LaravelPayment\\Providers\\PaymentServiceProvider"
```if you want to use facade mode, you can register a facade name what you want to use, for example `LaravelPayment`:
```
// config/app.php'aliases' => [
'Payment' => Hongyukeji\LaravelPayment\Facades\Payment::class, // This is default in laravel 5.5
],
```### configuration
```
// 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('hongyukeji');
*
* you can configured as:
* 'mch_id' => 'hongyukeji',
* or:
* 'mchId' => 'hongyukeji',
*/
'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
],
```### install payment gateways
You need to install the gateway you want to use: [omnipay#payment-gateways](https://github.com/thephpleague/omnipay#payment-gateways)
## Usage
Gateway instance:
```
Payment::gateway('GATEWAY NAME'); // GATEWAY NAME is key name of `gateways` configuration.
Payment::gateway('alipay');
Payment::gateway('paypal');
```Using default gateway:
```
Payment::purchase(...);
```Example:
```
$formData = [
'number' => '4242424242424242',
'expiryMonth' => '6',
'expiryYear' => '2030',
'cvv' => '123'
];$response = Payment::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();
}
```For more use about [Omnipay](https://github.com/omnipay/omnipay), please refer to [Omnipay Official Home Page](http://omnipay.thephpleague.com/)
## License
MIT