> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payviox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# openSession()

> Redirect the customer to the payment page for a given session ID. Key method of the recommended integration: your backend creates the session, the SDK opens it

Redirects the customer to the payment page for a given session ID.

```typescript theme={null}
openSession(sessionId: string): void
```

<Note>
  This is the method behind the [recommended integration](/quickstart/integration-methods): your backend creates the session with your secret key, and the SDK opens it in the browser. The session ID can come from anywhere — a `createSession()` call, or your own API.
</Note>

## Parameters

<ParamField path="sessionId" type="string" required>
  The session ID to open. Returned by [`POST /session`](/api/endpoints/create-session) or by [`createSession()`](/sdk/api-reference/create-session).

  ```javascript theme={null}
  payviox.openSession('ses_abc123...');
  ```
</ParamField>

## Examples

### Recommended: session created by your backend

```javascript theme={null}
const payviox = new Payviox('pk_live_your_key');

// Your backend computes the amount and calls POST /session with your secret key
const { session_id } = await fetch('/api/checkout', { method: 'POST' }).then((r) => r.json());

payviox.openSession(session_id);
```

### Session created by the SDK

```javascript theme={null}
const payviox = new Payviox('pk_live_your_key');

const sessionId = await payviox.createSession({
  amount: 5000,
  currency: 'USD',
  customer: 'user@example.com',
  description: 'Order payment',
  order_id: 'order_123',
  items: [{ name: 'Product', quantity: 1, price: 5000 }]
});

// Perform other actions...
console.log('Session ready:', sessionId);

// Redirect when ready
payviox.openSession(sessionId);
```

<Tip>
  Use this method whenever you need to do something between session creation and redirection — or when the session wasn't created in the browser at all.
</Tip>
