Environments

Collection modules are environment agnostic and the same draft and published versions work across both sandbox and live environments. This means that you need to configure and handle different behaviour for the environments within the code itself, for example if speaking to the payment provider’s UAT or production APIs.

An example is when calling the Root SDK or Stripe SDK, you will need to configure the client to use sandbox or production.

Use the configuration service in config.ts to configure the variables for each environment. This is also where you can add any other environment variables you may require.

const production: EnvironmentConfig = {
  ...baseConfig,
  // stripeApiKey: env.STRIPE_SECRET_KEY_LIVE,
  rootApiKey: env.ROOT_API_KEY_LIVE,
  rootBaseUrl: env.ROOT_BASE_URL_LIVE,
};

const sandbox: EnvironmentConfig = {
  ...baseConfig,
  // stripeApiKey: env.STRIPE_SECRET_KEY_TEST,
  rootApiKey: env.ROOT_API_KEY_SANDBOX,
  rootBaseUrl: env.ROOT_BASE_URL_SANDBOX,
};

The configuration service will provide the correct key for the environment, so you don't need to check each time.
Example:

this.stripeSDK = new Stripe(Config.env.stripeApiKey);