Vexor

Vexor.fromEnv()

Initialization from Environment Variables

There are 3 ways to instantiate a Vexor instance:

  1. Using the new Vexor() constructor with publishable key, project id and secret key.
  2. Using the Vexor.init() static method.
  3. Using the Vexor.fromEnv() method to initialize the Vexor instance from environment variables.

The Vexor.fromEnv() method provides a convenient way to create a new Vexor instance using environment variables. It's particularly useful when you want to keep your configuration separate from your code and easily switch between different environments (e.g., development, staging, production).

StaticVexor.fromEnv()

Vexor.fromEnv()

Initialize a new Vexor instance using environment variables.

Parameters

This method doesn't take any parameters. It reads the following environment variables:

  • NEXT_PUBLIC_VEXOR_PUBLISHABLE_KEY: Your Vexor publishable key
  • NEXT_PUBLIC_VEXOR_PROJECT: Your Vexor project ID
  • VEXOR_SECRET_KEY: Your Vexor secret key (optional, required for webhook handling)

Returns

Returns a new Vexor instance.

import { Vexor } from 'vexor';
 
export const vexor = Vexor.fromEnv();

Environment Variables

To use Vexor.fromEnv(), you need to set the following environment variables:

NEXT_PUBLIC_VEXOR_PUBLISHABLE_KEY=pk_test_1234567890
NEXT_PUBLIC_VEXOR_PROJECT=proj_0987654321
VEXOR_SECRET_KEY=sk_test_1234567890

Recommendations

  1. Create a .env file in your project root and add your Vexor environment variables:
NEXT_PUBLIC_VEXOR_PUBLISHABLE_KEY=pk_test_1234567890
NEXT_PUBLIC_VEXOR_PROJECT=proj_0987654321
VEXOR_SECRET_KEY=sk_test_1234567890
  1. Create a vexor.ts file in your lib or utils folder and export the Vexor instance:
import { Vexor } from 'vexor';
 
export const vexor = Vexor.fromEnv();

This approach allows you to use the Vexor instance across your app without explicitly passing configuration parameters.

The Vexor.fromEnv() method uses a singleton pattern, ensuring that only one instance of Vexor is created and reused throughout your application.

On this page