@sonic-equipment/ui 257.0.0 → 258.0.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/dist/index.js +1 -1
- package/dist/pages/checkout/payment-page/components/adyen-payment.d.ts +9 -0
- package/dist/pages/checkout/payment-page/components/adyen-payment.js +3 -28
- package/dist/pages/checkout/payment-page/components/payment.js +18 -8
- package/dist/pages/checkout/payment-page/payment-page.js +7 -1
- package/dist/shared/ga/data-layer.js +0 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -237,7 +237,7 @@ export { CheckoutPageSectionHeader } from './pages/checkout/layouts/checkout-pag
|
|
|
237
237
|
export { CheckoutPageSectionLink } from './pages/checkout/layouts/checkout-page-layout/components/checkout-page-section-link.js';
|
|
238
238
|
export { OrderConfirmationPage } from './pages/checkout/order-confirmation-page/order-confirmation-page.js';
|
|
239
239
|
export { OrderConfirmationPageContent } from './pages/checkout/order-confirmation-page/order-confirmation-page-content.js';
|
|
240
|
-
export { AdyenPayment } from './pages/checkout/payment-page/components/adyen-payment.js';
|
|
240
|
+
export { AdyenPayment, getAdyenQueryParams } from './pages/checkout/payment-page/components/adyen-payment.js';
|
|
241
241
|
export { Payment } from './pages/checkout/payment-page/components/payment.js';
|
|
242
242
|
export { useGetAdyenRedirectResult } from './pages/checkout/payment-page/hooks/use-get-adyen-redirect-result.js';
|
|
243
243
|
export { useHasReturnedFromAdyen } from './pages/checkout/payment-page/hooks/use-has-returned-from-adyen.js';
|
|
@@ -18,4 +18,13 @@ interface AdyenPaymentProps {
|
|
|
18
18
|
returnUrl: string;
|
|
19
19
|
}
|
|
20
20
|
export declare function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, dropinRef, environment, isDisabled, onComplete, onError, orderAmount, returnUrl, }: AdyenPaymentProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function getAdyenQueryParams(): {
|
|
22
|
+
amount?: undefined;
|
|
23
|
+
customerId?: undefined;
|
|
24
|
+
redirectResult?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
amount: string | undefined;
|
|
27
|
+
customerId: string | undefined;
|
|
28
|
+
redirectResult: string | undefined;
|
|
29
|
+
};
|
|
21
30
|
export {};
|
|
@@ -6,7 +6,7 @@ import clsx from 'clsx';
|
|
|
6
6
|
import qs from 'query-string';
|
|
7
7
|
import { useCultureCode } from '../../../../intl/use-culture-code.js';
|
|
8
8
|
import { useFormattedMessage } from '../../../../intl/use-formatted-message.js';
|
|
9
|
-
import { logger
|
|
9
|
+
import { logger } from '../../../../logging/logger.js';
|
|
10
10
|
import { Message } from '../../../../message/message.js';
|
|
11
11
|
import { useCreateAdyenSession } from '../../../../shared/api/storefront/hooks/payment/use-create-adyen-session.js';
|
|
12
12
|
import { useFetchAdyenConfig } from '../../../../shared/api/storefront/hooks/payment/use-fetch-adyen-config.js';
|
|
@@ -98,7 +98,6 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
|
|
|
98
98
|
},
|
|
99
99
|
showPayButton: false,
|
|
100
100
|
};
|
|
101
|
-
let removeParamsTimeout = null;
|
|
102
101
|
(async function loadAdyen() {
|
|
103
102
|
if (!dropinDivRef.current)
|
|
104
103
|
return;
|
|
@@ -106,19 +105,11 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
|
|
|
106
105
|
const dropIn = checkout.create('dropin');
|
|
107
106
|
if (redirectResult) {
|
|
108
107
|
checkout.submitDetails({ details: { redirectResult } });
|
|
109
|
-
removeParamsTimeout = setTimeout(removeAdyenQueryParamsFromUrl, 0);
|
|
110
108
|
}
|
|
111
|
-
// Remove Adyen query strings params from ref
|
|
112
|
-
// queryStringParams.current = {}
|
|
113
109
|
if (dropinRef.current)
|
|
114
110
|
dropinRef.current.unmount();
|
|
115
111
|
dropinRef.current = dropIn.mount(dropinDivRef.current);
|
|
116
112
|
})();
|
|
117
|
-
return () => {
|
|
118
|
-
if (removeParamsTimeout) {
|
|
119
|
-
clearTimeout(removeParamsTimeout);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
113
|
}, [
|
|
123
114
|
customerId,
|
|
124
115
|
adyenSettings,
|
|
@@ -141,15 +132,13 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
|
|
|
141
132
|
logger.error('Adyen Payment Error:', error);
|
|
142
133
|
return (jsx(Message, { type: "danger", children: t('All payment methods are unavailable at this time. Please contact customer support.') }));
|
|
143
134
|
}
|
|
144
|
-
return (jsx("div", { ref: dropinDivRef, className: clsx(
|
|
135
|
+
return (jsx("div", { ref: dropinDivRef, className: clsx(isDisabled && styles.loading), id: "dropin" }));
|
|
145
136
|
}
|
|
146
137
|
function getAdyenQueryParams() {
|
|
147
138
|
if (typeof window === 'undefined')
|
|
148
139
|
return {};
|
|
149
140
|
const params = qs.parse(window.location.search || '');
|
|
150
141
|
const { amount, customerId, redirectResult } = params;
|
|
151
|
-
// eslint-disable-next-line no-console
|
|
152
|
-
console.log('adyenQueryParam', { amount, customerId, redirectResult });
|
|
153
142
|
return {
|
|
154
143
|
amount: typeof amount === 'string' ? amount : undefined,
|
|
155
144
|
customerId: typeof customerId === 'string' ? customerId : undefined,
|
|
@@ -187,20 +176,6 @@ async function handlePaymentResponse(result, onSubmit, onError) {
|
|
|
187
176
|
onError(error, result);
|
|
188
177
|
}
|
|
189
178
|
}
|
|
190
|
-
function removeAdyenQueryParamsFromUrl() {
|
|
191
|
-
if (typeof window === 'undefined')
|
|
192
|
-
return;
|
|
193
|
-
try {
|
|
194
|
-
const url = new URL(window.location.href);
|
|
195
|
-
url.searchParams.delete('amount');
|
|
196
|
-
url.searchParams.delete('customerId');
|
|
197
|
-
url.searchParams.delete('redirectResult');
|
|
198
|
-
window.history.replaceState(null, '', url.toString());
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
consoleLogger.error(error);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
179
|
function handleRedirectPaymentAction(adyenPaymentResult) {
|
|
205
180
|
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
206
181
|
return;
|
|
@@ -223,4 +198,4 @@ function handleRedirectPaymentAction(adyenPaymentResult) {
|
|
|
223
198
|
}
|
|
224
199
|
}
|
|
225
200
|
|
|
226
|
-
export { AdyenPayment };
|
|
201
|
+
export { AdyenPayment, getAdyenQueryParams };
|
|
@@ -22,10 +22,23 @@ import { useDataLayer } from '../../../../shared/ga/use-data-layer.js';
|
|
|
22
22
|
import { getCurrencyCodeBySymbol } from '../../../../shared/model/currency.js';
|
|
23
23
|
import { isProductionEnvironment } from '../../../../shared/utils/environment.js';
|
|
24
24
|
import { BillingAndInvoiceInformation } from '../../components/billing-and-invoice-information.js';
|
|
25
|
-
import { useHasReturnedFromAdyen } from '../hooks/use-has-returned-from-adyen.js';
|
|
26
25
|
import { AdyenPayment } from './adyen-payment.js';
|
|
27
26
|
import styles from './payment.module.css.js';
|
|
28
27
|
|
|
28
|
+
function removeAdyenQueryParamsFromUrl() {
|
|
29
|
+
if (typeof window === 'undefined')
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
const url = new URL(window.location.href);
|
|
33
|
+
url.searchParams.delete('amount');
|
|
34
|
+
url.searchParams.delete('customerId');
|
|
35
|
+
url.searchParams.delete('redirectResult');
|
|
36
|
+
window.history.replaceState(null, '', url.toString());
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
logger.error(error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
29
42
|
function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPaymentComplete, onProcessing, }) {
|
|
30
43
|
const { createEcommerceEvent, dataLayer } = useDataLayer();
|
|
31
44
|
const { mutate: patchCart } = usePatchCart();
|
|
@@ -33,7 +46,6 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
33
46
|
const { sendPurchaseEventFromPaymentPage } = useAlgoliaInsights();
|
|
34
47
|
const invalidateCurrentCart = useInvalidateCurrentCart();
|
|
35
48
|
const dropinRef = useRef(null);
|
|
36
|
-
const hasReturnedFromAdyen = useHasReturnedFromAdyen();
|
|
37
49
|
const [paymentError, setPaymentError] = useState();
|
|
38
50
|
const [apiError, setAPIError] = useState();
|
|
39
51
|
const invalidateAdyen = useInvalidateAdyen();
|
|
@@ -41,7 +53,7 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
41
53
|
const cartRef = useRef(_cart);
|
|
42
54
|
const cart = cartRef.current;
|
|
43
55
|
const hasAtp = atp.length > 1;
|
|
44
|
-
const [asSoonAsPossible, setAsSoonAsPossible] = useState(!hasAtp || (
|
|
56
|
+
const [asSoonAsPossible, setAsSoonAsPossible] = useState(!hasAtp || (!isProcessing && !cart.requestedDeliveryDate));
|
|
45
57
|
const [deliveryDate, setDeliveryDate] = useState(cart.requestedDeliveryDateDisplay?.toString() || '');
|
|
46
58
|
const [selectedPaymentMethod, setSelectedPaymentMethod] = useState(cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY');
|
|
47
59
|
if (!isCountryCode(_cart.billTo?.country?.abbreviation))
|
|
@@ -55,11 +67,6 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
55
67
|
cart.billTo?.id &&
|
|
56
68
|
countryCode;
|
|
57
69
|
const isDisabled = isProcessing;
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (!hasReturnedFromAdyen)
|
|
60
|
-
return;
|
|
61
|
-
onProcessing(true);
|
|
62
|
-
}, [hasReturnedFromAdyen, onProcessing]);
|
|
63
70
|
useEffect(() => {
|
|
64
71
|
cartRef.current = _cart;
|
|
65
72
|
}, [_cart]);
|
|
@@ -163,6 +170,7 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
163
170
|
}
|
|
164
171
|
finally {
|
|
165
172
|
onProcessing(false);
|
|
173
|
+
removeAdyenQueryParamsFromUrl();
|
|
166
174
|
}
|
|
167
175
|
}
|
|
168
176
|
else {
|
|
@@ -184,6 +192,7 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
184
192
|
}
|
|
185
193
|
finally {
|
|
186
194
|
onProcessing(false);
|
|
195
|
+
removeAdyenQueryParamsFromUrl();
|
|
187
196
|
}
|
|
188
197
|
}
|
|
189
198
|
}
|
|
@@ -216,6 +225,7 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
216
225
|
}
|
|
217
226
|
finally {
|
|
218
227
|
onProcessing(false);
|
|
228
|
+
removeAdyenQueryParamsFromUrl();
|
|
219
229
|
}
|
|
220
230
|
}, [onPaymentComplete, onPlaceOrderCompleted, onProcessing, placeOrder]);
|
|
221
231
|
const onError = useCallback((error, result) => {
|
|
@@ -21,11 +21,17 @@ function PaymentPage({ hasReturnedFromAdyen, }) {
|
|
|
21
21
|
const { data: atp, isLoading: isAtpLoading } = useFetchCurrentCheckoutAtp();
|
|
22
22
|
const hasAtp = atp !== undefined && atp.length > 1;
|
|
23
23
|
const isLoading = isLoadingCart || isAtpLoading;
|
|
24
|
-
const [isProcessing, setIsProcessing] = useState(false);
|
|
24
|
+
const [isProcessing, setIsProcessing] = useState(hasReturnedFromAdyen ?? false);
|
|
25
25
|
const { isNavigating, navigate } = useNavigate();
|
|
26
26
|
const onPaymentComplete = useCallback(({ cartId }) => {
|
|
27
27
|
navigate(`${paths.ORDER_CONFIRMATION}?cartId=${cartId}`);
|
|
28
28
|
}, [navigate, paths]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const setProcessingOn = async () => setIsProcessing(true);
|
|
31
|
+
if (hasReturnedFromAdyen) {
|
|
32
|
+
setProcessingOn();
|
|
33
|
+
}
|
|
34
|
+
}, [hasReturnedFromAdyen, setIsProcessing]);
|
|
29
35
|
useEffect(() => {
|
|
30
36
|
if (isNavigating)
|
|
31
37
|
return;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { logger } from '../../logging/logger.js';
|
|
2
|
-
|
|
3
1
|
const _dataLayer = [];
|
|
4
2
|
_dataLayer.push = (function (_push) {
|
|
5
3
|
return (...items) => {
|
|
6
|
-
logger.info('dataLayer.push', items.length === 1 ? items[0] : items);
|
|
7
4
|
return _push(...items);
|
|
8
5
|
};
|
|
9
6
|
})(_dataLayer.push.bind(_dataLayer));
|