From 68c2f9b474b4c9cb855ea79ef37cd5d01a1b2582 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 18 Dec 2024 13:57:28 +0100 Subject: [PATCH 1/2] add configurable timeout for Http Client --- src/Request/HttpsClient.ts | 4 ++-- src/Utils/Types.ts | 1 + src/buckaroo.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index 30bdeab..d883148 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -8,8 +8,8 @@ export default class HttpsClient { protected _options: AxiosRequestConfig = {}; private _axiosInstance: AxiosInstance; - constructor(agent?: Agent) { - this._options.timeout = 10000; + constructor(agent?: Agent, timeout: number = 10000) { + this._options.timeout = timeout; this._options.maxRedirects = 10; this._options.withCredentials = true; diff --git a/src/Utils/Types.ts b/src/Utils/Types.ts index 96ffb76..4881e31 100644 --- a/src/Utils/Types.ts +++ b/src/Utils/Types.ts @@ -11,6 +11,7 @@ export declare interface IConfig { returnURLReject?: string; activePaymentMethods?: ServiceCode[]; disabledPaymentMethods?: ServiceCode[]; + timeout?: number; } export declare interface ICredentials { diff --git a/src/buckaroo.ts b/src/buckaroo.ts index 60f216c..955a7ed 100644 --- a/src/buckaroo.ts +++ b/src/buckaroo.ts @@ -14,7 +14,7 @@ export default class Buckaroo { constructor(credentials: ICredentials, config?: IConfig, agent?: Agent) { this._credentials = new Credentials(credentials.secretKey, credentials.websiteKey); this._config = { ...(config ?? { mode: 'TEST', currency: 'EUR' }) }; - this._httpClient = new HttpsClient(agent); + this._httpClient = new HttpsClient(agent, this._config.timeout); } static get Client(): Buckaroo { From bc613a917bfbe5187a15098fec84cb846f877fa1 Mon Sep 17 00:00:00 2001 From: Vildan Bina Date: Wed, 18 Dec 2024 14:00:22 +0100 Subject: [PATCH 2/2] add configurable timeout for Http Client --- src/Request/HttpsClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Request/HttpsClient.ts b/src/Request/HttpsClient.ts index d883148..212d508 100644 --- a/src/Request/HttpsClient.ts +++ b/src/Request/HttpsClient.ts @@ -8,8 +8,8 @@ export default class HttpsClient { protected _options: AxiosRequestConfig = {}; private _axiosInstance: AxiosInstance; - constructor(agent?: Agent, timeout: number = 10000) { - this._options.timeout = timeout; + constructor(agent?: Agent, timeout?: number) { + this._options.timeout = timeout ?? 10000; this._options.maxRedirects = 10; this._options.withCredentials = true;