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

@fastaar/nextjs

v0.1.2

Published

Next.js React Server Components & Route Handlers integration for Fastaar payment gateway

Readme

Fastaar Next.js integration

Accept bKash & Nagad payments in your Next.js application using Fastaar.

This package is optimized for the Next.js App Router, featuring full support for React Server Components (RSC), Server Actions, and Next.js Route Handlers for webhook signature verification. Written entirely in TypeScript.

Features

  • React Server Components: <CheckoutButton> for instant checkout forms.
  • Server Actions: Clean integration with server redirects.
  • Route Handlers Webhook Helper: Automatically reads, verifies, and parses incoming webhooks.
  • Client Caching: Singleton instance caching to prevent multiple instances during fast-refresh in development.
  • Full TypeScript Support: Auto-complete and strict types for payments, config, and webhooks.

Install

Install the package and its peer dependencies (if not already installed):

npm install @fastaar/nextjs

Configuration

Set the following environment variables in your .env.local or hosting provider:

# Required: Your Fastaar Live/Test API key
FASTAAR_API_KEY="fk_live_..."

# Optional: Your Webhook secret for signature verification
FASTAAR_WEBHOOK_SECRET="whsec_..."

Usage

1. Simple Checkout Button (Server Component)

Use the built-in <CheckoutButton> React Server Component. It renders a HTML form that invokes a Server Action to create the payment intent and automatically redirects the customer.

import { CheckoutButton } from '@fastaar/nextjs';

export default function CheckoutPage() {
  return (
    <main style={{ padding: '2rem' }}>
      <h1>Complete your purchase</h1>
      <p>Amount: 1,250 BDT</p>
      
      <CheckoutButton
        paymentParams={{
          amount: 1250,
          invoice_number: 'ORDER-42',
          success_url: 'https://your-site.com/thanks',
          cancel_url: 'https://your-site.com/cart',
          metadata: { userId: 'usr_1001' },
        }}
        className="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700"
      >
        Pay with bKash / Nagad
      </CheckoutButton>
    </main>
  );
}

2. Custom Flow (Server Actions)

If you need to perform additional server-side operations (like saving the order in your database as "pending" before redirecting), use getFastaarClient in your own Server Action:

import { getFastaarClient } from '@fastaar/nextjs';
import { redirect } from 'next/navigation';

export default function CheckoutPage() {
  async function handleCheckout() {
    'use server';

    // 1. Create order in your database
    // const order = await db.order.create(...);

    // 2. Initialize Fastaar client and create payment
    const fastaar = getFastaarClient();
    const payment = await fastaar.createPayment({
      amount: 1250,
      invoice_number: 'ORDER-42',
      success_url: 'https://your-site.com/thanks',
      cancel_url: 'https://your-site.com/cart',
    });

    // 3. Redirect to checkout page
    redirect(payment.checkout_url);
  }

  return (
    <form action={handleCheckout}>
      <button type="submit">Pay Now</button>
    </form>
  );
}

3. Webhook Route Handler (Next.js App Router)

Handle payment status notifications securely using Next.js Route Handlers. The verifyNextWebhook helper handles raw stream reading and signature verification using your FASTAAR_WEBHOOK_SECRET.

Create a file at app/api/webhooks/fastaar/route.ts:

import { verifyNextWebhook } from '@fastaar/nextjs';
import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const { isValid, event } = await verifyNextWebhook(req);

  if (!isValid || !event) {
    return new NextResponse('Invalid signature', { status: 400 });
  }

  // Handle the webhook event
  if (event.event === 'payment.completed') {
    const payment = event.data;
    const invoiceNumber = payment.invoice_number;       // your order reference, e.g. 'ORDER-42'
    const trxId = payment.customer_trx_id;             // operator transaction ID

    // Mark order as paid in database idempotently
    // await db.order.update({ where: { id: invoiceNumber }, data: { paid: true, trxId } });
    
    console.log(`Payment completed for invoice ${invoiceNumber}`);
  }

  return new NextResponse('OK', { status: 200 });
}

4. Fetching Payment Details

To manually fetch details for a payment:

import { getFastaarClient } from '@fastaar/nextjs';

const fastaar = getFastaarClient();

// Get by Fastaar payment ID
const payment = await fastaar.getPayment('01jxyz...');

// Look up by your own order reference
const payment = await fastaar.findByInvoiceNumber('ORDER-42');

// List payments
const payments = await fastaar.listPayments({ status: 'completed', per_page: 10 });

5. Refund a Payment

Refund a completed payment. Only payments with status completed can be refunded. A payment.refunded webhook fires automatically.

import { getFastaarClient } from '@fastaar/nextjs';

const fastaar = getFastaarClient();
const payment = await fastaar.refundPayment('01jxyz...');
// payment.status === 'refunded'

6. Customers

Store customer records to attach them to payments collected via payment links.

import { getFastaarClient } from '@fastaar/nextjs';

const fastaar = getFastaarClient();

// Create a customer — name and phone are required
const customer = await fastaar.createCustomer({
  name:    'Rahim Uddin',
  phone:   '01712345678',
  email:   '[email protected]',   // optional
  address: 'Dhaka, Bangladesh',   // optional
  notes:   'VIP customer',        // optional
});

// Retrieve, update, list
const fetched   = await fastaar.getCustomer(customer.id);
const updated   = await fastaar.updateCustomer(customer.id, { name: 'Rahim Ahmed' });
const customers = await fastaar.listCustomers({ email: '[email protected]' });

License

MIT