FloPay
Getting started

Node.js Quick Start

Create checkout sessions and handle webhooks with the FloPay server SDK.

Node.js Quick Start

The @flopay/node package provides server-side operations: creating checkout sessions, verifying webhooks, and managing customers.

Initialize

import { FloPay } from '@flopay/node';
 
const flopay = new FloPay('sk_test_your_secret_key');

Create a Checkout Session

const result = await flopay.checkout.sessions.create({
  billingApiUrl: 'https://billing.example.com',
  checkoutBaseUrl: 'https://checkout.example.com',
  clientId: 'client_123',
  items: [
    {
      providerItemId: 'prod_abc',
      providerItemName: 'Pro Plan',
      totalAmount: 49.99,
      overrideAmount: 24.99,
      currency: 'USD',
    },
  ],
  account: {
    userId: 'user_1',
    email: 'user@example.com',
    firstName: 'Jane',
    lastName: 'Doe',
  },
  successUrl: 'https://example.com/success',
  cancelUrl: 'https://example.com/cancel',
});
 
// result.status === 201 means a session was created
// result.redirectUrl contains the checkout URL

Subscriptions

Pass subscriptions instead of (or alongside) items:

const result = await flopay.checkout.sessions.create({
  billingApiUrl: 'https://billing.example.com',
  checkoutBaseUrl: 'https://checkout.example.com',
  clientId: 'client_123',
  subscriptions: [
    {
      providerPlanId: 'plan_monthly',
      providerPlanName: 'Monthly Pro',
      totalAmount: 9.99,
      currency: 'USD',
    },
  ],
  account: {
    userId: 'user_1',
    email: 'user@example.com',
  },
  successUrl: '/success',
  cancelUrl: '/cancel',
});

Verify Webhooks

const event = flopay.webhooks.constructEvent(
  requestBody,    // raw body string or Buffer
  signatureHeader, // Stripe-Signature header
  webhookSecret,   // whsec_...
);
 
switch (event.type) {
  case 'checkout.session.completed':
    // handle completion
    break;
}

The FloPay Node constructor requires a Stripe secret key. It initializes a Stripe client internally with the flopay-node app identifier.

API Overview

NamespaceMethods
flopay.checkout.sessionscreate, retrieve, expire, listLineItems
flopay.webhooksconstructEvent
flopay.customerscreate, retrieve, update

Next Steps

On this page