@infosoftas/s4-orders-js-sdk 0.1.21 → 0.2.0
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 +8 -8
- package/.release-it.json +10 -10
- package/README.md +565 -471
- package/package.json +62 -58
- package/src/App.completion.test.tsx +738 -0
- package/src/App.tsx +753 -639
- package/src/ErrorBoundary.tsx +41 -41
- package/src/api/InvoiceApi.ts +23 -23
- package/src/api/OrdersApi.ts +74 -59
- package/src/api/SubscribeApi.ts +18 -18
- package/src/bundle.ts +4 -4
- package/src/components/Alert/Alert.tsx +23 -23
- package/src/components/Button/Button.tsx +39 -39
- package/src/components/EHFForm/EHFForm.tsx +253 -253
- package/src/components/FormFields/AddressField.tsx +55 -55
- package/src/components/FormFields/EmailField.tsx +53 -53
- package/src/components/FormFields/FormFields.helper.ts +34 -34
- package/src/components/FormFields/FormFieldsMapper.ts +34 -34
- package/src/components/FormFields/InputField.tsx +52 -52
- package/src/components/FormFields/NameField.tsx +52 -52
- package/src/components/FormFields/PhoneField.tsx +53 -53
- package/src/components/FormFields/TermsCheckbox.tsx +70 -70
- package/src/components/FormFields/ToggleFiled.tsx +52 -52
- package/src/components/FormFields/fieldValidators.ts +71 -71
- package/src/components/MainIframe/MainIframe.tsx +42 -42
- package/src/components/OIOForm/OIOForm.tsx +307 -307
- package/src/components/OrderDenialModal/OrderDenialModal.tsx +102 -102
- package/src/components/OrderForm/ContactDetailsSection.tsx +71 -71
- package/src/components/OrderForm/OrderForm.tsx +420 -420
- package/src/components/OrderForm/PaymentMethodContent.tsx +62 -62
- package/src/components/OrderForm/PaymentMethodSection.tsx +79 -79
- package/src/components/OrderForm/SubmitConfirmationDialog.tsx +55 -55
- package/src/components/OrderForm/orderFormState.ts +171 -171
- package/src/components/OrderForm/useSlotElement.tsx +89 -89
- package/src/constants/index.ts +13 -13
- package/src/enums/api.ts +5 -5
- package/src/enums/general.ts +40 -40
- package/src/hooks/useIframe.tsx +59 -59
- package/src/hooks/useMessageEvent.tsx +194 -194
- package/src/hooks/useOrderForm.tsx +403 -403
- package/src/hooks/useQueryParams.ts +5 -5
- package/src/index.tsx +30 -30
- package/src/lib/utils.ts +1 -1
- package/src/types/api.ts +28 -28
- package/src/types/general.ts +154 -136
- package/src/types/order.ts +91 -70
- package/src/utils/fetcher.ts +131 -113
- package/src/utils/helper.ts +78 -78
- package/src/utils/order.helper.ts +272 -272
- package/src/utils/waitForOrderCompletion.ts +125 -0
- package/tsconfig.json +38 -38
package/src/hooks/useIframe.tsx
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
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
|
+
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 +1,194 @@
|
|
|
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;
|
|
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;
|