Skip to content

Commit

Permalink
[PEV-20-375] New sample view endpoints for VPOS portal Iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliCarracedo committed Feb 7, 2025
1 parent ef3dcac commit 8dd6c20
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions vpos/checkout/javascript/src/bancard-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import exceptions from './bancard-checkout-exceptions';
import constants from './constants';

const CHECKOUT_IFRAME_URL = `${constants.BANCARD_URL}/checkout/new`;
const CHECKOUT_EXAMPLE_IFRAME_URL = `${constants.BANCARD_URL}/checkout/static_example`;
const NEW_CARD_IFRAME_URL = `${constants.BANCARD_URL}/checkout/register_card/new`;
const CARD_EXAMPLE_IFRAME_URL = `${constants.BANCARD_URL}/checkout/static_example/register_card`;
const ZIMPLE_IFRAME_URL = `${constants.BANCARD_URL}/checkout/zimple/new`;
const ALLOWED_STYLES_URL = `${constants.BANCARD_URL}/checkout/allowed_styles`;
const CONFIRMATION_IFRAME_URL = `${constants.BANCARD_URL}/alias_token/confirmation/new`;
Expand Down Expand Up @@ -159,6 +161,18 @@ const internalMethods = {
internalMethods.initializeIframe(divId, iFrameUrl, options);
},

createStaticForm: ({
divId, applicationId, options, url,
}) => {
if (typeof applicationId !== 'string' || applicationId === '') {
throw new exceptions.InvalidParameter('Application id');
}

const iFrameUrl = internalMethods.addParamToUrl(url, 'application_id', applicationId);

internalMethods.initializeIframe(divId, iFrameUrl, options);
},

loadPinPad: ({
divId, aliasToken, options, url,
}) => {
Expand Down Expand Up @@ -190,6 +204,17 @@ class Bancard {
};
}

get CheckoutExample() {
return {
createStaticForm: (divId, applicationId, options) => {
this.divId = divId;
internalMethods.createStaticForm({
divId, applicationId, options, url: CHECKOUT_EXAMPLE_IFRAME_URL,
});
},
};
}

get Cards() {
return {
createForm: (divId, processId, options) => {
Expand All @@ -201,6 +226,17 @@ class Bancard {
};
}

get CardsExample() {
return {
createStaticForm: (divId, applicationId, options) => {
this.divId = divId;
internalMethods.createStaticForm({
divId, applicationId, options, url: CARD_EXAMPLE_IFRAME_URL,
});
},
};
}

get Zimple() {
return {
createForm: (divId, processId, options) => {
Expand Down
36 changes: 36 additions & 0 deletions vpos/checkout/javascript/src/specs/bancard-checkout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ describe('Bancard', () => {
});
});

describe('CheckoutExample', () => {
beforeEach(() => {
instance.CheckoutExample.createStaticForm('targetDiv', '1234');
window.location.replace = jest.fn();
});

afterEach(() => { instance.destroy(); });

test('It creates the iframe', () => {
expect(document.querySelectorAll('iframe').length).toBe(1);
});

test('Iframe points to correct URL', () => {
expect(document.querySelectorAll('iframe')[0].getAttribute('src'))
.toBe('https://desa.infonet.com.py:8085/checkout/static_example?application_id=1234');
});
});

describe('Cards', () => {
beforeEach(() => {
instance.Cards.createForm('targetDiv', '1234');
Expand All @@ -47,6 +65,24 @@ describe('Bancard', () => {
});
});

describe('CardsExample', () => {
beforeEach(() => {
instance.CardsExample.createStaticForm('targetDiv', '1234');
window.location.replace = jest.fn();
});

afterEach(() => { instance.destroy(); });

test('It creates the iframe', () => {
expect(document.querySelectorAll('iframe').length).toBe(1);
});

test('Iframe points to correct URL', () => {
expect(document.querySelectorAll('iframe')[0].getAttribute('src'))
.toBe('https://desa.infonet.com.py:8085/checkout/static_example/register_card?application_id=1234');
});
});

describe('Zimple', () => {
beforeEach(() => {
instance.Zimple.createForm('targetDiv', '1234');
Expand Down

0 comments on commit 8dd6c20

Please sign in to comment.