sudiptpa/paypal-rest 问题修复 & 功能扩展

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

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

sudiptpa/paypal-rest

最新稳定版本:v3.1

Composer 安装命令:

composer require sudiptpa/paypal-rest

包简介

PayPal REST API gateway for Omnipay payment processing library.

README 文档

README

PayPal REST API driver for the Omnipay PHP payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP. This package implements PayPal REST API support for Omnipay.

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Installation

Omnipay is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "sudiptpa/paypal-rest": "~3.0"
    }
}

And run composer to update your dependencies:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Usage

The library follows PayPal REST Orders v2 API, and below are the supported features.

Orders API v2

If you want the features other than mentioned above, then feel free to submit a PR by following the coding standard.

Initiate Gateway Request

use Omnipay\Omnipay;

$gateway = Omnipay::create('PayPalRest_Rest');

$gateway->setClientId('xxxxxxxxxxx');
$gateway->setSecret('xxxxxxxxxxx');
$gateway->setTestMode('xxxxxxxxxxx');

Access Token

$accessToken = $gateway->getToken();
 or
$accessToken = $gateway->createToken()->send();

Note, the Access Token is not stored in the gateway at this point.

Management of the Access Token is not (yet) included in this library. You should implement your own method for saving and reusing the Access Token until expired to avoid hitting PayPal query limits by generating a token for each API call.

You can set a previously retrieved Access Token in the gateway as follows:

$gateway->setToken($accessToken);

API Calls

$payload = [
    'amount' => 20,
    'transactionId' => '1001',
    'transactionReference' => 'INV-1001',
    'currency' => 'USD',
    'items' => [
        [
            'name' => 'Test Product 1',
            'description' => 'A sample description',
            'quantity' => 1,
            'price' => 20,
            'sku' => 'ITEM-CODE1',
            'category' => 'PHYSICAL_GOODS',
            'reference' => 'ITEM',
        ]
    ],
    'cancelUrl' => 'https://example.com/cancel/url',
    'returnUrl' => 'https://example.com/return/url',
];

$response = $gateway->purchase($payload)->send();

if ($response && $response->isSuccessful()) {
    // handle the success

    if ($response->isRedirect()) {
        $response->redirect();
    }

    // do something else
}

// handle the failure

Capture

$response = $gateway->completePurchase([
    'transactionReference' => 'PAYPAL-ORDER-ID',
])->send();

if ($response && $response->isSuccessful() && $response->isCaptured()) {
    // handle success
}

// handle failure

Fetch PayPal Order

$response = $gateway->fetchPurchase([
    'transactionReference' => 'PAYPAL-ORDER-ID',
])->send();

if ($response && $response->isSuccessful()) {
    // handle success
}

// handle failure

For general usage instructions, please see the main Omnipay repository.

Support

If you are having general issues with Omnipay, we suggest posting on Stack Overflow. Be sure to add the omnipay tag so it can be easily found.

If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a mailing list which you can subscribe to.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-16