Vexor.fromEnv()
Initialization from Environment Variables
There are 3 ways to instantiate a Vexor instance:
- Using the
new Vexor()
constructor with publishable key, project id and secret key. - Using the
Vexor.init()
static method. -
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 keyNEXT_PUBLIC_VEXOR_PROJECT
: Your Vexor project IDVEXOR_SECRET_KEY
: Your Vexor secret key (optional, required for webhook handling)
Returns
Returns a new Vexor instance.
Environment Variables
To use Vexor.fromEnv()
, you need to set the following environment variables:
Recommendations
- Create a
.env
file in your project root and add your Vexor environment variables:
- Create a
vexor.ts
file in yourlib
orutils
folder and export the Vexor instance:
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.