Skip to content

Commit

Permalink
Merge pull request #199 from tilfin/feature/export-PayPayRestSDK
Browse files Browse the repository at this point in the history
Enable to create the instance of PayPayRestSDK
  • Loading branch information
Shreyansh Pandey authored Mar 24, 2021
2 parents ee80318 + 128f961 commit 3b914ce
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { payPayRestSDK } from "./lib/paypay-rest-sdk";
import { payPayRestSDK, PayPayRestSDK } from "./lib/paypay-rest-sdk";

export = {
Configure: payPayRestSDK.configure,
Expand Down Expand Up @@ -29,4 +29,5 @@ export = {
CheckCashBackDetails: payPayRestSDK.getCashBackDetails,
ReversalCashBack: payPayRestSDK.reverseCashBack,
CheckCashBackReversalDetails: payPayRestSDK.getReverseCashBackDetails,
PayPayRestSDK
};
4 changes: 1 addition & 3 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,5 +28,3 @@ class Auth {
this.merchantId = merchantId;
}
}

export let auth = new Auth();
13 changes: 8 additions & 5 deletions src/lib/paypay-rest-sdk.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
}

/**
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -464,3 +466,4 @@ class PayPayRestSDK {
* These are methods and variables that are exposed to end-user
*/
export let payPayRestSDK = new PayPayRestSDK();
export { PayPayRestSDK };
26 changes: 26 additions & 0 deletions test/PayPayRestSDK.test.ts
Original file line number Diff line number Diff line change
@@ -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']);
});

0 comments on commit 3b914ce

Please sign in to comment.