Skip to content

Commit 388ea48

Browse files
INTER-3509-Add hide-credit-card-payment-option action (#23)
- New action allows the parent window to dispatch an action to PIGI to hide the credit card payment option.
1 parent 70f21eb commit 388ea48

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

src/pigi/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './sendAddPaymentAction';
44
export * from './sendClearErrorMessageAction';
55
export * from './sendDisplayErrorMessageAction';
66
export * from './sendHandleScaAction';
7+
export * from './sendHideCreditCardOptionAction';
78
export * from './sendRefreshOrderAction';
89
export * from './sendSelectPaymentMethodAction';
910
export * from './sendUpdateLanguageAction';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {pigiActionTypes, IApiReturnObject, IPigiActionType, IPigiResponseType, sendPigiAction, sendPigiActionAsync} from 'src';
2+
3+
const action: IPigiActionType = { actionType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION };
4+
/**
5+
* ## sendHideCreditCardOptionAction
6+
*
7+
* This action is to be sent after PIGI has been loaded. It causes the credit card
8+
* fields in PIGI to be hidden.
9+
*/
10+
export function sendHideCreditCardOptionAction(): IApiReturnObject {
11+
return sendPigiAction(action);
12+
}
13+
14+
/**
15+
* ## sendHideCreditCardOptionActionAsync
16+
*
17+
* This action is to be sent after PIGI has been loaded. It causes the credit card
18+
* fields in PIGI to be hidden.
19+
*
20+
* This method waits for a response back from PIGI before returning.
21+
*/
22+
export async function sendHideCreditCardOptionActionAsync(): Promise<IPigiResponseType> {
23+
return await sendPigiActionAsync(action);
24+
}

src/types/apiInterfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export interface IPigiActionTypes {
7878
PIGI_PAYMENT_ADDED: string;
7979
PIGI_DISPLAY_IN_FULL_PAGE: string;
8080
PIGI_DISPLAY_IN_FULL_PAGE_DONE: string;
81+
PIGI_HIDE_CREDIT_CARD_OPTION: string;
8182
}
8283

8384
export interface IExternalPaymentGatewayToParentActionTypes {

src/variables/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const pigiActionTypes: IPigiActionTypes = {
6767
PIGI_PAYMENT_ADDED: 'PIGI_PAYMENT_ADDED',
6868
PIGI_DISPLAY_IN_FULL_PAGE: 'PIGI_DISPLAY_IN_FULL_PAGE',
6969
PIGI_DISPLAY_IN_FULL_PAGE_DONE: 'PIGI_DISPLAY_IN_FULL_PAGE_DONE',
70+
PIGI_HIDE_CREDIT_CARD_OPTION: 'PIGI_HIDE_CREDIT_CARD_OPTION',
7071
};
7172

7273
export const externalPaymentGatewayToParentActionTypes: IExternalPaymentGatewayToParentActionTypes = {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {apiErrors, baseReturnObject, pigiActionTypes, FetchError, IPigiResponseType, sendHideCreditCardOptionAction, sendHideCreditCardOptionActionAsync} from 'src';
2+
import {pigi} from 'src/variables';
3+
import * as sendPigiAction from 'src/pigi/sendPigiAction';
4+
5+
describe('testing send PIGI Hide Credit Card Action', () => {
6+
pigi.iFrameId = 'PIGI';
7+
const calledOnce = 1;
8+
let sendPigiActionSpy: jest.SpyInstance;
9+
let sendPigiActionAsyncSpy: jest.SpyInstance;
10+
const expectedAction = { actionType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION };
11+
12+
beforeEach(() => {
13+
jest.restoreAllMocks();
14+
sendPigiActionSpy = jest.spyOn(sendPigiAction, 'sendPigiAction');
15+
sendPigiActionAsyncSpy = jest.spyOn(sendPigiAction, 'sendPigiActionAsync');
16+
});
17+
18+
test('calling sendAddPaymentAction success', () => {
19+
const tempReturnObject = {...baseReturnObject};
20+
tempReturnObject.success = true;
21+
sendPigiActionSpy.mockReturnValueOnce(tempReturnObject);
22+
23+
const res = sendHideCreditCardOptionAction();
24+
25+
expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce);
26+
expect(sendPigiActionSpy).toHaveBeenCalledWith(expectedAction);
27+
expect(res).not.toBeNull();
28+
expect(res).toStrictEqual(tempReturnObject);
29+
});
30+
31+
test('calling sendHideCreditCardOptionAction null Frame Window', () => {
32+
const tempReturnObject = {...baseReturnObject};
33+
tempReturnObject.success = false;
34+
tempReturnObject.error = new FetchError(apiErrors.noPigiIframe.status, apiErrors.noPigiIframe.message);
35+
sendPigiActionSpy.mockReturnValueOnce(tempReturnObject);
36+
37+
const res = sendHideCreditCardOptionAction();
38+
39+
expect(sendPigiActionSpy).toHaveBeenCalledTimes(calledOnce);
40+
expect(res).not.toBeNull();
41+
expect(res).toStrictEqual(tempReturnObject);
42+
});
43+
44+
test('calling sendAddPaymentActionAsync success', async () => {
45+
const tempReturnObject: IPigiResponseType = {
46+
responseType: pigiActionTypes.PIGI_HIDE_CREDIT_CARD_OPTION,
47+
payload: {success: true}
48+
};
49+
sendPigiActionAsyncSpy.mockReturnValueOnce(tempReturnObject);
50+
51+
const res = await sendHideCreditCardOptionActionAsync();
52+
53+
expect(sendPigiActionAsyncSpy).toHaveBeenCalledTimes(calledOnce);
54+
expect(sendPigiActionAsyncSpy).toHaveBeenCalledWith(expectedAction);
55+
expect(res).not.toBeNull();
56+
expect(res).toStrictEqual(tempReturnObject);
57+
});
58+
});
59+

0 commit comments

Comments
 (0)