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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@geekapps/billing-nextjs

v0.7.0

Published

Geekapps Billing SDK for Next.js — create charges server-side and render the hosted checkout/payment page client-side

Readme

@geekapps/billing-nextjs

SDK para Next.js — cria cobranças no servidor e redireciona o usuário para a página de checkout hospedada (billing-dashboard), onde o pagamento acontece de fato.

Server (Server Components / Server Actions / Route Handlers)

// lib/billing.ts — crie uma única instância e reutilize em todo o app
import { GeekappsBilling } from "@geekapps/billing-nextjs";

export const billing = new GeekappsBilling({
  apiUrl: process.env.BILLING_API_URL!,
  token: createServiceAccountToken({ /* ... */ }), // de @geekapps/billing-fastify
  mode: process.env.NODE_ENV === "production" ? "prod" : "dev", // definido uma vez
});
// app/checkout/actions.ts
"use server";
import { billing } from "@/lib/billing";

export async function createCheckout(customerId: string) {
  const charge = await billing.createCharge({
    customer_id: customerId,
    item_id: "...",
    method: "CARD",
  });

  return billing.checkoutUrl(process.env.CHECKOUT_BASE_URL!, charge.checkout_token);
}

Cobrança avulsa simples (sempre cartão)

"use server";
import { billing } from "@/lib/billing";

export async function chargeCustomer(customerId: string) {
  const result = await billing.charge(customerId, 5000); // R$ 50,00, sempre em cartão

  if (result.charged_off_session) {
    // cobrado direto no cartão salvo do cliente — já pode liberar o que for
    return { done: true };
  }

  // cliente ainda não tem cartão salvo: abra checkout_url (nova aba) para ele cadastrar e pagar
  return { done: false, checkoutUrl: result.checkout_url };
}

Assinatura de plano (checkout + confirmação + status)

Fluxo público (cliente final anônimo, ainda sem Customer cadastrado — coleta nome/e-mail no checkout):

"use server";
import { billing } from "@/lib/billing";

export async function subscribeToPlan(planId: string, name: string, email: string) {
  const { checkout_url, checkout_token, management_token } =
    await billing.createPlanCheckout(planId, { name, email });

  // 1. Redirecione o cliente para checkout_url (ou use <CheckoutRedirectButton> no client)
  // 2. Depois do retorno, confirme se realmente foi pago:
  const status = await billing.getPublicCheckoutStatus(checkout_token);

  // 3. Guarde management_token associado ao seu usuário — a qualquer momento depois,
  //    verifique se a assinatura segue ativa e qual item ela cobre:
  const subStatus = await billing.checkSubscriptionStatus(management_token);
  if (subStatus.subscription.active) {
    console.log("cobrando", subStatus.item.name);
  }

  return { checkout_url, status, subStatus };
}

Fluxo simplificado (autenticado, o Customer já existe na sua org — sem formulário de nome/e-mail):

"use server";
import { billing } from "@/lib/billing";

export async function subscribeExistingCustomer(planId: string, customerId: string) {
  const { checkout_url } = await billing.checkoutPlan(planId, customerId);
  // redirecione o cliente para checkout_url; ele paga e volta para sua URL de retorno
  return checkout_url;
}

export async function confirmSubscription(planId: string, customerId: string) {
  const { active, item } = await billing.confirmPlanSubscription(planId, customerId);
  if (active) {
    // ativa o plano real no seu sistema
  }
  return { active, item };
}

Plano avulso (sem página pública)

"use server";
import { billing } from "@/lib/billing";

export async function createStandalonePlan(itemId: string) {
  // plan_page_id omitido — plano fica avulso
  return billing.createPlan({ item_id: itemId, interval: "MONTHLY" });
}

Client (estado de pagamento)

"use client";
import { useCheckoutStatus } from "@geekapps/billing-nextjs/client";

function PaymentStatus({ token, initialStatus }: { token: string; initialStatus: string }) {
  const { status } = useCheckoutStatus({
    apiUrl: process.env.NEXT_PUBLIC_BILLING_API_URL!,
    checkoutToken: token,
    initialStatus,
  });

  return <p>Status: {status}</p>;
}

Assim como no @geekapps/billing-fastify, o mode é definido uma única vez ao criar GeekappsBilling — nenhuma chamada precisa recebê-lo de novo.