shellrent/paypal-restapi-v2-php-sdk
Composer 安装命令:
composer require shellrent/paypal-restapi-v2-php-sdk
包简介
PayPal's PHP SDK for Checkout REST APIs
README 文档
README
To consolidate support across various channels, we have currently turned off the feature of GitHub issues. Please visit https://www.paypal.com/support to submit your request or ask questions within our community forum.
Welcome to PayPal PHP SDK. This repository contains PayPal's PHP SDK and samples for v2/checkout/orders and v2/payments APIs.
This is a part of the next major PayPal SDK. It includes a simplified interface to only provide simple model objects and blueprints for HTTP calls. This repo currently contains functionality for PayPal Checkout APIs which includes Orders V2 and Payments V2.
Please refer to the PayPal Checkout Integration Guide for more information. Also refer to Setup your SDK for additional information about setting up the SDK's.
Latest Updates
Beginning January 2020, PayPal will require an update on the Personal Home Page (PHP) Checkout Software Developer Kit (SDK) to version 1.0.1. Merchants who have not updated their PHP Checkout SDK to version 1.0.1 will not be able to deserialize responses using outdated SDK integrations. All PHP Checkout SDK integrations are expected to be updated by March 1, 2020. Merchants are encouraged to prepare for the update as soon as possible to avoid possible service disruption. The Status Page has been updated with this information. The bulletin can be found here
Prerequisites
PHP 5.6 and above
An environment which supports TLS 1.2 (see the TLS-update site for more information)
Usage
Binaries
It is not mandatory to fork this repository for using the PayPal SDK. You can refer PayPal Checkout Server SDK for configuring and working with SDK without forking this code.
For contributing or referring the samples, You can fork/refer this repository.
Setting up credentials
Get client ID and client secret by going to https://developer.paypal.com/developer/applications and generating a REST API app. Get Client ID and Secret from there.
require __DIR__ . '/vendor/autoload.php'; use PayPalCheckoutSdk\Core\PayPalHttpClient; use PayPalCheckoutSdk\Core\SandboxEnvironment; // Creating an environment $clientId = "<<PAYPAL-CLIENT-ID>>"; $clientSecret = "<<PAYPAL-CLIENT-SECRET>>"; $environment = new SandboxEnvironment($clientId, $clientSecret); $client = new PayPalHttpClient($environment);
Examples
Creating an Order
Code:
// Construct a request object and set desired parameters // Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders use PayPalCheckoutSdk\Orders\OrdersCreateRequest; $request = new OrdersCreateRequest(); $request->prefer('return=representation'); $request->body = [ "intent" => "CAPTURE", "purchase_units" => [[ "reference_id" => "test_ref_id1", "amount" => [ "value" => "100.00", "currency_code" => "USD" ] ]], "application_context" => [ "cancel_url" => "https://example.com/cancel", "return_url" => "https://example.com/return" ] ]; try { // Call API with your client and get a response for your call $response = $client->execute($request); // If call returns body in response, you can get the deserialized version from the result attribute of the response print_r($response); }catch (HttpException $ex) { echo $ex->statusCode; print_r($ex->getMessage()); }
Example Output:
Status Code: 201
Id: 8GB67279RC051624C
Intent: CAPTURE
Gross_amount:
Currency_code: USD
Value: 100.00
Purchase_units:
1:
Amount:
Currency_code: USD
Value: 100.00
Create_time: 2018-08-06T23:34:31Z
Links:
1:
Href: https://api.sandbox.paypal.com/v2/checkout/orders/8GB67279RC051624C
Rel: self
Method: GET
2:
Href: https://www.sandbox.paypal.com/checkoutnow?token=8GB67279RC051624C
Rel: approve
Method: GET
3:
Href: https://api.sandbox.paypal.com/v2/checkout/orders/8GB67279RC051624C/capture
Rel: capture
Method: POST
Status: CREATED
Capturing an Order
Before capture, Order should be approved by the buyer using the approval URL returned in the create order response.
Code to Execute:
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest; // Here, OrdersCaptureRequest() creates a POST request to /v2/checkout/orders // $response->result->id gives the orderId of the order created above $request = new OrdersCaptureRequest("APPROVED-ORDER-ID"); $request->prefer('return=representation'); try { // Call API with your client and get a response for your call $response = $client->execute($request); // If call returns body in response, you can get the deserialized version from the result attribute of the response print_r($response); }catch (HttpException $ex) { echo $ex->statusCode; print_r($ex->getMessage()); }
Example Output:
Status Code: 201
Id: 8GB67279RC051624C
Create_time: 2018-08-06T23:39:11Z
Update_time: 2018-08-06T23:39:11Z
Payer:
Name:
Given_name: test
Surname: buyer
Email_address: test-buyer@paypal.com
Payer_id: KWADC7LXRRWCE
Phone:
Phone_number:
National_number: 408-411-2134
Address:
Country_code: US
Links:
1:
Href: https://api.sandbox.paypal.com/v2/checkout/orders/3L848818A2897925Y
Rel: self
Method: GET
Status: COMPLETED
Running tests
To run integration tests using your client id and secret, clone this repository and run the following command:
$ composer install $ CLIENT_ID=YOUR_SANDBOX_CLIENT_ID CLIENT_SECRET=OUR_SANDBOX_CLIENT_SECRET composer integration
Samples
You can start off by trying out creating and capturing an order
To try out different samples for both create and authorize intent check this link
Note: Update the PayPalClient.php with your sandbox client credentials or pass your client credentials as environment variable while executing the samples.
License
Code released under SDK LICENSE
shellrent/paypal-restapi-v2-php-sdk 适用场景与选型建议
shellrent/paypal-restapi-v2-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 263 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「orders」 「checkout」 「payments」 「sdk」 「paypal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shellrent/paypal-restapi-v2-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shellrent/paypal-restapi-v2-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shellrent/paypal-restapi-v2-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Add Shopify like fulfillments to your Craft Commerce orders.
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Adds a 'checkout' to a SilverStripe site which links to an Estimate and adds the ability to setup and pay
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
A PHP (and Laravel) package to interface with the Snipcart api.
统计信息
- 总下载量: 263
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: https
- 更新时间: 2021-09-22
