Skip to main content
Creates a new payment session and optionally redirects or embeds an iframe.
async createSession(
  sessionParameters: SessionParameters,
  parameters?: PayvioxParameters
): Promise<void | string>

Parameters

sessionParameters
SessionParameters
required
Object containing payment session details.
parameters
PayvioxParameters
Optional configuration for integration mode and behavior.

Return value

return
Promise<void | string>
Returns a Promise that resolves to:
  • void when using redirect: true (page redirects before returning)
  • string (session ID) in all other cases
// With redirect
await payviox.createSession(params, { redirect: true });
// Page redirects immediately

// Without redirect
const sessionId = await payviox.createSession(params);
console.log('Session ID:', sessionId);

Examples

const payviox = new Payviox('your_api_token');

await payviox.createSession({
  amount: 5000,
  currency: 'USD',
  customer: 'user@example.com',
  description: 'Premium Plan',
  paymentMethodId: 'pm_card',
  order_id: 'order_' + Date.now(),
  items: [
    { name: 'Premium Plan', quantity: 1, price: 5000 }
  ]
}, {
  redirect: true
});

Error handling

try {
  const sessionId = await payviox.createSession(sessionParams);
  console.log('Success:', sessionId);
} catch (error) {
  if (error.message.includes('Unauthorized')) {
    console.error('Invalid API token');
  } else if (error.message.includes('Bad request')) {
    console.error('Invalid parameters:', error.message);
  } else {
    console.error('Payment error:', error.message);
  }
}