artwl/laravel-paypal 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

artwl/laravel-paypal

Composer 安装命令:

composer require artwl/laravel-paypal

包简介

Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.

README 文档

README

This plugin only supports Laravel 5.1 to 5.8.

Introduction

By using this plugin you can process or refund payments and handle IPN (Instant Payment Notification) from PayPal in your Laravel application.

This plugin supports the new paypal rest api.

This package uses the new paypal rest api. Refer to this link on how to create API credentials:

https://developer.paypal.com/docs/api/overview/

Installation

1. Install:

composer require artwl/laravel-paypal:~4.0

2. [Optional] Add the service provider in config/app.php:

Srmklive\PayPal\Providers\PayPalServiceProvider::class

3. [Optional] Add the alias in config/app.php:

'PayPal' => Srmklive\PayPal\Facades\PayPal::class

4. Publish configuration:

php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"

Configuration

  • After installation, you will need to add your paypal settings. Following is the code you will find in config/paypal.php, which you should update accordingly.
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'            => '',
    ],

    '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.
];
  • Add this to .env
#PayPal API Mode

# Values: sandbox or live (Default: live)
PAYPAL_MODE=live

#PayPal Setting & API Credentials - sandbox
PAYPAL_SANDBOX_CLIENT_ID=
PAYPAL_SANDBOX_CLIENT_SECRET=

#PayPal Setting & API Credentials - live
PAYPAL_LIVE_CLIENT_ID=
PAYPAL_LIVE_CLIENT_SECRET=

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;


public function orderCreate(){
    $provider = new PayPalClient;
    $provider->setApiCredentials(config('paypal'));
    $provider->getAccessToken();
    
    $orderResponse = $provider->createOrder([
        "intent"=> "CAPTURE",
        "purchase_units"=> [
            0 => [
                "amount"=> [
                    "currency_code"=> "HKD",
                    "value"=> "12.00"
                ]
            ]
        ]
    ]);
    
    //order create success
    if ($orderResponse["status"] == "CREATED") {
        $orderId = $orderResponse["id"];
    }
}


//notify_url and webhook url, route need except csrf
public function payResult(Request $request) {
    $data = json_decode($request->getContent(), true);
    //pay success
    if ($data["event_type"] == "CHECKOUT.ORDER.APPROVED") {
        $orderId = $data["resource"]["id"];
    }
}

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 335
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固