paddlehq / paddle-php-sdk
Paddle's PHP SDK for Paddle Billing.
Installs: 25 040
Dependents: 0
Suggesters: 0
Security: 0
Stars: 29
Watchers: 17
Forks: 5
Open Issues: 4
Requires
- php: ^8.1
- ext-json: *
- ext-mbstring: *
- myclabs/php-enum: ^1.8
- php-http/async-client-implementation: ^1.0
- php-http/client-common: ^1.5 || ^2.0
- php-http/discovery: ^1.15
- php-http/httplug: ^1.1 || ^2.0
- php-http/logger-plugin: ^1.3
- php-http/message: ^1.5
- psr/http-factory: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/log: ^1.0 || ^2.0 || ^3.0
- symfony/property-access: ^5.4 || ^6.3 || ^7.0
- symfony/serializer: ^5.4 || ^6.3 || ^7.0
- symfony/uid: ^5.4 || ^6.3 || ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.49
- guzzlehttp/psr7: ^2.6
- monolog/monolog: ^3.5
- php-http/curl-client: ^2.3
- php-http/mock-client: ^1.6
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^9.5 || ^10.0
- rector/rector: dev-main
- symfony/var-dumper: ^6.3
This package is auto-updated.
Last update: 2024-11-25 14:06:01 UTC
README
Paddle Billing is a complete digital product sales and subscription management platform, designed for modern software businesses. It helps you increase your revenue, retain customers, and scale your operations.
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 API reference
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');
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') );