2017 © Pedro Peláez
 

library laravel-payment

Omnipay ServiceProvider for Laravel.

image

overtrue/laravel-payment

Omnipay ServiceProvider for Laravel.

  • Saturday, March 31, 2018
  • by overtrue
  • Repository
  • 2 Watchers
  • 29 Stars
  • 427 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 2 Versions
  • 116 % Grown

The README.md

Laravel Payment

:credit_card: Omnipay ServiceProvider for Laravel., (*1)

Build Status Latest Stable Version Total Downloads License composer.lock, (*2)

Installing

$ composer require overtrue/laravel-payment -v

After updated composer, if you are using laravel version < 5.5, you need to register service provider:, (*3)

// config/app.php

    'providers' => [
        //...
        Overtrue\LaravelPayment\ServiceProvider::class,
    ],

And publish the config file:, (*4)

$ php artisan vendor:publish --provider=Overtrue\\LaravelPayment\\ServiceProvider

if you want to use facade mode, you can register a facade name what you want to use, for example LaravelPayment:, (*5)

// config/app.php

    'aliases' => [
        'LaravelPayment' => Overtrue\LaravelPayment\Facade::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('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
    ],

install payment gateways

You need to install the gateway you want to use: omnipay#payment-gateways, (*6)

Usage

Gateway instance:, (*7)

LaravelPayment::gateway('GATEWAY NAME'); // GATEWAY NAME is key name of `gateways` configuration.
LaravelPayment::gateway('alipay');
LaravelPayment::gateway('paypal');

Using default gateway:, (*8)

LaravelPayment::purchase(...);

Example:, (*9)

$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();
}

For more use about Omnipay, please refer to Omnipay Official Home Page, (*10)

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?, (*11)

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》, (*12)

License

MIT, (*13)

The Versions

31/03 2018

dev-master

9999999-dev

Omnipay ServiceProvider for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

31/03 2018

1.0.1

1.0.1.0

Omnipay ServiceProvider for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue