Skip to main content

Overview

The Payviox class is the main entry point for the Payviox SDK. It provides methods to create payment sessions, open payment pages, and retrieve available payment methods.

Constructor

new Payviox(token)

Creates a new instance of the Payviox SDK.
const payviox = new Payviox('your_api_token');
Never expose your API token in client-side code in production environments. Consider creating sessions server-side and passing session IDs to the client.

Parameters

ParameterTypeRequiredDescription
tokenstring✅ RequiredYour Payviox API token. Obtain this from your dashboard at dash.payviox.com. Use test tokens (pk_test_...) for development and live tokens (pk_live_...) for production.

Examples

const payviox = new Payviox('pk_test_abc123...');

// Now you can use the SDK methods
await payviox.createSession({...});

Environment-specific tokens

It’s recommended to use different tokens for different environments:
const token = process.env.NODE_ENV === 'production'
  ? process.env.PAYVIOX_LIVE_TOKEN
  : process.env.PAYVIOX_TEST_TOKEN;

const payviox = new Payviox(token);

Available methods

Once instantiated, the Payviox class provides the following methods:
MethodDescriptionLink
createSession()Create a new payment session and optionally redirect or embed an iframeView details
openSession()Manually redirect the user to the payment pageView details
openIframe()Manually open an iframe for a payment sessionView details
getPaymentsMethods()Retrieve available payment methodsView details

Quick start

// 1. Initialize the SDK
const payviox = new Payviox('pk_test_abc123...');

// 2. Get available payment methods
const methods = await payviox.getPaymentsMethods();

// 3. Create a payment session
await payviox.createSession({
  amount: 5000,
  currency: 'USD',
  customer: 'user@example.com',
  description: 'Order payment',
  paymentMethodId: methods[0].id,
  order_id: 'order_' + Date.now(),
  items: [
    { name: 'Product', quantity: 1, price: 5000 }
  ]
}, {
  redirect: true
});