Skip to content

Commit

Permalink
Merge 7e80e05 into dc4e902
Browse files Browse the repository at this point in the history
  • Loading branch information
PaypayBob committed Sep 28, 2020
2 parents dc4e902 + 7e80e05 commit 4fb6b76
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib/auth.ts
Expand Up @@ -7,7 +7,7 @@
class Auth {
clientId: string;
clientSecret: string;
merchantId: string;
merchantId?: string;
/**
* Set intial values to empty string
*/
Expand All @@ -22,7 +22,7 @@ class Auth {
* @param {String} clientId API_KEY provided by client
* @param {String} clientSecret API_SECRET provided by client
*/
setAuth(clientId: string, clientSecret: string, merchantId: string) {
setAuth(clientId: string, clientSecret: string, merchantId?: string) {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.merchantId = merchantId;
Expand Down
8 changes: 7 additions & 1 deletion src/lib/paypay-rest-sdk.ts
Expand Up @@ -27,7 +27,7 @@ class PayPayRestSDK {
* @param {string} clientSecret API_SECRET provided by end-user
* @param {string} merchantId MERCHANT_ID provided by end-user
*/
public configure = (clientConfig: { clientId: string; clientSecret: string; merchantId: string; productionMode: boolean;}) => {
public configure = (clientConfig: { clientId: string; clientSecret: string; merchantId?: string; productionMode: boolean;}) => {
auth.setAuth(clientConfig.clientId, clientConfig.clientSecret, clientConfig.merchantId);
if (clientConfig.productionMode) {
this.productionMode = clientConfig.productionMode
Expand Down Expand Up @@ -67,12 +67,18 @@ class PayPayRestSDK {
}

private setHttpsOptions(header: string) {
let isempty : any = [undefined, null, "", 'undefined', 'null'];
this.options.hostname = this.config.getHostname(),
this.options.port = this.config.getPortNumber(),
this.options.headers = {
"Authorization": header,
"X-ASSUME-MERCHANT": auth.merchantId,
};
if(isempty.includes(auth.merchantId)){
this.options.headers = {
"Authorization": header,
};
}
this.config.setHttpsOptions(this.options);
}

Expand Down
79 changes: 79 additions & 0 deletions test/qrCodeCreateWithMerchantNotSpecified.test.ts
@@ -0,0 +1,79 @@
import { payPayRestSDK } from "../src/lib/paypay-rest-sdk";
import { httpsClient } from '../src/lib/httpsClient';

const conf = {
clientId: '5345435fsdfsr54353454',
clientSecret: 'dgfgdfgt46435gsdr35tte5',
productionMode: false
};

payPayRestSDK.configure(conf);

test('Unit Test - Create QR code without specifying the merchant id', async () => {

const payload = {
merchantPaymentId: '2312324',
amount: {
amount: 1,
currency: 'JPY',
},
codeType: 'ORDER_QR',
orderDescription: 'Test Description',
isAuthorization: false,
redirectUrl: 'https://test.redirect.url/',
redirectType: 'WEB_LINK',
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'
};

const response = {
"resultInfo": {
"code": "SUCCESS",
"message": "Success",
"codeId": "08100001"
},
"data": {
"codeId": "08100001",
"url": "https://test.url/",
"deeplink": "https://test.deeplink",
"expiryDate": 3213232,
"merchantPaymentId": "342423423",
"amount": {
"amount": 10.50,
"currency": "JPY"
},
"orderDescription": "Test Description",
"orderItems": [
{
"name": "Test Item",
"category": "Test Category",
"quantity": 1,
"productId": "349329",
"unit_price": {
"amount": 10.50,
"currency": "JPY"
}
}
],
"metadata": {},
"requestedAt": 2131312,
"redirectUrl": "https://test.redirect.url/",
"redirectType": "WEB_LINK",
"isAuthorization": true,
"authorizationExpiry": null
}
};

const mockHttpsCall = jest.spyOn(httpsClient, 'httpsCall');
mockHttpsCall.mockImplementation(jest.fn((_options: any, _payload = '', _callback: any) => {
_callback(response);
}));

await payPayRestSDK.qrCodeCreate(payload, (result: any) => {
expect(result).toEqual(response);
});

expect(mockHttpsCall).toHaveBeenCalledTimes(1);
expect(mockHttpsCall).toHaveBeenCalledWith(expect.anything(), payload, expect.anything());

mockHttpsCall.mockClear();
});

0 comments on commit 4fb6b76

Please sign in to comment.