Repository navigation
Paddle
Typed Paddle Billing API client for Deno, Bun,
Node.js and Cloudflare Workers, as an alternative to @paddle/paddle-node-sdk.
It covers products, prices and discounts, customers and addresses,
transactions with checkout links and invoice PDFs, and subscription changes:
plan changes, cancel, pause, resume, activate and one-time charges. It also
covers refunds and credits, customer portal links, the event log, and
Paddle-Signature webhook verification.
Paddle is a merchant of record: it charges the customer, files the sales tax and VAT, and pays you out. This connect wraps the part of Paddle Billing (API version 1) that a SaaS checkout and its catalogue need.
| Area | Methods |
|---|---|
| Products |
createProduct, getProduct, listProducts, listAllProducts, findProductsByCustomData, updateProduct, archiveProduct, unarchiveProduct
|
| Prices |
createPrice, getPrice, listPrices, listAllPrices, updatePrice
|
| Discounts |
createDiscount, getDiscount, getDiscountByCode, listDiscounts, listAllDiscounts, updateDiscount, archiveDiscount, unarchiveDiscount
|
| Customers |
createCustomer, getCustomer, listCustomers, listAllCustomers, updateCustomer, createAddress, getAddress, listAddresses, updateAddress, createCustomerPortalSession
|
| Transactions |
createTransaction, getTransaction, isPaid, listTransactions, listAllTransactions, updateTransaction, getTransactionInvoice
|
| Subscriptions |
getSubscription, listSubscriptions, listAllSubscriptions, updateSubscription, changePlan, removeScheduledChange, undoScheduledCancellation, cancelSubscription, pauseSubscription, resumeSubscription, activateSubscription, chargeSubscription, getUpdatePaymentMethodTransaction
|
| Adjustments |
createRefund, getRefund, listRefunds, listAllRefunds, createAdjustment, getAdjustment, listAdjustments, listAllAdjustments, getAdjustmentCreditNote
|
| Events |
listEvents, listAllEvents, verifyWebhook (static and instance) |
Three behaviours are deliberate, because getting them wrong costs real money:
-
It defaults to the sandbox.
environmentis'sandbox'unless you set it. The client also refuses apdl_live_…key on a sandbox client and apdl_sdbx_…key on a live one. -
isPaidis true only forpaidandcompleted. Abilledtransaction is an issued invoice, not a payment. -
Amounts are strings in the smallest currency unit.
"1999"is $19.99. A request that sends"19.99"is rejected before it reaches Paddle.
Method names follow @tundraconnect/dodo-payments wherever Paddle has the
same operation (isPaid, createRefund, getDiscountByCode, changePlan,
undoScheduledCancellation, archiveProduct, verifyWebhook, …), so
switching between the two reads the same. Paddle's own nouns stay where its
model differs: a Dodo payment is a Paddle transaction. See
Coming from Dodo Payments.
Every request sends Paddle-Version: 1. Request bodies are checked locally,
and an unknown or misspelt field is rejected rather than silently dropped.
Your tests don't need to fake HTTP. Have your code take a Paddle instance
and pass in a stand-in that returns the shapes from
@tundraconnect/paddle/schemas or throws a real PaddleError:
import { PaddleError } from '@tundraconnect/paddle/errors';
const outage = new PaddleError('SERVICE_UNAVAILABLE', { status: 503 });
console.log(outage.code, outage.transient); // SERVICE_UNAVAILABLE trueTo exercise the client itself against a fake transport, pass a fetch
function in the constructor options. The client sends every request
through it, so the same option fits a proxy, a tracing wrapper or an
SSRF-pinned fetch.
| Topic | Description |
|---|---|
| API | Client configuration and endpoint methods |
| Errors | Error codes and diagnostic metadata |
| Schemas | Public Guardian schemas and inferred types |
Deno:
deno add jsr:@tundraconnect/paddleBun:
bunx jsr add @tundraconnect/paddleNode.js:
npx jsr add @tundraconnect/paddleimport { Paddle } from '@tundraconnect/paddle';
// Sandbox by default. Pass environment: 'live' (and a live key) for real money.
const paddle = new Paddle({
auth: { type: 'BEARER', token: 'pdl_sdbx_apikey_...' },
});
const transaction = await paddle.createTransaction({
items: [{ price_id: 'pri_01', quantity: 1 }],
custom_data: { order_id: 'ord_42' },
});
console.log(transaction.checkout?.url); // send the buyer herecheckout.url uses the default payment link set in your Paddle checkout
settings, and stays null until one is set.
Never trust the browser redirect: the buyer controls it. Check the transaction or act on a verified webhook.
if (await paddle.isPaid(transaction.id)) {
// fulfil order ord_42
}verifyWebhook is static, so a webhook handler needs no API key. Read the
body with text(), never json(): re-serializing changes the bytes and
breaks the signature.
async function handle(req: Request): Promise<Response> {
const event = await Paddle.verifyWebhook({
payload: await req.text(),
headers: req.headers,
secret: 'pdl_ntfset_...', // the notification destination's secret
});
switch (event.event_type) {
case 'transaction.completed':
// event.data is the transaction
break;
case 'subscription.canceled':
// revoke access
break;
}
return new Response(null, { status: 200 });
}The default tolerance is Paddle's own 5 seconds. Pass toleranceSeconds if
your server clock drifts.
// Upgrade: send the COMPLETE new item list, with a proration mode.
await paddle.changePlan('sub_01', {
items: [{ price_id: 'pri_annual', quantity: 1 }],
proration_billing_mode: 'prorated_immediately',
});
// Cancel at the end of the paid period, then change your mind.
await paddle.cancelSubscription('sub_01');
await paddle.undoScheduledCancellation('sub_01');
// Let the customer manage it themselves.
const portal = await paddle.createCustomerPortalSession('ctm_01', {
subscriptionIds: ['sub_01'],
});
console.log(portal.urls.general.overview);const product = await paddle.createProduct({
name: 'Pro plan',
tax_category: 'saas',
});
await paddle.createPrice({
product_id: product.id,
description: 'Pro monthly',
unit_price: { amount: '1500', currency_code: 'USD' },
billing_cycle: { interval: 'month', frequency: 1 },
});
for await (const price of paddle.listAllPrices({ productId: [product.id] })) {
console.log(price.id, price.unit_price.amount);
}const refund = await paddle.createRefund({
transaction_id: 'txn_01',
reason: 'Customer request',
type: 'full',
});
console.log(refund.status); // 'pending_approval' until Paddle reviews itMIT. Part of Tundra Connect, typed vendor API clients for Deno, Bun, Node.js and Cloudflare Workers.
- Affonso
- Algolia
- AviationWeather
- AzureBlob
- Binance
- CloudflareDNS
- CloudflareEmail
- CloudflareKV
- CloudflareSaaS
- CloudflareTurnstile
- CoinGecko
- Deribit
- Discord
- DodoPayments
- EIA
- GCS
- GoogleAnalytics
- GoogleCertificateManager
- GoogleWebRisk
- Kalshi
- ntfy
- OpenExchange
- OpenMeteo
- OpenWeatherMap
- Paddle
- PayPal
- Polymarket
- Pyth
- Razorpay
- Resend
- S3
- SendGrid
- Sentry
- Slack
- Stripe
- Telegram
- Twilio
- UpstashRedis
- URLhaus