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

Adding config props to stories #2802

Merged
merged 12 commits into from
Aug 26, 2024
Prev Previous commit
Next Next commit
CustomCard handles payments result, including 3DS2 action
sponglord committed Aug 21, 2024
commit 835b4de45b119f2f8dc01971dc35db1b3037d80c
35 changes: 33 additions & 2 deletions packages/lib/storybook/stories/CustomCardContainer.tsx
Original file line number Diff line number Diff line change
@@ -39,13 +39,44 @@ export const CustomCardContainer = ({ element, context }) => {
}
})
.then(result => {
// handlePaymentResult(result, component);
handlePaymentResult(result, component);
})
.catch(error => {
throw Error(error);
});
};

const handlePaymentResult = (result, component) => {
console.log('Result: ', result);

if (result.action) {
threeDS2(result, component);
} else {
// @ts-ignore
document.querySelector('.secured-fields').style.display = 'none';

switch (result.resultCode) {
case 'Authorised':
case 'Refused':
document.getElementById('topLevelHolder').innerText = result.resultCode;
break;
default:
}
}
};

const threeDS2 = (result, component) => {
if (window['customCard']) {
const sfNode = document.querySelector('.secured-fields');
// Clear the contents of the .secured-fields div
while (sfNode.firstChild) {
sfNode.removeChild(sfNode.firstChild);
}
}

component.handleAction(result.action);
};

useEffect(() => {
if (!element) return;

@@ -55,7 +86,7 @@ export const CustomCardContainer = ({ element, context }) => {
}, [element]);

return (
<div>
<div id={'topLevelHolder'}>
<div
ref={container}
id="component-root"