@adyen/api-library
Version:
The Adyen API Library for NodeJS enables you to work with Adyen APIs.
69 lines • 3.25 kB
JavaScript
;
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* Adyen NodeJS API Library
* Copyright (c) 2020 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("./config");
/**
* Base Service class for all API services.
* Handles the setup of the endpoint URL for the API requests.
*/
class Service {
constructor(client) {
this.apiKeyRequired = false;
this.client = client;
}
/**
* Constructs the base URL for API requests based on environment and endpoint type.
* - For non-LIVE environments, replaces '-live' with '-test'.
* - For LIVE environment, requires a liveEndpointUrlPrefix.
* - Handles special cases for 'pal-' and 'checkout-' endpoints.
* @param url - The original endpoint URL.
* @returns The formatted endpoint URL.
* @throws Error if url is not provided or liveEndpointUrlPrefix is missing for LIVE environment.
*/
createBaseUrl(url) {
const config = this.client.config;
if (!url) {
throw new Error("Endpoint URL must be provided.");
}
if (config.environment !== config_1.EnvironmentEnum.LIVE) {
return url.replace("-live", "-test");
}
if (config.environment === config_1.EnvironmentEnum.LIVE) {
if (!(config === null || config === void 0 ? void 0 : config.liveEndpointUrlPrefix)) {
throw new Error("Live endpoint URL prefix must be provided for LIVE environment.");
}
}
if (url.includes("/authe/")) {
return url.replace("https://test.adyen.com/", "https://authe-live.adyen.com/");
}
if (url.includes("pal-")) {
return url.replace("https://pal-test.adyen.com/pal/servlet/", `https://${this.client.config.liveEndpointUrlPrefix}-pal-live.adyenpayments.com/pal/servlet/`);
}
if (url.includes("checkout-")) {
if (url.includes("/possdk/v68")) {
return url.replace("https://checkout-test.adyen.com/", `https://${this.client.config.liveEndpointUrlPrefix}-checkout-live.adyenpayments.com/`);
}
return url.replace("https://checkout-test.adyen.com/", `https://${this.client.config.liveEndpointUrlPrefix}-checkout-live.adyenpayments.com/checkout/`);
}
return url.replace("-test", "-live");
}
}
exports.default = Service;
//# sourceMappingURL=service.js.map