diff --git a/src/index.ts b/src/index.ts index 41bd23d7..7983c8be 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { payPayRestSDK } from "./lib/paypay-rest-sdk"; +import { payPayRestSDK, PayPayRestSDK } from "./lib/paypay-rest-sdk"; export = { Configure: payPayRestSDK.configure, @@ -29,4 +29,5 @@ export = { CheckCashBackDetails: payPayRestSDK.getCashBackDetails, ReversalCashBack: payPayRestSDK.reverseCashBack, CheckCashBackReversalDetails: payPayRestSDK.getReverseCashBackDetails, + PayPayRestSDK }; \ No newline at end of file diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 959c64bb..40fd349f 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -4,7 +4,7 @@ * Right now, we don't have any such checks, this is a dummy file */ -class Auth { +export class Auth { clientId: string; clientSecret: string; merchantId?: string; @@ -28,5 +28,3 @@ class Auth { this.merchantId = merchantId; } } - -export let auth = new Auth(); diff --git a/src/lib/paypay-rest-sdk.ts b/src/lib/paypay-rest-sdk.ts index 77fc9fd4..3ef89e87 100644 --- a/src/lib/paypay-rest-sdk.ts +++ b/src/lib/paypay-rest-sdk.ts @@ -1,7 +1,7 @@ /* * Main file, methods that are exposed to end-user */ -import { auth } from "./auth"; +import { Auth } from "./auth"; import { Conf } from "./conf"; import { httpsClient } from "./httpsClient"; import { HmacSHA256, enc, algo } from "crypto-js"; @@ -15,10 +15,12 @@ export interface HttpsClientMessage { class PayPayRestSDK { private options: any = ""; private productionMode: boolean = false; + private auth: Auth; private config: Conf; constructor() { this.config = new Conf(this.productionMode); + this.auth = new Auth(); } /** @@ -28,7 +30,7 @@ class PayPayRestSDK { * @param {string} merchantId MERCHANT_ID provided by end-user */ public configure = (clientConfig: { clientId: string; clientSecret: string; merchantId?: string; productionMode: boolean; }) => { - auth.setAuth(clientConfig.clientId, clientConfig.clientSecret, clientConfig.merchantId); + this.auth.setAuth(clientConfig.clientId, clientConfig.clientSecret, clientConfig.merchantId); if (clientConfig.productionMode) { this.productionMode = clientConfig.productionMode } else { @@ -72,9 +74,9 @@ class PayPayRestSDK { this.options.port = this.config.getPortNumber(); this.options.headers = { "Authorization": header, - "X-ASSUME-MERCHANT": auth.merchantId, + "X-ASSUME-MERCHANT": this.auth.merchantId, }; - if (isempty.includes(auth.merchantId)) { + if (isempty.includes(this.auth.merchantId)) { this.options.headers = { "Authorization": header, }; @@ -106,7 +108,7 @@ class PayPayRestSDK { const authHeader = this.createAuthHeader(this.options.method, cleanPath, this.options.method === "GET" || this.options.method === "DELETE" ? null : input, - auth); + this.auth); this.setHttpsOptions(authHeader); if (this.options.method === "POST") { @@ -464,3 +466,4 @@ class PayPayRestSDK { * These are methods and variables that are exposed to end-user */ export let payPayRestSDK = new PayPayRestSDK(); +export { PayPayRestSDK }; diff --git a/test/PayPayRestSDK.test.ts b/test/PayPayRestSDK.test.ts new file mode 100644 index 00000000..5a6b7566 --- /dev/null +++ b/test/PayPayRestSDK.test.ts @@ -0,0 +1,26 @@ +import PayPay from "../src"; + + + +test('Unit Test - Check the different fields between two RestSDK instances', async () => { + const conf1 = { + clientId: 'clientId1', + clientSecret: 'clientSecret1', + merchantId: '2473982', + productionMode: false + }; + const client1 = new PayPay.PayPayRestSDK(); + client1.configure(conf1) + + const conf2 = { + clientId: 'clientId2', + clientSecret: 'clientSecret2', + merchantId: '3429854', + productionMode: true + }; + const client2 = new PayPay.PayPayRestSDK(); + client2.configure(conf2) + + expect(client1['auth']).not.toEqual(client2['auth']); + expect(client1['config']).not.toEqual(client2['config']); +});