Files
english/.opencode/skills/payment-integration/references/paddle/sdk.md
2026-04-12 01:06:31 +07:00

2.6 KiB

Paddle SDKs

Official SDKs for server-side integration.

Node.js

npm install @paddle/paddle-node-sdk
import Paddle from '@paddle/paddle-node-sdk';

const paddle = new Paddle(process.env.PADDLE_API_KEY, {
  environment: 'sandbox' // 'production'
});

// Products
const products = await paddle.products.list();
const product = await paddle.products.create({
  name: 'Pro Plan',
  taxCategory: 'standard'
});

// Prices
const prices = await paddle.prices.list({ productId: 'pro_xxx' });
const price = await paddle.prices.create({
  productId: 'pro_xxx',
  description: 'Monthly',
  unitPrice: { amount: '999', currencyCode: 'USD' },
  billingCycle: { interval: 'month', frequency: 1 }
});

// Transactions
const transaction = await paddle.transactions.create({
  items: [{ priceId: 'pri_xxx', quantity: 1 }]
});

// Subscriptions
const subscription = await paddle.subscriptions.get('sub_xxx');
await paddle.subscriptions.update('sub_xxx', {
  items: [{ priceId: 'pri_new', quantity: 1 }]
});
await paddle.subscriptions.cancel('sub_xxx', { effectiveFrom: 'nextBillingPeriod' });

// Customers
const customers = await paddle.customers.list({ email: 'user@example.com' });

Python

pip install paddle-python-sdk
from paddle_billing import Client, Environment

paddle = Client(
    api_key="your_api_key",
    options=Options(environment=Environment.SANDBOX)
)

# Products
products = paddle.products.list()
product = paddle.products.create(
    name="Pro Plan",
    tax_category="standard"
)

# Subscriptions
subscription = paddle.subscriptions.get("sub_xxx")
paddle.subscriptions.cancel(
    "sub_xxx",
    effective_from="next_billing_period"
)

PHP

composer require paddle/paddle-php-sdk
use Paddle\SDK\Client;

$paddle = new Client('your_api_key');

// Products
$products = $paddle->products->list();

// Subscriptions
$subscription = $paddle->subscriptions->get('sub_xxx');
$paddle->subscriptions->cancel('sub_xxx', [
    'effective_from' => 'next_billing_period'
]);

Go

go get github.com/PaddleHQ/paddle-go-sdk
import paddle "github.com/PaddleHQ/paddle-go-sdk"

client, _ := paddle.New(
    os.Getenv("PADDLE_API_KEY"),
    paddle.WithBaseURL(paddle.SandboxBaseURL),
)

// Products
products, _ := client.ListProducts(ctx, nil)

// Subscriptions
sub, _ := client.GetSubscription(ctx, "sub_xxx")

Error Handling

try {
  await paddle.subscriptions.get('sub_invalid');
} catch (error) {
  if (error.code === 'entity_not_found') {
    console.log('Subscription not found');
  }
}