Skip to content

docs: Create a guide for seat based pricing #6638

Description

@rishi-raj-jain

Until we ship a fix for #4815, we need to inform users how to make this happen today.
Write a guide covering the following:

With the base code snippets:

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN });

// When a new user is added
async function trackNewUser(customerId: string) {
  // Each event call (like below) represents 1 new user
  await polar.events.ingest({
    events: [
      {
        // note that this field value is equal to the one that was entered in the `name` field in the `Condition` in the meter group
        name: "new-user",
        // Your user ID
        external_customer_id: customerId,
      },
    ],
  });
}

and

// At the start of each billing cycle, check no. of current users
async function billCurrentUsers(customerId: string) {
  const customers = await getNumberOfCustomersFromYourDB(customerId);
  const currentCustomers = customer.length;
    // Send events for each additional workspace
    for (let i = 0; i < currentCustomers; i++) {
      await polar.events.ingest({
        events: [{
          name: "new-user",
          external_customer_id: customerId
        }]
      });
  }
}

Metadata

Metadata

Labels

contentDeveloper & product docs, guides and contentpolar-teamIssues that will be handled by the core Polar teamsupportIssues for our support team, e.g internal tooling, guides etcvotes-neededWe need 👍 to properly prioritize this issue

Type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions