Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cash back api #176

Merged
merged 3 commits into from Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -615,3 +615,4 @@ There are two ways to react with this situation:

## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpaypay%2Fpaypayopa-sdk-node.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpaypay%2Fpaypayopa-sdk-node?ref=badge_large)

6 changes: 5 additions & 1 deletion src/index.ts
Expand Up @@ -25,4 +25,8 @@ export = {
RefundPendingPayment: payPayRestSDK.refundPendingPayment,
GetUserAuthorizationStatus: payPayRestSDK.getUserAuthorizationStatus,
UnlinkUser: payPayRestSDK.unlinkUser,
};
CashBack: payPayRestSDK.cashBack,
CheckCashBackDetails: payPayRestSDK.getCashBackDetails,
ReversalCashBack: payPayRestSDK.reverseCashBack,
CheckCashBackReversalDetails: payPayRestSDK.getReverseCashBackDetails,
};
20 changes: 20 additions & 0 deletions src/lib/conf.prod.json
Expand Up @@ -55,6 +55,26 @@
"METHOD": "GET",
"PATH": "/v2/refunds/{merchantRefundId}",
"API_NAME": "v2_getRefundDetails"
},
"GIVE_CASH_BACK": {
"METHOD": "POST",
"PATH": "/v2/cashback",
"API_NAME": "v2_createCashBackRequest"
},
"CHECK_CASHBACK_DETAILS": {
"METHOD": "GET",
"PATH": "/v2/cashback/{merchantCashbackId}",
"API_NAME": "v2_getCashbackDetails"
},
"REVERSAL_CASHBACK": {
"METHOD": "POST",
"PATH": "/v2/cashback_reversal",
"API_NAME": "v2_createReverseCashBackRequest"
},
"CHECK_CASHBACK_REVERSE_DETAILS": {
"METHOD": "GET",
"PATH": "/v2/cashback_reversal/{merchantCashbackReversalId}/{merchantCashbackId}",
"API_NAME": "v2_getReversedCashBackDetails"
}
},
"API_WALLET": {
Expand Down
20 changes: 20 additions & 0 deletions src/lib/conf.stage.json
Expand Up @@ -55,6 +55,26 @@
"METHOD": "GET",
"PATH": "/v2/refunds/{merchantRefundId}",
"API_NAME": "v2_getRefundDetails"
},
"GIVE_CASH_BACK": {
"METHOD": "POST",
"PATH": "/v2/cashback",
"API_NAME": "v2_createCashBackRequest"
},
"CHECK_CASHBACK_DETAILS": {
"METHOD": "GET",
"PATH": "/v2/cashback/{merchantCashbackId}",
"API_NAME": "v2_getCashbackDetails"
},
"REVERSAL_CASHBACK": {
"METHOD": "POST",
"PATH": "/v2/cashback_reversal",
"API_NAME": "v2_createReverseCashBackRequest"
},
"CHECK_CASHBACK_REVERSE_DETAILS": {
"METHOD": "GET",
"PATH": "/v2/cashback_reversal/{merchantCashbackReversalId}/{merchantCashbackId}",
"API_NAME": "v2_getReversedCashBackDetails"
}
},
"API_WALLET": {
Expand Down
61 changes: 61 additions & 0 deletions src/lib/paypay-rest-sdk.ts
Expand Up @@ -397,6 +397,67 @@ class PayPayRestSDK {
callback(result);
})
}

/**
* Cash back
*
* @callback Callback function to handle result
* @returns {Object} Returns result containing STATUS and BODY
* @param {string} inputParams Array of UserAuthorizationId : The unique UserAuthorizationId id
* @param inputParams
* @param callback
*/
public cashBack = (payload: any, callback: HttpsClientMessage): void => {
httpsClient.httpsCall(this.paypaySetupOptions("API_PAYMENT", "GIVE_CASH_BACK", payload), payload, (result: any) => {
callback(result);
})
}

/**
* Get Cash back details
*
* @callback Callback function to handle result
* @returns {Object} Returns result containing STATUS and BODY
* @param {string} inputParams Array of UserAuthorizationId : The unique UserAuthorizationId id
* @param inputParams
* @param callback
*/
public getCashBackDetails = (inputParams: Array<string | number>, callback: HttpsClientMessage): void => {
httpsClient.httpsCall(this.paypaySetupOptions("API_PAYMENT", "CHECK_CASHBACK_DETAILS", inputParams), "", (result: any) => {
callback(result);
})
}

/**
* Reverse Cash back
*
* @callback Callback function to handle result
* @returns {Object} Returns result containing STATUS and BODY
* @param {string} inputParams Array of UserAuthorizationId : The unique UserAuthorizationId id
* @param inputParams
* @param callback
*/
public reverseCashBack = (payload: any, callback: HttpsClientMessage): void => {
httpsClient.httpsCall(this.paypaySetupOptions("API_PAYMENT", "REVERSAL_CASHBACK", payload), payload, (result: any) => {
callback(result);
})
}

