GithubHelp home page GithubHelp logo

laravel-payment's Introduction

Laravel Payment

💳 Omnipay ServiceProvider for Laravel.

Build Status Latest Stable Version Total Downloads License composer.lock

Installing

$ composer require overtrue/laravel-payment -v

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

// config/app.php

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

And publish the config file:

$ 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:

// 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

Usage

Gateway instance:

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

Using default gateway:

LaravelPayment::purchase(...);

Example:

$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

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

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

License

MIT

laravel-payment's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar makroxyz avatar overtrue avatar shirone avatar summerblue avatar sunl888 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-payment's Issues

执行composer require overtrue/laravel-payment -v 提示package没找到

在我的项目中执行 composer require overtrue/laravel-payment -v

提示如下错误:
[InvalidArgumentException]
Could not find package overtrue/laravel-payment at any version for your minimum-stability (stable). Check the packa
ge spelling or your minimum-stability
我的laravel版本是5.5

发布路径问题

因为我们项目外面有两层目录(项目名称/code/框架代码),所以在 php artisan vendor:publis 的时候会报 Can't locate path: <0> 这个错误.
希望能将
$this->publishes([ __DIR__.'/../config/payments.php', ], 'config');
改成
$this->publishes([ __DIR__.'/../config/payments.php' => config_path('payments.php'), ], 'config');

omnipay/paypal gateways support mutlple gateways

from the package github, it says:
The following gateways are provided by this package:

PayPal_Express (PayPal Express Checkout)
PayPal_ExpressInContext (PayPal Express In-Context Checkout)
PayPal_Pro (PayPal Website Payments Pro)
PayPal_Rest (Paypal Rest API)

So in the payments.php how do I add multiple gateways from this same package?

May I do like this:

'gateways' => [
'PayPal_Express' => [
'driver' => 'PayPal_Express',
'options' => [
'username' => env('PAYPAL_EXPRESS_USERNAME'),
'password' => env('PAYPAL_EXPRESS_PASSWORD'),
'signature' => env('PAYPAL_EXPRESS_SIGNATURE'),
'test_mode' => env('PAYPAL_EXPRESS_TEST_MODE'),
],
],
'PayPal_Rest' => [
'driver' => 'PayPal_Rest',
'options' => [
'client_id' => env('PAYPAL_REST_USERNAME'),
'client_secret' => env('PAYPAL_REST_PASSWORD'),

        ],
    ],

]

不能使用微信支付

发布配置文件的时候出错,微信支付也不能使用,其他没测。
laravel5.5
"Type error: Return value of Overtrue\LaravelPayment\Factory::applyDriverOptions() must be an instance of Overtrue\LaravelPayment\void, none returned"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.