Documentation Index Fetch the complete documentation index at: https://mintlify.com/paynow-gg/typescript-sdk/llms.txt
Use this file to discover all available pages before exploring further.
This guide will help you make your first API calls using the PayNow TypeScript SDK. We’ll show you how to use both the storefront and management clients.
Prerequisites
Before you begin, make sure you have:
Node.js 16 or later installed
A PayNow store ID
For management operations: an API key from your PayNow dashboard
Install the SDK
Install the package
Install the SDK using your preferred package manager: npm install @paynow-gg/typescript-sdk
Import the SDK
Import the client creation functions: import { createStorefrontClient , createManagementClient } from "@paynow-gg/typescript-sdk" ;
Using the storefront client
The storefront client is used for customer-facing operations. Here’s how to get started:
Create a storefront client
Initialize the client with your store ID: const storefront = createStorefrontClient ( "411486491630370816" );
The storefront client can optionally accept a customer token as the second parameter for authenticated requests.
Fetch store information
Retrieve your store’s public information: const response = await storefront . store . getStorefrontStore ();
console . log ( response . data );
Work with the cart
Add products to a cart and create a checkout: // Add a product to the cart
await storefront . cart . addLine ({
data: {
productVersionId: "prod_version_123" ,
quantity: 1
}
});
// Get the current cart
const cart = await storefront . cart . getCart ();
console . log ( cart . data );
// Create a checkout session
const checkout = await storefront . cart . createCartCheckout ();
// Redirect user to checkout.data.url
Using the management client
The management client requires an API key and provides access to administrative operations:
Create a management client
Initialize the client with your store ID and API key: const management = createManagementClient (
"411486491630370816" ,
"your-api-key"
);
Never expose your API key in client-side code. Management operations should only be performed server-side.
List orders
Retrieve orders from your store: const response = await management . orders . getOrders ({
params: {
limit: 10 ,
offset: 0
}
});
console . log ( response . data );
Get customer information
Fetch details about a specific customer: const customer = await management . customers . getCustomer ({
path: {
customerId: "cust_123"
}
});
console . log ( customer . data );
Authenticated storefront requests
For operations that require customer authentication, pass a customer token when creating the client:
const authenticatedStorefront = createStorefrontClient (
"411486491630370816" ,
"customer-token-here"
);
// Now you can access customer-specific data
const customer = await authenticatedStorefront . customer . getCustomer ();
console . log ( customer . data );
Error handling
The SDK provides typed error handling with the isPayNowError type guard:
import { isPayNowError } from "@paynow-gg/typescript-sdk" ;
try {
const response = await storefront . store . getStorefrontStore ();
console . log ( response . data );
} catch ( error ) {
if ( isPayNowError ( error )) {
console . error ( `PayNow error: ${ error . response . data . message } ` );
console . error ( `Error code: ${ error . response . data . code } ` );
console . error ( `Status: ${ error . response . data . status } ` );
} else {
console . error ( "Unknown error:" , error );
}
}
Next steps
Installation Learn about advanced configuration options
API reference Explore all available endpoints and methods