Copy
async createSession(
sessionParameters: SessionParameters,
parameters?: PayvioxParameters
): Promise<void | string>
Parameters
Object containing payment session details.
Show SessionParameters properties
Show SessionParameters properties
Payment amount in the smallest currency unit (cents for USD).
Copy
amount: 5000 // $50.00
Minimum amount is typically 100 ($1.00). Check your currency’s requirements.
Three-letter ISO currency code.
Copy
currency: 'USD' // or 'EUR', 'GBP', etc.
Customer identifier. Can be an email, customer ID, or any unique identifier.
Copy
customer: 'customer_abc123'
// or
customer: 'user@example.com'
Human-readable description of the payment.
Copy
description: 'Premium subscription - Monthly'
Payment method identifier. Use
'pm_card' for card payments.Copy
paymentMethodId: 'pm_card'
Use
getPaymentsMethods() to discover available payment method IDs.Unique identifier for this order. Must be unique across all your transactions.
Copy
order_id: 'order_2024_001'
// or generate dynamically
order_id: 'order_' + Date.now()
Array of items being purchased.
Copy
items: [
{
name: 'Product A',
quantity: 2,
price: 2500 // Prix unitaire en centimes
},
{
name: 'Product B',
quantity: 1,
price: 5000
}
]
Optional configuration for integration mode and behavior.
Show PayvioxParameters properties
Show PayvioxParameters properties
If
true, automatically redirects to the payment page.Copy
{ redirect: true }
Cannot be used simultaneously with
iframeMode: true.If
true, embeds the payment form in an iframe.Copy
{ iframeMode: true }
Requires
iframeConfig to be set when enabled.Configuration for iframe mode. Required when
iframeMode is true.Show IframeConfig properties
Show IframeConfig properties
DOM element where the iframe will be inserted.
Copy
iframeTarget: document.getElementById('payment-container')
Width of the iframe. Any valid CSS width value.
Copy
width: '500px' // or '100%', '80vw', etc.
Height of the iframe. Any valid CSS height value.
Copy
height: '600px' // or '100vh', '80%', etc.
Remove iframe border for seamless integration.
Copy
withoutBorder: true
Make iframe background transparent.
Copy
transparentBackground: true
Additional CSS styles to apply to the iframe.
Copy
style: 'border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'
Return value
Returns a Promise that resolves to:
voidwhen usingredirect: true(page redirects before returning)string(session ID) in all other cases
Copy
// 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
Copy
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
Copy
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);
}
}