• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

srmklive/laravel-paypal: Laravel plugin for processing payments through PayPal. ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

srmklive/laravel-paypal

开源软件地址(OpenSource Url):

https://github.com/srmklive/laravel-paypal

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Laravel PayPal

Software License Latest Version on Packagist Total Downloads StyleCI Tests Coverage Status Code Quality

Documentation

The documentation for the package can be viewed by clicking the following link:

https://srmklive.github.io/laravel-paypal/docs.html

Usage

Following are some ways through which you can access the paypal provider:

// Import the class namespaces first, before using it directly
use Srmklive\PayPal\Services\PayPal as PayPalClient;

$provider = new PayPalClient;

// Through facade. No need to import namespaces
$provider = \PayPal::setProvider();

Configuration File

The configuration file paypal.php is located in the config folder. Following are its contents when published:

return [
    'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
    'sandbox' => [
        'client_id'         => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
        'client_secret'     => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
        'app_id'            => 'APP-80W284485P519543T',
    ],
    'live' => [
        'client_id'         => env('PAYPAL_LIVE_CLIENT_ID', ''),
        'client_secret'     => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
        'app_id'            => env('PAYPAL_LIVE_APP_ID', ''),
    ],

    'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
    'currency'       => env('PAYPAL_CURRENCY', 'USD'),
    'notify_url'     => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application.
    'locale'         => env('PAYPAL_LOCALE', 'en_US'), // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
    'validate_ssl'   => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client.
];

Override PayPal API Configuration

You can override PayPal API configuration by calling setApiCredentials method:

$provider->setApiCredentials($config);

Get Access Token

After setting the PayPal API configuration by calling setApiCredentials method. You need to get access token before performing any API calls

$provider->getAccessToken();

Set Currency

By default, the currency used is USD. If you wish to change it, you may call setCurrency method to set a different currency before calling any respective API methods:

$provider->setCurrency('EUR');

Helper Methods

Please note that in the examples below, the call to addPlanTrialPricing is optional and it can be omitted when you are creating subscriptions without trial period.

setReturnAndCancelUrl() is optional. If you set urls you have to use real domains. e.g. localhost, project.test does not work.

Create Recurring Daily Subscription

$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addPlanTrialPricing('DAY', 7)
            ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

Create Recurring Weekly Subscription

$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addPlanTrialPricing('DAY', 7)
            ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

Create Recurring Monthly Subscription

$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addPlanTrialPricing('DAY', 7)
            ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100)
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

Create Recurring Annual Subscription

$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addPlanTrialPricing('DAY', 7)
            ->addAnnualPlan('Demo Plan', 'Demo Plan', 600)
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

Create Recurring Subscription with Custom Intervals

$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
            ->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3)
            ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
            ->setupSubscription('John Doe', '[email protected]', '2021-12-10');

Create Subscription by Existing Product & Billing Plan

$response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
    ->setupSubscription('John Doe', '[email protected]', $start_date);

Support

This version supports Laravel 6 or greater.

  • In case of any issues, kindly create one on the Issues section.
  • If you would like to contribute:
    • Fork this repository.
    • Implement your features.
    • Generate pull request.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ant-vel/App: Laravel e-commerce Application.发布时间:2022-07-08
下一篇:
dingo/api: A RESTful API package for the Laravel and Lumen frameworks.发布时间:2022-07-08
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap