Socket
Book a DemoInstallSign in
Socket

@anitrack/patreon-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anitrack/patreon-wrapper

Universal Patron API v2 wrapper that simplifies their API usage in JavaScript

Source
npmnpm
Version
1.5.1
Version published
Weekly downloads
97
90.2%
Maintainers
1
Weekly downloads
 
Created
Source

Patreon Wrapper 🍊

💎 Simple Patreon wrapper designed best for Discord Bots to process user's patreon subscription and lower down the Patreon API complexity...

🌄 You can also simulates sandbox of fake Patrons for development and code testing purposes

🍊 This package was previously used in AniTrack before switching to a real payment gateway

Table of Contents


Installing

Using NPM

$ npm install @anitrack/patreon-wrapper

Using YARN

$ yarn add @anitrack/patreon-wrapper

Usage Example

Importing

CommonJS

const { Patreon } = require('@anitrack/patreon-wrapper')

Typescript ES6

import { Patreon } from '@anitrack/patreon-wrapper'

Authorization

Where do I find Campaign ID? F12 your Patreon page and search for "campaign" then keep looking until you finds URL with campaign params that contains around 7 degits. That should be your Campaign ID

Patreon.Authorization({
    AccessToken: 'YOUR_API_V2_ACCESS_TOKEN',
    CampaignID: 'YOUR_CAPAIGN_ID',
})

Fetching every Patrons on the Campaign

Promies then catch

Patreon.FetchPatrons(['active_patron', 'declined_patron'])
    .then((Patrons) => {
        // Handle Patrons List
        console.log(Patrons)
    })
    .catch((err) => {
        // Handle Error
        console.log(err)
    })

Async/Await

var Patrons = await Patreon.FetchPatrons(['active_patron', 'declined_patron'])

console.log(Patrons)

Clean Response Example

 // Example response from fetching Patron list
 [
    {
      displayId: '12345678',
      displayName: 'Username',
      emailAddress: 'email@address.com',
      isFollower: false,
      subscription: {
        note: '',
        currentEntitled: {
          status: 'active_patron',
          tier: {
            id: '12345678',
            title: 'My First Tier'
          },
          cents: 500, // 5 USD
          willPayCents: 500,
          lifetimeCents: 1500,
          firstCharge: '2022-01-15 15:00:00.000', // ISO 8601 DATE
          nextCharge: '2022-05-15 15:00:00.000',
          lastCharge: '2022-05-15 15:00:00.000'
        }
      },
      mediaConnection: {
        patreon: {
          id: '12345678',
          url: 'https://www.patreon.com/api/oauth2/v2/user/12345678'
        },
        discord: {
          id: '12345678',
          url: 'https://discordapp.com/users/12345678'
        }
      }
    },
    {
    ...
    },
    {
    ...
    }
]

Sandboxing

This is great for development and working with fake patrons users. The fake patrons object will be exactly the same as real ones!

Importing Sandbox

import { Patreon, Sandbox } from '@anitrack/patreon-wrapper'

Adding Fake Patrons to the Sandbox

You can repeat this as much as you want

Sandbox.AppendPatron({
    displayId: '123', // Patreon ID
    displayName: '123', // Patreon Username
    emailAddress: 'email@address.com', // Patreon Email
    tier: { id: '123', title: 'Tier 1' }, // Current Tier
    cents: 500, // Current paying in cent 500 -> $5.00
    willPayCents: 500, // Next pay price
    lifetimeCents: 1500, // Total lifetime spent
    firstCharge: '2022-01-15 15:00:00.000', // ISO 8601 String date format
    nextCharge: '2022-05-15 15:00:00.000',
    lastCharge: '2022-04-15 15:00:00.000',
    patronStatus: 'active_patron', // Can be 'active_patron' & 'declined_patron'
    mediaConnection: {
        patreon: {
            id: '123',
            url: 'https://www.patreon.com/api/oauth2/v2/user/user_id',
        },
        discord: { id: '123', url: 'https://discord.com/users/user_id' },
    },
})

Viewing Fake Patrons Only

Sandbox.GetFakePatrons()

Viewing Fake Patrons + Real Patrons

Just fetch Patrons normally like you would with real ones

Patreon.FetchPatrons(['active_patron', 'declined_patron'])
    .then((Patrons) => {
        console.dir(Patrons, { depth: null })
    })
    .catch((err) => {
        console.log(err)
    })

License

MIT

Keywords

patreon

FAQs

Package last updated on 16 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts