Skip to content

Commit be8dd8b

Browse files
committed
[PEV-20-375] New sample view endpoints for VPOS portal Iframe
1 parent ef3dcac commit be8dd8b

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

.github/workflows/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ jobs:
99
build:
1010
name: 'Run tests'
1111
runs-on: ubuntu-latest
12-
container: node:9.4.0
12+
container: node:23.7.0
1313
defaults:
1414
run:
1515
working-directory: ./vpos/checkout/javascript
1616

1717
timeout-minutes: 10
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- run: yarn install --frozen-lockfile
2222
- run: yarn test
2323

vpos/checkout/javascript/src/bancard-checkout.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import exceptions from './bancard-checkout-exceptions';
22
import constants from './constants';
33

44
const CHECKOUT_IFRAME_URL = `${constants.BANCARD_URL}/checkout/new`;
5+
const CHECKOUT_EXAMPLE_IFRAME_URL = `${constants.BANCARD_URL}/checkout/static_example`;
56
const NEW_CARD_IFRAME_URL = `${constants.BANCARD_URL}/checkout/register_card/new`;
7+
const CARD_EXAMPLE_IFRAME_URL = `${constants.BANCARD_URL}/checkout/static_example/register_card`;
68
const ZIMPLE_IFRAME_URL = `${constants.BANCARD_URL}/checkout/zimple/new`;
79
const ALLOWED_STYLES_URL = `${constants.BANCARD_URL}/checkout/allowed_styles`;
810
const CONFIRMATION_IFRAME_URL = `${constants.BANCARD_URL}/alias_token/confirmation/new`;
@@ -159,6 +161,18 @@ const internalMethods = {
159161
internalMethods.initializeIframe(divId, iFrameUrl, options);
160162
},
161163

164+
createStaticForm: ({
165+
divId, applicationId, options, url,
166+
}) => {
167+
if (typeof applicationId !== 'string' || applicationId === '') {
168+
throw new exceptions.InvalidParameter('Application id');
169+
}
170+
171+
const iFrameUrl = internalMethods.addParamToUrl(url, 'application_id', applicationId);
172+
173+
internalMethods.initializeIframe(divId, iFrameUrl, options);
174+
},
175+
162176
loadPinPad: ({
163177
divId, aliasToken, options, url,
164178
}) => {
@@ -190,6 +204,17 @@ class Bancard {
190204
};
191205
}
192206

207+
get CheckoutExample() {
208+
return {
209+
createStaticForm: (divId, applicationId, options) => {
210+
this.divId = divId;
211+
internalMethods.createStaticForm({
212+
divId, applicationId, options, url: CHECKOUT_EXAMPLE_IFRAME_URL,
213+
});
214+
},
215+
};
216+
}
217+
193218
get Cards() {
194219
return {
195220
createForm: (divId, processId, options) => {
@@ -201,6 +226,17 @@ class Bancard {
201226
};
202227
}
203228

229+
get CardsExample() {
230+
return {
231+
createStaticForm: (divId, applicationId, options) => {
232+
this.divId = divId;
233+
internalMethods.createStaticForm({
234+
divId, applicationId, options, url: CARD_EXAMPLE_IFRAME_URL,
235+
});
236+
},
237+
};
238+
}
239+
204240
get Zimple() {
205241
return {
206242
createForm: (divId, processId, options) => {

vpos/checkout/javascript/src/specs/bancard-checkout.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ describe('Bancard', () => {
2929
});
3030
});
3131

32+
describe('CheckoutExample', () => {
33+
beforeEach(() => {
34+
instance.CheckoutExample.createStaticForm('targetDiv', '1234');
35+
window.location.replace = jest.fn();
36+
});
37+
38+
afterEach(() => { instance.destroy(); });
39+
40+
test('It creates the iframe', () => {
41+
expect(document.querySelectorAll('iframe').length).toBe(1);
42+
});
43+
44+
test('Iframe points to correct URL', () => {
45+
expect(document.querySelectorAll('iframe')[0].getAttribute('src'))
46+
.toBe('https://desa.infonet.com.py:8085/checkout/static_example?application_id=1234');
47+
});
48+
});
49+
3250
describe('Cards', () => {
3351
beforeEach(() => {
3452
instance.Cards.createForm('targetDiv', '1234');
@@ -47,6 +65,24 @@ describe('Bancard', () => {
4765
});
4866
});
4967

68+
describe('CardsExample', () => {
69+
beforeEach(() => {
70+
instance.CardsExample.createStaticForm('targetDiv', '1234');
71+
window.location.replace = jest.fn();
72+
});
73+
74+
afterEach(() => { instance.destroy(); });
75+
76+
test('It creates the iframe', () => {
77+
expect(document.querySelectorAll('iframe').length).toBe(1);
78+
});
79+
80+
test('Iframe points to correct URL', () => {
81+
expect(document.querySelectorAll('iframe')[0].getAttribute('src'))
82+
.toBe('https://desa.infonet.com.py:8085/checkout/static_example/register_card?application_id=1234');
83+
});
84+
});
85+
5086
describe('Zimple', () => {
5187
beforeEach(() => {
5288
instance.Zimple.createForm('targetDiv', '1234');

0 commit comments

Comments
 (0)