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

v6 - Synchronous submit with order tracking #2425

Merged
merged 58 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
94afef0
draft: async submit
ribeiroguilherme Nov 13, 2023
0011106
temp: disabling errors
ribeiroguilherme Nov 29, 2023
1372f66
feat: advanced flow with googlepay
ribeiroguilherme Nov 29, 2023
9a05b85
draft gp sessions flow
m1aw Nov 30, 2023
6635431
feat: googlepay adjustments
ribeiroguilherme Nov 30, 2023
d47f03a
apple pay adjustments
ribeiroguilherme Dec 1, 2023
8336aa0
Merge branch 'v6' into feat/express-payment-and-order-tracking
ribeiroguilherme Dec 1, 2023
76625a9
feat: clean up
ribeiroguilherme Dec 1, 2023
57561e9
sanitizing response and checking resultCode
ribeiroguilherme Dec 4, 2023
fde4db9
fixed bug checking resultCode
ribeiroguilherme Dec 4, 2023
b5c8862
add: onPaymentFailed callback
m1aw Dec 5, 2023
62f4518
refactor: change handle order, adds onPaymentMethodsRequest
m1aw Dec 6, 2023
4cf1e54
refactor: rename onOrderCreated to onOrderUpdated
m1aw Dec 6, 2023
95519d7
fix: handle reject onPaymentMethodsRequest
m1aw Dec 6, 2023
39a92c9
fixes UIelement props overwritten on update
m1aw Dec 7, 2023
ad6b2b5
feat: applepay order tracking untested changes
ribeiroguilherme Dec 8, 2023
a96dc2a
applepay: exposing authorization event
ribeiroguilherme Dec 11, 2023
077870f
untested applepay address format
Dec 12, 2023
5820016
applepay - formatting data accordingly
ribeiroguilherme Dec 14, 2023
1d0d7bb
applepay address formatter unit tests
ribeiroguilherme Dec 15, 2023
324a3ae
feat: parsing googlepay address
ribeiroguilherme Dec 15, 2023
0c7c16d
using onAuthorized on gpay,applepay,paypal
ribeiroguilherme Dec 18, 2023
a4aa928
feat: handling failure
ribeiroguilherme Dec 19, 2023
75ddaa3
feat: giftcard in storybook
m1aw Dec 19, 2023
83dd840
additional details part
ribeiroguilherme Dec 20, 2023
689b362
checkout.submitDetails fix
ribeiroguilherme Dec 21, 2023
5879bc3
always resolving
ribeiroguilherme Dec 21, 2023
ab0e7ba
rejecting googlepay onauthorize with error
ribeiroguilherme Dec 21, 2023
3c930e9
applepay rejecting onauthorized
ribeiroguilherme Dec 22, 2023
638c0f8
fix: current tests
ribeiroguilherme Jan 16, 2024
02756ef
tests: applepay
ribeiroguilherme Jan 17, 2024
163dbcd
tests: googlepay
ribeiroguilherme Jan 17, 2024
7e86326
fix: temp stuff
ribeiroguilherme Jan 17, 2024
cc3327f
test: uielement, handling order, actions, additional details
ribeiroguilherme Jan 19, 2024
135c9bc
fix: reverting prettier config
ribeiroguilherme Jan 19, 2024
30cbf9e
Merge branch 'v6' into feat/express-payment-and-order-tracking
ribeiroguilherme Jan 19, 2024
99f3222
Merge branch 'v6' into feat/express-payment-and-order-tracking
ribeiroguilherme Jan 22, 2024
b8c03f6
fixing old playground
ribeiroguilherme Jan 22, 2024
be9b591
fixing storybook
ribeiroguilherme Jan 23, 2024
d1df1a3
storybook
ribeiroguilherme Jan 23, 2024
20b273f
fix googletest
ribeiroguilherme Jan 23, 2024
0aaa389
fix: updating e2e playwright
ribeiroguilherme Jan 23, 2024
cd8561d
updating size-limit
ribeiroguilherme Jan 23, 2024
c198dd9
e2e testcafe: updating files
ribeiroguilherme Jan 23, 2024
0c5319f
fixed testcafe tests
ribeiroguilherme Jan 24, 2024
ea50de1
fixing sonarcloud lint
ribeiroguilherme Jan 25, 2024
c49af07
attempt to delete types.ts from sonarcloud
ribeiroguilherme Jan 25, 2024
a2ee22c
moved exclusions to sonarcloud file
ribeiroguilherme Jan 25, 2024
d167743
sonarcloud: adding spec file
ribeiroguilherme Jan 25, 2024
39a5ea8
feat: using error message from i18n
ribeiroguilherme Jan 25, 2024
b7d9a04
Fixed typescript errors related to mismatching onError function signa…
sponglord Jan 31, 2024
1377445
Added wait to e2e test to give time for payment to be processed
sponglord Jan 31, 2024
edc36ea
Removed onError type from Card/types
sponglord Feb 1, 2024
8b88b8f
Added onValidationError callback for the CustomCard component
sponglord Feb 1, 2024
cbc28f2
Added optional chaining operator for customCard's onValidationError c…
sponglord Feb 5, 2024
03faf1f
fix giftcard callback types
m1aw Jan 29, 2024
b5ed5f9
AmazonPay storybook
m1aw Feb 5, 2024
4d1b1cb
fix type def amazonpay
m1aw Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions packages/e2e-playwright/app/src/handlers.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
import { makePayment, makeDetailsCall, createOrder } from './services';

