Skip to main content
This guide covers everything you need to know about installing and configuring the PayNow TypeScript SDK in your project.

Requirements

The SDK requires:
  • Node.js 16 or later
  • TypeScript 4.5 or later (for TypeScript projects)

Package installation

Install the SDK using your preferred package manager:
npm install @paynow-gg/typescript-sdk
The package includes TypeScript type definitions, so no additional @types package is needed.

Importing the SDK

The SDK exports two main functions for creating API clients:
import { createStorefrontClient, createManagementClient } from "@paynow-gg/typescript-sdk";

Available exports

The SDK provides the following exports:
ExportDescription
createStorefrontClientCreates a client for storefront operations
createManagementClientCreates a client for management operations
isPayNowErrorType guard for PayNowError instances
ManagementSchemasTypeScript types for management API schemas
StorefrontSchemasTypeScript types for storefront API schemas
WebhookPayloadSchemasTypeScript types for webhook payloads

Basic setup

Storefront client

Create a storefront client with just your store ID:
import { createStorefrontClient } from "@paynow-gg/typescript-sdk";

const storefront = createStorefrontClient("411486491630370816");
For authenticated customer requests, pass a customer token:
const authenticatedStorefront = createStorefrontClient(
  "411486491630370816",
  "customer-token-here"
);

Management client

Create a management client with your store ID and API key:
import { createManagementClient } from "@paynow-gg/typescript-sdk";

const management = createManagementClient(
  "411486491630370816",
  "your-api-key"
);
Keep your API key secure and never expose it in client-side code. Management clients should only be used in server-side environments.

Advanced configuration

Both client creation functions accept an optional configuration object as their last parameter. This object follows the Axios CreateAxiosDefaults interface, allowing you to customize the HTTP client behavior.

Custom timeout

Set a custom timeout for API requests:
const storefront = createStorefrontClient(
  "411486491630370816",
  undefined,
  {
    timeout: 10000 // 10 seconds
  }
);

Custom headers

Add custom headers to all requests:
const management = createManagementClient(
  "411486491630370816",
  "your-api-key",
  {
    headers: {
      "X-Custom-Header": "custom-value"
    }
  }
);

Base URL override

Override the default API base URL (useful for testing):
const storefront = createStorefrontClient(
  "411486491630370816",
  undefined,
  {
    baseURL: "https://api.staging.paynow.gg"
  }
);
The default base URL is https://api.paynow.gg. You typically don’t need to override this unless you’re testing against a staging environment.

Request interceptors

While the SDK doesn’t directly expose the Axios instance, you can configure interceptors through the options:
import axios from "axios";

const customInstance = axios.create({
  baseURL: "https://api.paynow.gg"
});

// Add request interceptor
customInstance.interceptors.request.use((config) => {
  console.log("Making request to:", config.url);
  return config;
});

// Note: For advanced use cases, you may need to create a custom wrapper

TypeScript configuration

For optimal TypeScript support, ensure your tsconfig.json includes:
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true
  }
}

Using type definitions

The SDK exports TypeScript types for all API schemas:
import type { 
  StorefrontSchemas, 
  ManagementSchemas,
  WebhookPayloadSchemas 
} from "@paynow-gg/typescript-sdk";

// Access specific schema types
type Store = StorefrontSchemas["Store"];
type Order = ManagementSchemas["Order"];
type OrderCreatedWebhook = WebhookPayloadSchemas["Order_Created"];
These types are automatically generated from the PayNow OpenAPI specifications, ensuring they’re always accurate and up-to-date.

Environment variables

For better security and configuration management, store your credentials in environment variables:
const storeId = process.env.PAYNOW_STORE_ID;
const apiKey = process.env.PAYNOW_API_KEY;

if (!storeId || !apiKey) {
  throw new Error("Missing PayNow credentials");
}

const management = createManagementClient(storeId, apiKey);

Next steps

Quickstart

Make your first API calls with the SDK

API reference

Explore all available endpoints and methods

Build docs developers (and LLMs) love