paddlehq/paddle-php-sdk
Composer 安装命令:
composer require paddlehq/paddle-php-sdk
包简介
Paddle's PHP SDK for Paddle Billing.
README 文档
README
Paddle Billing is the developer-first merchant of record, designed for modern SaaS, AI, mobile app, and digital product businesses. We take care of payments, tax, subscriptions, and metrics with one unified API that does it all.
This is a PHP SDK that you can use to integrate Paddle Billing with applications written in PHP.
For working with Paddle in your frontend, use Paddle.js. You can open checkouts, securely collect payment information, build pricing pages, and integrate with Paddle Retain.
Important: This package works with Paddle Billing. It does not support Paddle Classic. To work with Paddle Classic, see: Paddle Classic dev docs
Requirements
PHP 8.1 and later.
Composer
You can install the bindings via Composer. Run the following command:
composer require paddlehq/paddle-php-sdk
To use the bindings, use Composer's autoload:
require_once 'vendor/autoload.php';
Usage
To authenticate, you'll need an API key. You can create and manage API keys in Paddle > Developer tools > Authentication.
Pass your API key while initializing a new Paddle client.
use Paddle\SDK\Client; $paddle = new Client('API_KEY');
You can also pass an environment to work with the sandbox:
use Paddle\SDK\Client; use Paddle\SDK\Environment; use Paddle\SDK\Options; $paddle = new Client( apiKey: 'API_KEY', options: new Options(Environment::SANDBOX), );
Keep in mind that API keys are separate for your sandbox and live accounts, so you'll need to generate keys for each environment.
Examples
List entities
You can list supported entities with the list function in the resource. It returns an iterator to help when working with multiple pages.
use Paddle\SDK\Client; $paddle = new Client('API_KEY'); $products = $paddle->products->list(); // List returns an iterable, so pagination is handled automatically. foreach ($products as $product) { echo $product->id; }
Create an entity
You can create a supported entity with the create function in the resource. It accepts the resource's corresponding Create operation e.g. CreateProduct. The created entity is returned.
use Paddle\SDK\Client; use Paddle\SDK\Entities\Shared\TaxCategory; use Paddle\SDK\Resources\Products\Operations\CreateProduct; $paddle = new Client('API_KEY'); $product = $paddle->products->create( new CreateProduct( name: 'ChatApp Education', taxCategory: TaxCategory::Standard(), ), );
Update an entity
You can update a supported entity with the update function in the resource. It accepts the id of the entity to update and the corresponding Update operation e.g. UpdateProduct. The updated entity is returned.
use Paddle\SDK\Client; use Paddle\SDK\Resources\Products\Operations\UpdateProduct; $paddle = new Client('API_KEY'); $operation = new UpdateProduct( name: 'ChatApp Professional' ); $product = $paddle->products->update('id', $operation);
Where operations require more than one id, the update function accepts multiple arguments. For example, to update an address for a customer, pass the customerId and the addressId:
$address = $paddle->addresses->update( 'customer_id', 'address_id', $operation, );
Get an entity
You can get an entity with the get function in the resource. It accepts the id of the entity to get. The entity is returned.
use Paddle\SDK\Client; $paddle = new Client('API_KEY'); $product = $paddle->products->get('id');
Error Handling
If a request fails, Paddle throws an ApiError exception that contains the same information as errors returned by the API. You can use the errorCode attribute to search an error in the error reference and to handle the error in your app. Validation errors also return an array of errors that tell you which fields failed validation. The retryAfter property will be set for too_many_requests errors.
This example shows how to handle an error with the code conflict:
use Paddle\SDK\Exceptions\ApiError; try { // Call functions from the SDK } catch (ApiError $e) { // $e->errorCode will always follow the error code defined in our documentation if ($e->errorCode === 'conflict') { // Handle Conflict error } }
Resources
Webhook signature verification
The SDK includes a helper class to verify webhook signatures sent by Notifications from Paddle.
use Paddle\SDK\Notifications\Secret; use Paddle\SDK\Notifications\Verifier; (new Verifier())->verify( $request, new Secret('WEBHOOK_SECRET_KEY') );
Learn more
paddlehq/paddle-php-sdk 适用场景与选型建议
paddlehq/paddle-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 345.26k 次下载、GitHub Stars 达 55, 最近一次更新时间为 2024 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sdk」 「paddle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 paddlehq/paddle-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 paddlehq/paddle-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 paddlehq/paddle-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Cashier Register is a simple quota feature usage tracker for Laravel Cashier subscriptions.
Easy user billing for Laravel projects
Integrate Kanuu to your Laravel application
Streamlined E-Commerce Shopping Cart Solution
Alfabank REST API integration
Paddle driver for the Omnipay Laravel Payment processing library
统计信息
- 总下载量: 345.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 56
- 点击次数: 27
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-01-11