function removeComponent(component) {
component.remove();
}

export function showAuthorised(message = 'Authorised') {
const resultElement = document.getElementById('result-message');
resultElement.classList.remove('hide');
resultElement.innerText = message;
}

export function handleResponse(response, component) {
if (response.action) {
component.handleAction(response.action, window.actionConfigObject || {});
} else if (response.resultCode) {
component.remove();
showAuthorised();
}
}

export function handleError(obj) {
// SecuredField related errors should not go straight to console.error
if (obj.type === 'card') {
Expand All @@ -28,28 +15,45 @@ export function handleError(obj) {
}
}

export function handleSubmit(state, component) {
component.setStatus('loading');
export async function handleSubmit(state, component, actions) {
try {
const { action, order, resultCode, donationToken } = await makePayment(state.data);

return makePayment(state.data)
.then(response => {
component.setStatus('ready');
handleResponse(response, component);
})
.catch(error => {
throw Error(error);
if (!resultCode) actions.reject();

actions.resolve({
resultCode,
action,
order,
donationToken
});
} catch (error) {
console.error('## onSubmit - critical error', error);
actions.reject();
}
}

export function handleAdditionalDetails(details, component) {
return makeDetailsCall(details.data)
.then(response => {
component.setStatus('ready');
handleResponse(response, component);
})
.catch(error => {
throw Error(error);
export async function handleAdditionalDetails(state, component, actions) {
try {
const { resultCode, action, order, donationToken } = await makeDetailsCall(state.data);

if (!resultCode) actions.reject();

actions.resolve({
resultCode,
action,
order,
donationToken
});
} catch (error) {
console.error('## onAdditionalDetails - critical error', error);
actions.reject();
}
}

export function handlePaymentCompleted(data, component) {
component.remove();
showAuthorised();
}

export function handleOrderRequest(resolve, reject, data) {
Expand Down
5 changes: 3 additions & 2 deletions packages/e2e-playwright/app/src/pages/ANCV/ANCV.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AdyenCheckout, ANCV } from '@adyen/adyen-web';
import '@adyen/adyen-web/styles/adyen.css';
import { handleError, showAuthorised } from '../../handlers';
import { handleError, handlePaymentCompleted, showAuthorised } from '../../handlers';
import { shopperLocale, countryCode } from '../../services/commonConfig';
import '../../style.scss';
import { createSession } from '../../services';
Expand All @@ -27,7 +27,8 @@ const initCheckout = async () => {
locale: shopperLocale,
countryCode,
showPayButton: true,
onOrderCreated: data => {
onPaymentCompleted: handlePaymentCompleted,
onOrderUpdated: data => {
showAuthorised('Partially Authorised');
},
onError: handleError
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-playwright/app/src/pages/Cards/Cards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AdyenCheckout, Card } from '@adyen/adyen-web';
import '@adyen/adyen-web/styles/adyen.css';
import { handleSubmit, handleAdditionalDetails, handleError } from '../../handlers';
import { handleSubmit, handleAdditionalDetails, handleError, handlePaymentCompleted } from '../../handlers';
import { amount, shopperLocale, countryCode } from '../../services/commonConfig';
import '../../style.scss';

Expand All @@ -15,6 +15,7 @@ const initCheckout = async () => {
showPayButton: true,
onSubmit: handleSubmit,
onAdditionalDetails: handleAdditionalDetails,
onPaymentCompleted: handlePaymentCompleted,
onError: handleError,
...window.mainConfiguration
});
Expand Down
18 changes: 13 additions & 5 deletions packages/e2e-playwright/app/src/pages/CustomCards/CustomCards.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { AdyenCheckout, CustomCard } from '@adyen/adyen-web';
import '@adyen/adyen-web/styles/adyen.css';
import { handleSubmit, handleAdditionalDetails } from '../../handlers';
import { handleSubmit, handleAdditionalDetails, handlePaymentCompleted, showAuthorised } from '../../handlers';
import { amount, shopperLocale, countryCode } from '../../services/commonConfig';
import '../../style.scss';
import './customcards.style.scss';
import { setFocus, onBrand, onConfigSuccess, onBinLookup, onChange } from './customCards.config';
import { makePayment } from '../../services';

const initCheckout = async () => {
// window.TextEncoder = null; // Comment in to force use of "compat" version
Expand All @@ -15,8 +16,7 @@ const initCheckout = async () => {
countryCode,
environment: 'test',
showPayButton: true,
onSubmit: handleSubmit,
onAdditionalDetails: handleAdditionalDetails,
onPaymentCompleted: handlePaymentCompleted,
...window.mainConfiguration
});

Expand Down Expand Up @@ -56,7 +56,7 @@ const initCheckout = async () => {
payBtn.setAttribute('data-testid', `pay-${attribute}`);
payBtn.classList.add('adyen-checkout__button', 'js-components-button--one-click', `js-pay-${attribute}`);

payBtn.addEventListener('click', e => {
payBtn.addEventListener('click', async e => {
e.preventDefault();

console.log('### CustomCards::createPayButton:: click attribut', attribute);
Expand All @@ -70,7 +70,15 @@ const initCheckout = async () => {
};
component.state.data = { paymentMethod };

handleSubmit(component.state, component);
const response = await makePayment(component.state.data);
component.setStatus('ready');

if (response.action) {
component.handleAction(response.action, window.actionConfigObject || {});
} else if (response.resultCode) {
component.remove();
showAuthorised();
}
});

document.querySelector(parent).appendChild(payBtn);
Expand Down
3 changes: 2 additions & 1 deletion packages/e2e-playwright/app/src/pages/Dropin/Dropin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AdyenCheckout, Dropin } from '@adyen/adyen-web/auto';
import '@adyen/adyen-web/styles/adyen.css';
import { getPaymentMethods } from '../../services';
import { amount, shopperLocale, countryCode } from '../../services/commonConfig';
import { handleSubmit, handleAdditionalDetails, handleError } from '../../handlers';
import { handleSubmit, handleAdditionalDetails, handleError, handlePaymentCompleted } from '../../handlers';
import '../../style.scss';

const initCheckout = async () => {
Expand All @@ -19,6 +19,7 @@ const initCheckout = async () => {
environment: 'test',
onSubmit: handleSubmit,
onAdditionalDetails: handleAdditionalDetails,
onPaymentCompleted: handlePaymentCompleted,
onError: handleError,
...window.mainConfiguration
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AdyenCheckout, Ideal } from '@adyen/adyen-web';
import '@adyen/adyen-web/styles/adyen.css';
import { handleSubmit, handleAdditionalDetails, handleError } from '../../handlers';
import { handleSubmit, handleAdditionalDetails, handleError, handlePaymentCompleted } from '../../handlers';
import { amount, shopperLocale, countryCode } from '../../services/commonConfig';
import '../../style.scss';
import { getPaymentMethods } from '../../services';
Expand All @@ -24,6 +24,7 @@ const initCheckout = async () => {
showPayButton: true,
onSubmit: handleSubmit,
onAdditionalDetails: handleAdditionalDetails,
onPaymentCompleted: handlePaymentCompleted,
onError: handleError
// ...window.mainConfiguration
});
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-playwright/tests/ancv/ancv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { setupMock } from '../../mocks/setup/setup.mock';
import { statusMock } from '../../mocks/status/status.mock';

test.describe('ANCV - Sessions', () => {
test('should call onOrderCreated when payment is partially authorised (Sessions flow)', async ({ ancvPage }) => {
test('should call onOrderUpdated when payment is partially authorised (Sessions flow)', async ({ ancvPage }) => {
const { ancv, page } = ancvPage;

await createOrderMock(page, orderCreatedMockData);
Expand Down
53 changes: 35 additions & 18 deletions packages/e2e/app/src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,43 @@ export function handleError(obj) {
}
}

export function handleSubmit(state, component) {
component.setStatus('loading');

return makePayment(state.data)
.then(response => {
component.setStatus('ready');
handleResponse(response, component);
})
.catch(error => {
throw Error(error);
export async function handleSubmit(state, component, actions) {
try {
const { action, order, resultCode, donationToken } = await makePayment(state.data);

if (!resultCode) actions.reject();

actions.resolve({
resultCode,
action,
order,
donationToken
});
} catch (error) {
console.error('## onSubmit - critical error', error);
actions.reject();
}
}

export function handleAdditionalDetails(details, component) {
return makeDetailsCall(details.data)
.then(response => {
component.setStatus('ready');
handleResponse(response, component);
})
.catch(error => {
throw Error(error);
export async function handleAdditionalDetails(state, component, actions) {
try {
const { resultCode, action, order, donationToken } = await makeDetailsCall(state.data);

if (!resultCode) actions.reject();

actions.resolve({
resultCode,
action,
order,
donationToken
});
} catch (error) {
console.error('## onAdditionalDetails - critical error', error);
actions.reject();
}
}

export function handlePaymentCompleted(data, component) {
component.remove();
alert(data.resultCode);
}
48 changes: 24 additions & 24 deletions packages/e2e/app/src/pages/Cards/Cards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AdyenCheckout, Card } from '@adyen/adyen-web';
import '@adyen/adyen-web/styles/adyen.css';
import { handleSubmit, handleAdditionalDetails, handleError } from '../../handlers';
import { handleSubmit, handleAdditionalDetails, handleError, handlePaymentCompleted } from '../../handlers';
import { amount, shopperLocale, countryCode } from '../../services/commonConfig';
import '../../style.scss';

Expand All @@ -15,35 +15,35 @@ const initCheckout = async () => {
showPayButton: true,
onSubmit: handleSubmit,
onAdditionalDetails: handleAdditionalDetails,
onPaymentCompleted: handlePaymentCompleted,
onError: handleError,
...window.mainConfiguration
});

// Credit card with installments
window.card = new Card({
core: checkout,
brands: ['mc', 'visa', 'amex', 'maestro', 'bcmc'],
onChange: state => {
/**
* Needed now that, for v5, we enhance the securedFields state.errors object with a rootNode prop
* - Testcafe doesn't like a ClientFunction retrieving an object with a DOM node in it!?
*
* AND, for some reason, if you place this onChange function in expiryDate.clientScripts.js it doesn't always get read.
* It'll work when it's part of a small batch but if part of the full test suite it gets ignored - so the tests that rely on
* window.mappedStateErrors fail
*/
if (!!Object.keys(state.errors).length) {
// Replace any rootNode values in the objects in state.errors with an empty string
const nuErrors = Object.entries(state.errors).reduce((acc, [fieldType, error]) => {
acc[fieldType] = error ? { ...error, rootNode: '' } : error;
return acc;
}, {});
window.mappedStateErrors = nuErrors;
}
},
...window.cardConfig
})
.mount('.card-field');
core: checkout,
brands: ['mc', 'visa', 'amex', 'maestro', 'bcmc'],
onChange: state => {
/**
* Needed now that, for v5, we enhance the securedFields state.errors object with a rootNode prop
* - Testcafe doesn't like a ClientFunction retrieving an object with a DOM node in it!?
*
* AND, for some reason, if you place this onChange function in expiryDate.clientScripts.js it doesn't always get read.
* It'll work when it's part of a small batch but if part of the full test suite it gets ignored - so the tests that rely on
* window.mappedStateErrors fail
*/
if (!!Object.keys(state.errors).length) {
// Replace any rootNode values in the objects in state.errors with an empty string
const nuErrors = Object.entries(state.errors).reduce((acc, [fieldType, error]) => {
acc[fieldType] = error ? { ...error, rootNode: '' } : error;
return acc;
}, {});
window.mappedStateErrors = nuErrors;
}
},
...window.cardConfig
}).mount('.card-field');
};

initCheckout();
Loading