/**
* Get Reverse Cash back details
*
* @callback Callback function to handle result
* @returns {Object} Returns result containing STATUS and BODY
* @param {string} inputParams Array of UserAuthorizationId : The unique UserAuthorizationId id
* @param inputParams
* @param callback
*/
public getReverseCashBackDetails = (inputParams: Array<string | number>, callback: HttpsClientMessage): void => {
httpsClient.httpsCall(this.paypaySetupOptions("API_PAYMENT", "CHECK_CASHBACK_REVERSE_DETAILS", inputParams), "", (result: any) => {
callback(result);
})
}

}

/**
Expand Down
50 changes: 50 additions & 0 deletions test/cashback.test.ts
@@ -0,0 +1,50 @@
import { payPayRestSDK } from "../src/lib/paypay-rest-sdk";
import { httpsClient } from '../src/lib/httpsClient';
const { v4: uuidv4 } = require('uuid');

const conf = {
clientId: 'test',
clientSecret: 'test',
merchantId: 'test',
productionMode: false
};

payPayRestSDK.configure(conf);

test('Unit Test - Cash Back', async () => {

const payload = {
"merchantCashbackId": uuidv4(),
"userAuthorizationId": "testId",
"amount": {
"amount": 1,
"currency": "JPY"
},
"requestedAt": 1609749559,
"orderDescription": "order description",
"walletType": "CASHBACK",
"expiryDate": '2021-07-31',
"metadata": ""
}

const response = {
"resultInfo": { "code": "REQUEST_ACCEPTED", "message": "Request accepted", "codeId": "08100001" },
"data": null,
}



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

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

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

mockHttpsCall.mockClear();
});
33 changes: 33 additions & 0 deletions test/checkCashBackDetails.test.ts
@@ -0,0 +1,33 @@
import { payPayRestSDK } from "../src/lib/paypay-rest-sdk";
import { httpsClient } from '../src/lib/httpsClient';

const conf = {
clientId: 'testId',
clientSecret: 'testId',
merchantId: '2473982',
productionMode: false
};

payPayRestSDK.configure(conf);

test('Unit Test - Check cashback details', async () => {

const merchantPaymentId = [12393849];
const response = {
STATUS: 200,
BODY: '{"resultInfo":{"code":"SUCCESS","message":"Success","codeId":"08100001"},"data":{"status":"SUCCESS","acceptedAt":1611747653,"merchantAlias":"test","amount":{"amount":1,"currency":"JPY"},"requestedAt":1611747650,"metadata":"","cashbackId":"test","merchantCashbackId":"test","userAuthorizationId":"test","orderDescription":"order description","walletType":"PREPAID"}}'
}

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

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

expect(mockHttpsCall).toHaveBeenCalledTimes(1);

mockHttpsCall.mockClear();
});
33 changes: 33 additions & 0 deletions test/checkCashBackReversalDetails.test.ts
@@ -0,0 +1,33 @@
import { payPayRestSDK } from "../src/lib/paypay-rest-sdk";
import { httpsClient } from '../src/lib/httpsClient';

const conf = {
clientId: 'test',
clientSecret: 'test',
merchantId: '2473982',
productionMode: false
};

payPayRestSDK.configure(conf);

test('Unit Test - Check cashback reversal details', async () => {

const merchantPaymentId = [12393849];
const response = {
STATUS: 200,
BODY: '{"resultInfo":{"code":"SUCCESS","message":"Success","codeId":"08100001"},"data":{"status":"SUCCESS","acceptedAt":1611747702,"merchantAlias":"test","amount":{"amount":1,"currency":"JPY"},"requestedAt":1611747699,"metadata":"","cashbackReversalId":"test","merchantCashbackReversalId":"test","merchantCashbackId":"test"}}'
}

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

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

expect(mockHttpsCall).toHaveBeenCalledTimes(1);

mockHttpsCall.mockClear();
});
48 changes: 48 additions & 0 deletions test/reversalCashBack.test.ts
@@ -0,0 +1,48 @@
import { payPayRestSDK } from "../src/lib/paypay-rest-sdk";
import { httpsClient } from '../src/lib/httpsClient';
const { v4: uuidv4 } = require('uuid');

const conf = {
clientId: 'test',
clientSecret: 'test',
merchantId: 'test',
productionMode: false
};

payPayRestSDK.configure(conf);

test('Unit Test - Reversal Cash Back', async () => {

const payload = {
"merchantCashbackReversalId": uuidv4(),
"merchantCashbackId": "testId",
"amount": {
"amount": 1,
"currency": "JPY"
},
"requestedAt": 1609749559,
"orderDescription": "order description",
"walletType": "PREPAID",
"expiryDate": "",
"metadata": ""
}

const response = {
"resultInfo": { "code": "REQUEST_ACCEPTED", "message": "Request accepted", "codeId": "08100001" },
"data": null,
}

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

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

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

mockHttpsCall.mockClear();
});