npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@team-gpt/paddle-billing-sdk

v0.0.20

Published

Paddle Billing SDK for Node

Downloads

33

Readme

Paddle Billing SDK

Unofficial Paddle Billing API SDK for Node.js runtime

See https://developer.paddle.com/api-reference/overview

Getting Started

Setup

npm i @team-gpt/paddle-billing-sdk
yarn add @team-gpt/paddle-billing-sdk
bun add @team-gpt/paddle-billing-sdk

Peer dependencies

Axios - https://axios-http.com/

npm i axios
yarn add axios

Endpoints

  • [x] Prices
  • [x] Products
  • [x] Customer
  • [ ] Discounts
  • [ ] Addresses
  • [ ] Businesses
  • [x] Transactions
  • [x] Subscriptions
  • [ ] Adjustments
  • [ ] Event Types
  • [ ] Events
  • [ ] Notifications

Usage

Authentication

Create an apikey from the Authentication page in Paddle platform:

PADDLE_AUTH_SECRET=
NEXT_PUBLIC_PADDLE_VENDOR_ID=
NEXT_PUBLIC_PADDLE_SANDBOX=

Paddle Client

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),
})

Webhooks

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 authSecret = process.env.PADDLE_AUTH_SECRET
const webhookSecret = process.env.PADDLE_WEBHOOK_SECRET

if (!authSecret) throw new Error('No Paddle auth secret set!')

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 })
    }
  }
}

Receive webhooks

  1. Create an account in https://ngrok.com/

  2. Expose your local server

    ngrok http 3000
  3. 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
  4. Send a request

Extend custom data

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
  }
}

Testing

bun test

License

MIT