@infosoftas/s4-orders-js-sdk 0.1.21 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +0 -0
- package/.release-it.json +0 -0
- package/README.md +572 -471
- package/build/postcss-scope-tailwind.cjs +0 -0
- package/components.json +0 -0
- package/package.json +62 -58
- package/src/App.completion.test.tsx +677 -0
- package/src/App.css +0 -14
- package/src/App.paymentReturn.test.tsx +341 -0
- package/src/App.tsx +722 -639
- package/src/ErrorBoundary.tsx +0 -0
- package/src/api/InvoiceApi.ts +0 -0
- package/src/api/OrdersApi.ts +74 -59
- package/src/api/SubscribeApi.ts +0 -0
- package/src/bundle.ts +0 -0
- package/src/components/Alert/Alert.tsx +0 -0
- package/src/components/Button/Button.tsx +0 -0
- package/src/components/EHFForm/EHFForm.tsx +250 -253
- package/src/components/FormFields/AddressField.tsx +0 -0
- package/src/components/FormFields/EmailField.tsx +0 -0
- package/src/components/FormFields/FormFields.helper.ts +0 -0
- package/src/components/FormFields/FormFieldsMapper.ts +0 -0
- package/src/components/FormFields/InputField.tsx +0 -0
- package/src/components/FormFields/NameField.tsx +0 -0
- package/src/components/FormFields/PhoneField.tsx +0 -0
- package/src/components/FormFields/TermsCheckbox.tsx +0 -0
- package/src/components/FormFields/ToggleFiled.tsx +0 -0
- package/src/components/FormFields/fieldValidators.ts +0 -0
- package/src/components/OIOForm/OIOForm.tsx +304 -307
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +0 -0
- package/src/components/OrderForm/ContactDetailsSection.tsx +0 -0
- package/src/components/OrderForm/OrderForm.tsx +417 -420
- package/src/components/OrderForm/PaymentMethodContent.tsx +0 -0
- package/src/components/OrderForm/PaymentMethodSection.tsx +0 -0
- package/src/components/OrderForm/SubmitConfirmationDialog.tsx +0 -0
- package/src/components/OrderForm/orderFormState.ts +0 -0
- package/src/components/OrderForm/useSlotElement.tsx +0 -0
- package/src/components/ui/alert-dialog.tsx +0 -0
- package/src/components/ui/alert.tsx +0 -0
- package/src/components/ui/button.tsx +0 -0
- package/src/components/ui/card.tsx +0 -0
- package/src/components/ui/checkbox.tsx +0 -0
- package/src/components/ui/field.tsx +0 -0
- package/src/components/ui/input.tsx +0 -0
- package/src/components/ui/label.tsx +0 -0
- package/src/components/ui/radio-group.tsx +0 -0
- package/src/components/ui/separator.tsx +0 -0
- package/src/components/ui/skeleton.tsx +0 -0
- package/src/components/ui/spinner.tsx +0 -0
- package/src/components/ui/switch.tsx +0 -0
- package/src/components/ui/textarea.tsx +0 -0
- package/src/constants/index.ts +0 -0
- package/src/custom.d.ts +0 -0
- package/src/enums/api.ts +0 -0
- package/src/enums/general.ts +42 -40
- package/src/hooks/useOrderForm.tsx +400 -403
- package/src/hooks/usePaymentReturn.tsx +139 -0
- package/src/hooks/useQueryParams.ts +0 -0
- package/src/index.tsx +0 -0
- package/src/lib/utils.ts +0 -0
- package/src/types/api.ts +0 -0
- package/src/types/general.ts +153 -136
- package/src/types/order.ts +91 -70
- package/src/utils/fetcher.ts +131 -113
- package/src/utils/helper.ts +0 -0
- package/src/utils/order.helper.test.ts +81 -0
- package/src/utils/order.helper.ts +285 -272
- package/src/utils/waitForOrderCompletion.ts +125 -0
- package/tsconfig.json +39 -38
- package/src/components/MainIframe/MainIframe.tsx +0 -42
- package/src/hooks/useIframe.tsx +0 -59
- package/src/hooks/useMessageEvent.tsx +0 -194
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getOrderStatus } from '../api/OrdersApi';
|
|
2
|
+
|
|
3
|
+
type CompletionResult =
|
|
4
|
+
| { status: 'Completed' | 'Cancelled' | 'Rejected' | 'Aborted' }
|
|
5
|
+
| { status: 'Pending'; reason: 'timeout' | 'statusUnavailable' };
|
|
6
|
+
|
|
7
|
+
const retryDelay = (retryAfter?: string | null): number => {
|
|
8
|
+
if (!retryAfter) {
|
|
9
|
+
// Cross-origin APIs may not expose Retry-After. Do not retry blindly.
|
|
10
|
+
return 10000;
|
|
11
|
+
}
|
|
12
|
+
const seconds = Number(retryAfter);
|
|
13
|
+
if (Number.isFinite(seconds) && !/^\d+$/.test(retryAfter)) {
|
|
14
|
+
return 10000;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const delay = Number.isFinite(seconds)
|
|
18
|
+
? seconds * 1000
|
|
19
|
+
: Date.parse(retryAfter) - Date.now();
|
|
20
|
+
return Number.isFinite(delay) ? Math.max(500, delay) : 10000;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const pause = (delay: number, signal: AbortSignal): Promise<void> =>
|
|
24
|
+
new Promise((resolve) => {
|
|
25
|
+
const done = () => {
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
signal.removeEventListener('abort', done);
|
|
28
|
+
resolve();
|
|
29
|
+
};
|
|
30
|
+
const timer = setTimeout(done, delay);
|
|
31
|
+
signal.addEventListener('abort', done, { once: true });
|
|
32
|
+
if (signal.aborted) {
|
|
33
|
+
done();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const waitForOrderCompletion = async (
|
|
38
|
+
orderId: string,
|
|
39
|
+
signal: AbortSignal
|
|
40
|
+
): Promise<CompletionResult> => {
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
let timedOut = false;
|
|
43
|
+
const abort = () => controller.abort();
|
|
44
|
+
const deadline = Date.now() + 10000;
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
timedOut = true;
|
|
47
|
+
controller.abort();
|
|
48
|
+
}, 10000);
|
|
49
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
50
|
+
|
|
51
|
+
const aborted = (): CompletionResult =>
|
|
52
|
+
timedOut
|
|
53
|
+
? { status: 'Pending', reason: 'timeout' }
|
|
54
|
+
: { status: 'Aborted' };
|
|
55
|
+
let onAbort!: () => void;
|
|
56
|
+
const cancellation = new Promise<CompletionResult>((resolve) => {
|
|
57
|
+
onAbort = () => resolve(aborted());
|
|
58
|
+
controller.signal.addEventListener('abort', onAbort, { once: true });
|
|
59
|
+
});
|
|
60
|
+
if (signal.aborted) {
|
|
61
|
+
controller.abort();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const poll = async (): Promise<CompletionResult> => {
|
|
65
|
+
while (!controller.signal.aborted && Date.now() < deadline) {
|
|
66
|
+
let delay = 500;
|
|
67
|
+
try {
|
|
68
|
+
const order = await getOrderStatus(orderId, controller.signal);
|
|
69
|
+
if (controller.signal.aborted) {
|
|
70
|
+
return aborted();
|
|
71
|
+
}
|
|
72
|
+
if (Date.now() >= deadline) {
|
|
73
|
+
return { status: 'Pending', reason: 'timeout' };
|
|
74
|
+
}
|
|
75
|
+
if (order?.id !== orderId) {
|
|
76
|
+
return { status: 'Pending', reason: 'statusUnavailable' };
|
|
77
|
+
}
|
|
78
|
+
switch (order.status) {
|
|
79
|
+
case 'Completed':
|
|
80
|
+
case 'Cancelled':
|
|
81
|
+
case 'Rejected':
|
|
82
|
+
return { status: order.status };
|
|
83
|
+
case 'Created':
|
|
84
|
+
case 'InProgress':
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
return {
|
|
88
|
+
status: 'Pending',
|
|
89
|
+
reason: 'statusUnavailable',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (controller.signal.aborted) {
|
|
94
|
+
return aborted();
|
|
95
|
+
}
|
|
96
|
+
const { status, retryAfter } = (error || {}) as {
|
|
97
|
+
status?: number;
|
|
98
|
+
retryAfter?: string;
|
|
99
|
+
};
|
|
100
|
+
if (status === 429) {
|
|
101
|
+
delay = retryDelay(retryAfter);
|
|
102
|
+
} else if (status && status !== 404 && status < 500) {
|
|
103
|
+
return { status: 'Pending', reason: 'statusUnavailable' };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
await pause(
|
|
107
|
+
Math.min(delay, deadline - Date.now()),
|
|
108
|
+
controller.signal
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return signal.aborted
|
|
112
|
+
? { status: 'Aborted' }
|
|
113
|
+
: { status: 'Pending', reason: 'timeout' };
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
// Race also bounds transports that do not settle when their signal aborts.
|
|
118
|
+
return await Promise.race([poll(), cancellation]);
|
|
119
|
+
} finally {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
signal.removeEventListener('abort', abort);
|
|
122
|
+
controller.signal.removeEventListener('abort', onAbort);
|
|
123
|
+
controller.abort();
|
|
124
|
+
}
|
|
125
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022",
|
|
4
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"checkJs": false,
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"allowSyntheticDefaultImports": true,
|
|
10
|
-
"strict": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"noFallthroughCasesInSwitch": true,
|
|
13
|
-
"module": "esnext",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"API
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"checkJs": false,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"allowSyntheticDefaultImports": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"noFallthroughCasesInSwitch": true,
|
|
13
|
+
"module": "esnext",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"moduleResolution": "bundler",
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"verbatimModuleSyntax": true,
|
|
18
|
+
"noEmit": false,
|
|
19
|
+
"noImplicitAny": true,
|
|
20
|
+
"jsx": "react-jsx",
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
"inlineSources": true,
|
|
23
|
+
"sourceRoot": "/",
|
|
24
|
+
"paths": {
|
|
25
|
+
"@/*": ["./src/*"],
|
|
26
|
+
"API": ["./src/api"],
|
|
27
|
+
"API/*": ["./src/api/*"],
|
|
28
|
+
"Component/*": ["./src/components/*"],
|
|
29
|
+
"Utils/*": ["./src/utils/*"],
|
|
30
|
+
"Hooks/*": ["./src/hooks/*"],
|
|
31
|
+
"Models/*": ["./src/models/*"],
|
|
32
|
+
"Types/*": ["./src/types/*"],
|
|
33
|
+
"Enums/*": ["./src/enums/*"],
|
|
34
|
+
"Constants/*": ["./src/constants/*"]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"include": ["src"],
|
|
38
|
+
"exclude": ["node_modules"]
|
|
39
|
+
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { type FC, useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import useIframe from '../../hooks/useIframe';
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
iframeSrc: string | null;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const MainIframe: FC<Props> = ({ iframeSrc }) => {
|
|
10
|
-
const [loading, setLoading] = useState(false);
|
|
11
|
-
|
|
12
|
-
const { frameRef, messageReceiver } = useIframe();
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (frameRef && iframeSrc) {
|
|
16
|
-
setLoading(true);
|
|
17
|
-
frameRef?.current &&
|
|
18
|
-
(frameRef?.current as HTMLIFrameElement).addEventListener(
|
|
19
|
-
'load',
|
|
20
|
-
() => {
|
|
21
|
-
setLoading(false);
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
messageReceiver();
|
|
25
|
-
}
|
|
26
|
-
}, [frameRef, iframeSrc]);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<div className="sdk-iframe-wrapper" data-testid="sdk-iframe-id">
|
|
30
|
-
{loading && <div>... Loading</div>}
|
|
31
|
-
{iframeSrc && (
|
|
32
|
-
<iframe
|
|
33
|
-
ref={frameRef}
|
|
34
|
-
src={iframeSrc}
|
|
35
|
-
style={{ minHeight: '830px', width: '100%' }}
|
|
36
|
-
></iframe>
|
|
37
|
-
)}
|
|
38
|
-
</div>
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default MainIframe;
|
package/src/hooks/useIframe.tsx
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
let currentMessageReceiver: (event: Event) => void;
|
|
4
|
-
|
|
5
|
-
const useIframe = () => {
|
|
6
|
-
const frameRef = useRef(null);
|
|
7
|
-
|
|
8
|
-
const messageReceiver = (
|
|
9
|
-
callback?: (type: string, value: string) => void
|
|
10
|
-
) => {
|
|
11
|
-
if (currentMessageReceiver) {
|
|
12
|
-
window.removeEventListener('message', currentMessageReceiver);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
currentMessageReceiver = (event: Event) => {
|
|
16
|
-
if (!frameRef.current) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const childWindow = (frameRef.current as HTMLIFrameElement)
|
|
21
|
-
.contentWindow;
|
|
22
|
-
|
|
23
|
-
if ((event as MessageEvent).source !== childWindow) {
|
|
24
|
-
return; // Skip message in this event listener
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let { value, type } = (event as MessageEvent).data as unknown as {
|
|
28
|
-
value: string;
|
|
29
|
-
type: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (callback) {
|
|
33
|
-
callback(type, value);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
window.addEventListener('message', currentMessageReceiver, false);
|
|
38
|
-
|
|
39
|
-
return () => {
|
|
40
|
-
removeMessageReceiver();
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const removeMessageReceiver = () => {
|
|
45
|
-
if (currentMessageReceiver) {
|
|
46
|
-
window.removeEventListener(
|
|
47
|
-
'addEventListener',
|
|
48
|
-
currentMessageReceiver
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
frameRef,
|
|
55
|
-
messageReceiver,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default useIframe;
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback } from 'react';
|
|
2
|
-
|
|
3
|
-
import { MessageEventTypeEnum, PaymentMethodEnum } from '../enums/general';
|
|
4
|
-
import type { CompleteOrderParamsType, OrderInfoType } from '../types/order';
|
|
5
|
-
import useQueryParams from './useQueryParams';
|
|
6
|
-
|
|
7
|
-
const MOLLIE_ORDER_TTL_MS = 20 * 60 * 1000;
|
|
8
|
-
|
|
9
|
-
// Reads and consumes the persisted Mollie order id. The key is always removed:
|
|
10
|
-
// the return leg gets one chance to use it, whether or not it is still valid.
|
|
11
|
-
const takeStoredMollieOrderId = (): string | null => {
|
|
12
|
-
const raw = sessionStorage.getItem('mollieOrderId');
|
|
13
|
-
if (!raw) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
sessionStorage.removeItem('mollieOrderId');
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const { id, ts } = JSON.parse(raw) as { id: string; ts: number };
|
|
21
|
-
|
|
22
|
-
return Date.now() - ts <= MOLLIE_ORDER_TTL_MS ? id : null;
|
|
23
|
-
} catch {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const useMessageEvent = (
|
|
29
|
-
messageCallback: (data: CompleteOrderParamsType) => Promise<void>,
|
|
30
|
-
handleMessageEvent: (type: MessageEventTypeEnum, orderId?: string) => void,
|
|
31
|
-
showIframe: boolean,
|
|
32
|
-
orderInfo: OrderInfoType | null
|
|
33
|
-
) => {
|
|
34
|
-
const queryParams = useQueryParams();
|
|
35
|
-
|
|
36
|
-
const handleMessage = useCallback(
|
|
37
|
-
async (event: MessageEvent) => {
|
|
38
|
-
// Vipps handler
|
|
39
|
-
if (event.data.type === MessageEventTypeEnum.VIPPS_COMPLETE) {
|
|
40
|
-
await messageCallback({
|
|
41
|
-
orderId: event.data.orderId || '',
|
|
42
|
-
agreementId: event.data.agreementId || '',
|
|
43
|
-
orderInfo: orderInfo || null,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// SwedbankPay handler
|
|
48
|
-
if (event.data.type === MessageEventTypeEnum.COMPLETE) {
|
|
49
|
-
await messageCallback({
|
|
50
|
-
orderId: event.data.orderId || '',
|
|
51
|
-
agreementId: event.data.agreementId || '',
|
|
52
|
-
orderInfo: orderInfo || null,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (event.data.type === MessageEventTypeEnum.CANCEL) {
|
|
56
|
-
handleMessageEvent(event.data.type);
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
[orderInfo]
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
window.addEventListener('message', handleMessage, false);
|
|
64
|
-
|
|
65
|
-
return () => {
|
|
66
|
-
window.removeEventListener('message', handleMessage, false);
|
|
67
|
-
};
|
|
68
|
-
}, [handleMessage]);
|
|
69
|
-
|
|
70
|
-
// Vipps
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (
|
|
73
|
-
queryParams.get('orderId') &&
|
|
74
|
-
queryParams.get('agreementId') &&
|
|
75
|
-
top &&
|
|
76
|
-
window !== top
|
|
77
|
-
) {
|
|
78
|
-
top?.postMessage(
|
|
79
|
-
{
|
|
80
|
-
type: MessageEventTypeEnum.VIPPS_COMPLETE,
|
|
81
|
-
orderId: queryParams.get('orderId'),
|
|
82
|
-
agreementId: queryParams.get('agreementId'),
|
|
83
|
-
},
|
|
84
|
-
top?.location?.origin || '*'
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}, [queryParams.get('orderId'), queryParams.get('agreementId')]);
|
|
88
|
-
|
|
89
|
-
//Vipps
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (
|
|
92
|
-
queryParams.get('orderId') &&
|
|
93
|
-
queryParams.get('agreementId')
|
|
94
|
-
// !showIframe
|
|
95
|
-
) {
|
|
96
|
-
messageCallback({
|
|
97
|
-
orderId: queryParams.get('orderId') || '',
|
|
98
|
-
agreementId: queryParams.get('agreementId') || '',
|
|
99
|
-
orderInfo: orderInfo || null,
|
|
100
|
-
paymentMethod: PaymentMethodEnum.Vipps,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}, [
|
|
104
|
-
queryParams.get('orderId'),
|
|
105
|
-
queryParams.get('agreementId'),
|
|
106
|
-
// showIframe,
|
|
107
|
-
]);
|
|
108
|
-
|
|
109
|
-
// SwedbankPay
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
if (
|
|
112
|
-
queryParams.get('action') &&
|
|
113
|
-
queryParams.get('S4OrderId') &&
|
|
114
|
-
queryParams.get('TransactionId') &&
|
|
115
|
-
top &&
|
|
116
|
-
window !== top
|
|
117
|
-
) {
|
|
118
|
-
top?.postMessage(
|
|
119
|
-
{
|
|
120
|
-
type: queryParams.get('action'),
|
|
121
|
-
orderId: queryParams.get('S4OrderId'),
|
|
122
|
-
agreementId: queryParams.get('TransactionId'),
|
|
123
|
-
},
|
|
124
|
-
top?.location?.origin || '*'
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}, [
|
|
128
|
-
queryParams.get('S4OrderId'),
|
|
129
|
-
queryParams.get('TransactionId'),
|
|
130
|
-
queryParams.get('action'),
|
|
131
|
-
]);
|
|
132
|
-
|
|
133
|
-
// SwedbankPay
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (
|
|
136
|
-
queryParams.get('S4OrderId') &&
|
|
137
|
-
queryParams.get('TransactionId') &&
|
|
138
|
-
queryParams.get('action') === MessageEventTypeEnum.COMPLETE &&
|
|
139
|
-
!showIframe
|
|
140
|
-
) {
|
|
141
|
-
messageCallback({
|
|
142
|
-
orderId: queryParams.get('S4OrderId') || '',
|
|
143
|
-
agreementId: queryParams.get('TransactionId') || '',
|
|
144
|
-
orderInfo: orderInfo || null,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
queryParams.get('action') === MessageEventTypeEnum.CANCEL &&
|
|
150
|
-
(!showIframe || !queryParams.get('TransactionId'))
|
|
151
|
-
) {
|
|
152
|
-
const cancelOrderId =
|
|
153
|
-
queryParams.get('S4OrderId') || takeStoredMollieOrderId();
|
|
154
|
-
handleMessageEvent(
|
|
155
|
-
queryParams.get('action') as MessageEventTypeEnum,
|
|
156
|
-
cancelOrderId || undefined
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
}, [
|
|
160
|
-
queryParams.get('action'),
|
|
161
|
-
queryParams.get('S4OrderId'),
|
|
162
|
-
queryParams.get('TransactionId'),
|
|
163
|
-
showIframe,
|
|
164
|
-
]);
|
|
165
|
-
|
|
166
|
-
// Mollie: a completion return with no TransactionId (that one is SwedbankPay's).
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
if (
|
|
169
|
-
queryParams.get('action') !== MessageEventTypeEnum.COMPLETE ||
|
|
170
|
-
queryParams.get('TransactionId')
|
|
171
|
-
) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const s4OrderId = queryParams.get('S4OrderId');
|
|
176
|
-
const storedOrderId = takeStoredMollieOrderId();
|
|
177
|
-
const mollieOrderId = s4OrderId || storedOrderId;
|
|
178
|
-
if (!mollieOrderId) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
messageCallback({
|
|
183
|
-
orderId: mollieOrderId,
|
|
184
|
-
agreementId: '',
|
|
185
|
-
orderInfo: orderInfo || null,
|
|
186
|
-
});
|
|
187
|
-
}, [
|
|
188
|
-
queryParams.get('action'),
|
|
189
|
-
queryParams.get('S4OrderId'),
|
|
190
|
-
queryParams.get('TransactionId'),
|
|
191
|
-
]);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
export default useMessageEvent;
|