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

@invertase/node-paddle-sdk

v0.3.3

Published

A fully typed NodeJS library for integration with Paddle.

Downloads

389

Readme

Node Paddle SDK

A NodeJS library for integrating with Paddle.

The library provides full TypeScript definitions for the Paddle API & Webhook events.

Installation

npm install @invertase/node-paddle-sdk --save

Usage

import { PaddleSDK } from '@invertase/node-paddle-sdk';

const paddle = new PaddleSDK(
  12345, // Required: Vendor ID
  'xxxx', // Required: Vendor Auth Code
  'xxxx', // Optional: Public Key
);

The Public Key is optional, but required if using the verifyWebhook method.

API

The library provides integration with the Paddle API endpoints.

The vendor_id and vendor_auth_code parameters are not required and are automatically provided by the library.

Example usage:

try {
  const coupons = await paddle.listCoupons({
    product_id: 123,
  });
} catch (e) {
  console.error(e.code, e.message);
}

Product API

Coupons

Products

Licenses

Pay Links

Transactions

Payments

Subscription API

Plans

Users

Modifiers

Payments

One-off Charges

Alert API

Webhooks

Webhooks

The library provides useful helpers for handling Webhooks, along with type definitions for events for TypeScript users.

Verifying a webhook

To verify a webhook, you must have provided a public key whilst creating a PaddleSDK instance otherwise an error will be thrown. If the provided body does not conform to a Paddle Webhook request (JSON response containing both a alert_name and p_signature), an error will also be thrown.

Pass the request body to the verifyWebhook method to verify the signature:

// Express example

// Ensure you accept a JSON request body.
app.use(express.json());

app.post('/your-webhook-endpoint', (req, res) => {
  const verified = paddle.verifyWebhook(req.body);

  if (!verified) {
    return res.status(403).send('Invalid webhook request.');
  }

  ...
});

TypeScript

The library provides type definitions for the various Paddle Webhook events. Using the alert_name, you can discover the type of the event:

import { PaddleWebhook } from '@invertase/node-paddle-sdk';

app.post('/your-webhook-endpoint', (req, res) => {
  const verified = paddle.verifyWebhook(req.body);

  if (!verified) {
    return res.status(403).send('Invalid webhook request.');
  }

  const event = req.body as PaddleWebhook;

  if (event.alert_name === 'subscription_created') {
    // `event` is now cast as a `SubscriptionCreatedWebhook`
    console.log(event.subscription_id);
  }
});

Sandbox Environment

If using the Paddle Sandbox Environment, you can set the library to use a custom server endpoint:

import { PaddleSDK } from '@invertase/node-paddle-sdk';

const paddle = new PaddleSDK(
  12345, // Required: Vendor ID
  'xxxx', // Required: Vendor Auth Code
  'xxxx', // Optional: Public Key
  'https://sandbox-vendors.paddle.com/api/2.0', // Optional: Custom Server Endpoint
);

License