Skip to main content
Loops provides a simple and powerful API for creating checkout sessions. This documentation covers the TypeScript SDK that makes it easy to integrate with the Loops API. Key Features
Our SDK is built with TypeScript first, providing excellent developer experience with full type safety and IntelliSense support.
npm add @loops-fi/sdk
import { Loops } from "@loops-fi/sdk";

const loops = new Loops({
  apiKey: process.env["LOOPS_API_KEY"] ?? "",
});
Create checkout sessions with a single API call. Perfect for integrating payments into your application.
const result = await loops.checkoutSessions.create({
  paymentLinkId: "<id>",
});
Built with developers in mind - comprehensive error handling, retry mechanisms, and detailed documentation.

Quickstart

1. Install the SDK

npm add @loops-fi/sdk

2. Initialize the Client

import { Loops } from "@loops-fi/sdk";

const loops = new Loops({
  apiKey: process.env["LOOPS_API_KEY"] ?? "",
});

3. Create a Checkout Session

async function createCheckoutSession() {
  try {
    const result = await loops.checkoutSessions.create({
      paymentLinkId: "<your-payment-link-id>",
      externalCustomerId: "customer-123", // optional
      metadata: {
        // optional
        orderId: "order-456",
        source: "website",
      },
    });

    console.log("Checkout session created:", result);
    // Redirect user to result.url to complete checkout
  } catch (error) {
    console.error("Error creating checkout session:", error);
  }
}

Authentication

The SDK uses API Key authentication. Set your API key when initializing the client:
const loops = new Loops({
  apiKey: process.env["LOOPS_API_KEY"] ?? "",
});

API Reference

The SDK provides access to the following API endpoint:
  • POST /api/v1/checkout/sessions - Create a new checkout session
For detailed API documentation, see the API Reference section.

Error Handling

The SDK includes comprehensive error handling with specific error types for different scenarios:
import * as errors from "@loops-fi/sdk/models/errors";

try {
  const result = await loops.checkoutSessions.create({
    paymentLinkId: "<id>",
  });
} catch (error) {
  if (error instanceof errors.BadRequestError) {
    console.log("Bad request:", error.data$.error);
  } else if (error instanceof errors.UnauthorizedError) {
    console.log("Unauthorized - check your API key");
  } else if (error instanceof errors.LoopsError) {
    console.log("API error:", error.message);
  }
}

More Documentation

For comprehensive SDK documentation, examples, and advanced usage, please refer to:

Next Steps

I