puntodev/paypal
Composer 安装命令:
composer require puntodev/paypal
包简介
PayPal API Client
README 文档
README
A lightweight Laravel package that wraps the PayPal Orders v2 API (create, find and capture orders) and provides classic IPN verification. It uses Laravel's HTTP client under the hood and caches the OAuth2 access token automatically.
Requirements
- PHP
>=8.4 <9.0 - Laravel 13+ (
illuminate/support^13.0)
Installation
Install via composer:
composer require puntodev/paypal
The package auto-registers its service provider and the Paypal facade via Laravel
package discovery. To publish the config file:
php artisan vendor:publish --provider="Puntodev\Payments\PayPalServiceProvider" --tag="config"
Configuration
Set the following environment variables:
PAYPAL_API_CLIENT_ID=your-client-id PAYPAL_API_CLIENT_SECRET=your-client-secret SANDBOX_GATEWAYS=true # true -> sandbox, false -> production
These map to config/paypal.php:
return [ 'client_id' => env('PAYPAL_API_CLIENT_ID'), 'client_secret' => env('PAYPAL_API_CLIENT_SECRET'), 'use_sandbox' => env('SANDBOX_GATEWAYS', false), ];
When use_sandbox is true the client targets api.sandbox.paypal.com and the
sandbox IPN endpoint; otherwise it targets production.
Usage
Resolving the client
Inject the PayPal contract (or use the Paypal facade) and obtain a PayPalApi
instance. Use defaultClient() to use the configured credentials, or
withCredentials() to override them at runtime (e.g. for multi-tenant setups):
use Puntodev\Payments\PayPal; public function __construct(private PayPal $paypal) {} // With the credentials from config/paypal.php $api = $this->paypal->defaultClient(); // Or with per-request credentials (sandbox flag still comes from config) $api = $this->paypal->withCredentials($clientId, $clientSecret);
Building an order
OrderBuilder produces the payload for the Orders v2 API. The order intent is
CAPTURE, items are sent as DIGITAL_GOODS with NO_SHIPPING, and a discount is
only included when greater than zero:
use Puntodev\Payments\OrderBuilder; $order = (new OrderBuilder()) ->externalId('your-internal-id') ->currency('USD') ->amount(23.20) ->discount(2.20) // optional ->description('My custom product') ->brandName('My brand name') ->locale('es-AR') // defaults to es-AR ->returnUrl('https://example.com/return') ->cancelUrl('https://example.com/cancel') ->make();
Creating, finding and capturing orders
$created = $api->createOrder($order); $orderId = $created['id']; // Send the buyer to the "payer-action" link to approve the payment $approveUrl = collect($created['links']) ->firstWhere('rel', 'payer-action')['href']; // Later, fetch or capture the order $order = $api->findOrderById($orderId); $capture = $api->captureOrder($orderId);
All order methods return the decoded JSON response as an array and throw
Illuminate\Http\Client\RequestException on HTTP errors.
Verifying IPN notifications
// In your IPN webhook controller $status = $api->verifyIpn($request->getContent()); // "VERIFIED" or "INVALID" if ($status === 'VERIFIED') { // process the notification }
Testing
composer test # runs PHPUnit composer test-coverage # generates HTML coverage report
Note: the test suite (
tests/PayPalApiTest.php) makes real HTTP calls to the PayPal sandbox. You must provide valid sandbox credentials viaPAYPAL_API_CLIENT_IDandPAYPAL_API_CLIENT_SECRET.phpunit.xml.distforcesSANDBOX_GATEWAYS=true.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Releasing
Releases are cut from GitHub and the changelog is kept in sync automatically:
- Merge the pull requests you want to ship into
master. Label them so the notes group nicely (security,enhancement,bug,dependencies,documentation); grouping is configured in.github/release.yml. - On GitHub, go to Releases → Draft a new release, create a
vX.Y.Ztag following SemVer, and click Generate release notes. - Publish the release. Packagist picks up the new tag, and the
update-changelog.ymlworkflow writes the release notes intoCHANGELOG.mdand commits them back tomaster.
The Unreleased section in the changelog is just an anchor — release notes flow
from the published GitHub release, so there is no changelog to edit by hand.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mariano.goldman@puntodev.com.ar instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
puntodev/paypal 适用场景与选型建议
puntodev/paypal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.03k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 09 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「paypal」 「puntodev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 puntodev/paypal 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 puntodev/paypal 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 puntodev/paypal 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PayPal SDK for ExpressCheckout and AdaptivePayments. Supports recurring payments, simple payments, parallel payments and chained payments.
MercadoPago API Client
Bookable Library
A PayPal IPN (Instant Payment Notification) listener for PHP
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
统计信息
- 总下载量: 7.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-14