Skip to main content
This example demonstrates a full integration flow: initializing the client, creating a customer, and starting a subscription.

Prerequisites

  • Node.js v14+
  • No SDK required — this example uses the CrediBill HTTP API via server-side requests (App Router)

Full Script (API-first)

// app/api/demo/create-customer/route.ts
import { NextResponse } from "next/server";

export async function POST(request: Request) {
  const body = await request.json();

  // Server-side: call CrediBill API using secret key
  const response = await fetch(
    "https://giant-goldfish-922.convex.site/api/customers",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.CREDIBILL_SECRET_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(body),
    }
  );

  const data = await response.json();

  if (!response.ok) {
    return NextResponse.json({ error: data }, { status: response.status });
  }

  return NextResponse.json(data);
}
Usage (server-side only): POST JSON to /api/demo/create-customer with body: Usage (server-side only): POST JSON to /api/demo/create-customer with body:
{
  "email": "[email protected]",
  "name": "Startup Inc",
  "paymentMethod": "mobile_money_mtn",
  "paymentDetails": { "phoneNumber": "+256772123456" }
}
Notes:
  • Prefer calling the CrediBill API from your server (App Router or serverless functions) so secret keys remain confidential.
  • For frontend data fetching patterns, see the React + TanStack Query examples in other guides.