bc-checkout-sdk
Version:
BetterCommerce's Checkout NodeJS SDK enables BC client applications to integrate with Checkout merchant API system. It publishes an interface to interact with [Checkout API](https://api-reference.checkout.com/#operation/getPaymentDetails/) endpoints.
113 lines (112 loc) • 4.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckoutEnvironment = void 0;
const Endpoints_1 = require("../../constants/Endpoints");
/**
* {CheckoutEnvironment} class is used to setup the environment.
* This class provides options to select the environment.
*/
class CheckoutEnvironment {
/**
* Initialize the Checkout client with the given public and secret keys.
* @param publicKey {string} The public key provided by Checkout.
* @param secretKey {string} The secret key provided by Checkout.
* @returns {CheckoutEnvironment} The class instance.
*/
static initClient(publicKey, secretKey) {
CheckoutEnvironment.publicKey = publicKey;
CheckoutEnvironment.secretKey = secretKey;
return this;
}
/**
* Initialize the Checkout client with the given access id, secret, and processing channel id.
* @param accessId {string} The access id provided by Checkout.
* @param accessSecret {string} The access secret provided by Checkout.
* @param procesingChannelId {string} The processing channel id provided by Checkout.
* @param useSandBox {boolean} If true, the client will point to the sandbox environment.
* @param extras {Object} Additional configuration options for the client.
* @returns {CheckoutEnvironment} The class instance.
*/
static initServer(accessId, accessSecret, procesingChannelId, useSandBox = true, extras = {}) {
CheckoutEnvironment.accessId = accessId;
CheckoutEnvironment.accessSecret = accessSecret;
CheckoutEnvironment.procesingChannelId = procesingChannelId;
CheckoutEnvironment.extras = extras;
if (useSandBox) {
CheckoutEnvironment.authUrl = Endpoints_1.Endpoints.Base.Auth.SANDBOX_URL;
CheckoutEnvironment.baseUrl = Endpoints_1.Endpoints.Base.Api.SANDBOX_URL;
CheckoutEnvironment.environment = "sandbox";
}
else {
CheckoutEnvironment.authUrl = Endpoints_1.Endpoints.Base.Auth.PRODUCTION_URL;
CheckoutEnvironment.baseUrl = Endpoints_1.Endpoints.Base.Api.PRODUCTION_URL;
CheckoutEnvironment.environment = "production";
}
return this;
}
/**
* Get the public key provided by Checkout.
* @returns {string} The public key.
*/
static getPublicKey() {
return CheckoutEnvironment.publicKey;
}
/**
* Get the secret key provided by Checkout.
* @returns {string} The secret key.
*/
static getSecretKey() {
return CheckoutEnvironment.secretKey;
}
/**
* Get the access id provided by Checkout.
* @returns {string} The access id.
*/
static getAccessId() {
return CheckoutEnvironment.accessId;
}
/**
* Get the access secret provided by Checkout.
* @returns {string} The access secret.
*/
static getAccessSecret() {
return CheckoutEnvironment.accessSecret;
}
/**
* Get the processing channel ID provided by Checkout.
* @returns {string} The processing channel ID.
*/
static getProcessingChannelId() {
return CheckoutEnvironment.procesingChannelId;
}
/**
* Get any additional configuration options that were passed in the constructor.
* @returns {Object} The additional configuration options.
*/
static getExtras() {
return CheckoutEnvironment.extras;
}
/**
* Get the environment set for the CheckoutEnvironment.
* For example, "sandbox" or "production".
* @returns {string} The environment.
*/
static getEnvironment() {
return CheckoutEnvironment.environment;
}
/**
* Returns the base url of the Checkout authentication service.
* @returns {string} The base url of the Checkout authentication service.
*/
static getAuthUrl() {
return CheckoutEnvironment.authUrl;
}
/**
* Returns the base url of the Checkout API service.
* @returns {string} The base url of the Checkout API service.
*/
static getBaseUrl() {
return CheckoutEnvironment.baseUrl;
}
}
exports.CheckoutEnvironment = CheckoutEnvironment;