Unofficial Paddle Billing API SDK for Node.js runtime
See https://developer.paddle.com/api-reference/overview
See https://github.com/PaddleHQ/paddle-node-sdk/
npm i @team-gpt/paddle-billing-sdk
yarn add @team-gpt/paddle-billing-sdk
bun add @team-gpt/paddle-billing-sdk
Axios - https://axios-http.com/
npm i axios
yarn add axios
- Prices
- Products
- Customer
- Discounts
- Addresses
- Businesses
- Transactions
- Subscriptions
- Adjustments
- Event Types
- Events
- Notifications
Create an apikey from the Authentication page in Paddle platform:
PADDLE_AUTH_SECRET=
NEXT_PUBLIC_PADDLE_VENDOR_ID=
NEXT_PUBLIC_PADDLE_SANDBOX=
import { PaddleClient } from '@team-gpt/paddle-billing-sdk'
/**
* @see https://developer.paddle.com/api-reference/overview
*/
export const paddleClient = new PaddleClient({
authToken: process.env.PADDLE_AUTH_SECRET || 'MISSING',
vendorId: Number(process.env.NEXT_PUBLIC_PADDLE_VENDOR_ID),
sandbox: Boolean(process.env.NEXT_PUBLIC_PADDLE_SANDBOX),
})
Usage with Next.js API handlers
// /pages/api/webhooks/paddle-events.ts
import { WebhookEvents, signatureHeader } from 'paddle-billing-sdk'
import { NextApiRequest, NextApiResponse } from 'next'
const webhookSecret = process.env.PADDLE_WEBHOOK_SECRET
export const config = {
api: {
bodyParser: false,
},
}
const handler = async function (req: NextApiRequest, res: NextApiResponse) {
if (req.method !== 'POST') {
res.setHeader('Allow', 'POST')
res.status(405).end('Method Not Allowed')
return
}
if (!req.headers[signatureHeader] || typeof req.headers[signatureHeader] !== 'string') {
res.status(400).end('Invalid signature')
return
}
try {
const sig = req.headers[signatureHeader]
const events = new WebhookEvents(sig, webhookSecret)
const buf = await WebhookEvents.buffer(req)
const event = events.constructEvent(buf)
console.log(event)
} catch (error) {
console.log(error)
if (error instanceof Error) {
res.status(400).json({ error: error.message })
}
}
}
-
Create an account in https://ngrok.com/
-
Expose your local server
ngrok http 3000
-
Add the exposed server to Paddle Notifications at https://sandbox-vendors.paddle.com/notifications
https://xxx-xx-xxx-xxx-xx.ngrok-free.app/api/webhooks/paddle-events
-
Send a request
If you're getting this error while using the client then you need to install axios
as a dependency:
npm i axios
yarn add axios
bun add axios
To extend the default custom data interfaces add the following to your codebase
// Custom interfaces for metadata
declare module '@team-gpt/paddle-billing-sdk' {
export interface PriceMetadata {
myKey: string
}
export interface ProductMetadata {
myKey: string
}
export interface CustomerMetadata {
myKey: string
}
export interface TransactionMetadata {
myKey: string
}
export interface SubscriptionMetadata {
myKey: string
}
}
bun test
MIT