@sonic-equipment/ui 248.0.2 → 249.0.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.
|
@@ -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 } from '../../../../logging/logger.js';
|
|
9
|
+
import { logger, consoleLogger } 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';
|
|
@@ -18,7 +18,7 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
|
|
|
18
18
|
const t = useFormattedMessage();
|
|
19
19
|
const cultureCode = useCultureCode();
|
|
20
20
|
// Get and remove Adyen query string params and keep them in a ref
|
|
21
|
-
const queryStringParams = useRef(
|
|
21
|
+
const queryStringParams = useRef(getAdyenQueryParams());
|
|
22
22
|
const { amount: adyenAmount, customerId: adyenCustomerId, redirectResult, } = queryStringParams.current;
|
|
23
23
|
const dropinDivRef = useRef(null);
|
|
24
24
|
const { data: adyenSettings } = useFetchAdyenConfig();
|
|
@@ -98,19 +98,27 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
|
|
|
98
98
|
},
|
|
99
99
|
showPayButton: false,
|
|
100
100
|
};
|
|
101
|
+
let removeParamsTimeout = null;
|
|
101
102
|
(async function loadAdyen() {
|
|
102
103
|
if (!dropinDivRef.current)
|
|
103
104
|
return;
|
|
104
105
|
const checkout = await AdyenCheckout(options);
|
|
105
106
|
const dropIn = checkout.create('dropin');
|
|
106
|
-
if (redirectResult)
|
|
107
|
+
if (redirectResult) {
|
|
107
108
|
checkout.submitDetails({ details: { redirectResult } });
|
|
109
|
+
removeParamsTimeout = setTimeout(removeAdyenQueryParamsFromUrl, 0);
|
|
110
|
+
}
|
|
108
111
|
// Remove Adyen query strings params from ref
|
|
109
|
-
queryStringParams.current = {}
|
|
112
|
+
// queryStringParams.current = {}
|
|
110
113
|
if (dropinRef.current)
|
|
111
114
|
dropinRef.current.unmount();
|
|
112
115
|
dropinRef.current = dropIn.mount(dropinDivRef.current);
|
|
113
116
|
})();
|
|
117
|
+
return () => {
|
|
118
|
+
if (removeParamsTimeout) {
|
|
119
|
+
clearTimeout(removeParamsTimeout);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
114
122
|
}, [
|
|
115
123
|
customerId,
|
|
116
124
|
adyenSettings,
|
|
@@ -135,21 +143,23 @@ function AdyenPayment({ amount, cartId, countryCode, currencyCode, customerId, d
|
|
|
135
143
|
}
|
|
136
144
|
return (jsx("div", { ref: dropinDivRef, className: clsx(Boolean(redirectResult) && styles.loading, isDisabled && styles.loading), id: "dropin" }));
|
|
137
145
|
}
|
|
138
|
-
function
|
|
146
|
+
function getAdyenQueryParams() {
|
|
139
147
|
if (typeof window === 'undefined')
|
|
140
148
|
return {};
|
|
141
149
|
const params = qs.parse(window.location.search || '');
|
|
142
150
|
const { amount, customerId, redirectResult } = params;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
// eslint-disable-next-line no-console
|
|
152
|
+
console.log('adyenQueryParam', { amount, customerId, redirectResult });
|
|
153
|
+
return {
|
|
154
|
+
amount: typeof amount === 'string' ? amount : undefined,
|
|
155
|
+
customerId: typeof customerId === 'string' ? customerId : undefined,
|
|
156
|
+
redirectResult: typeof redirectResult === 'string' ? redirectResult : undefined,
|
|
157
|
+
};
|
|
150
158
|
}
|
|
151
159
|
async function handlePaymentResponse(result, onSubmit, onError) {
|
|
152
160
|
try {
|
|
161
|
+
// eslint-disable-next-line no-console
|
|
162
|
+
console.log({ result });
|
|
153
163
|
if (result.action) {
|
|
154
164
|
if (result.action.type === 'redirect') {
|
|
155
165
|
return handleRedirectPaymentAction(result);
|
|
@@ -177,6 +187,20 @@ async function handlePaymentResponse(result, onSubmit, onError) {
|
|
|
177
187
|
onError(error, result);
|
|
178
188
|
}
|
|
179
189
|
}
|
|
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
|
+
}
|
|
180
204
|
function handleRedirectPaymentAction(adyenPaymentResult) {
|
|
181
205
|
if (typeof window === 'undefined' || typeof document === 'undefined')
|
|
182
206
|
return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs, jsx
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
4
4
|
import { Form } from 'react-aria-components';
|
|
5
5
|
import { useAlgoliaInsights } from '../../../../algolia/use-algolia-insights.js';
|
|
@@ -244,11 +244,11 @@ function Payment({ atp, cart: _cart, form, isProcessing, onError: _onError, onPa
|
|
|
244
244
|
MA: t('industry.MA'),
|
|
245
245
|
OT: t('industry.OT'),
|
|
246
246
|
/* eslint-enable sort-keys-fix/sort-keys-fix */
|
|
247
|
-
}, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "customerVatNumber" }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
247
|
+
}, placeholder: t('Select an industry'), variant: "solid" }), jsx(TextField, { showLabel: true, defaultValue: cart.customerVatNumber, isDisabled: isDisabled, label: t('VAT Number'), minLength: 8, name: "customerVatNumber" }, `vat${Boolean(validationErrors.customerVatNumber)}`), jsx(TextField, { showLabel: true, defaultValue: cart.poNumber, isDisabled: isDisabled, isRequired: cart.requiresPoNumber, label: t('PO Number'), name: "poNumber" }), paymentMethodOptions && Object.keys(paymentMethodOptions).length > 1 && (jsx(Select, { "data-test-selector": "paymentMethodSelect", defaultSelectedOption: cart.paymentOptions?.paymentMethods?.[0]?.name || 'ADY', isDisabled: isDisabled, label: t('Payment method'), name: "paymentMethod", onChange: setSelectedPaymentMethod, options: paymentMethodOptions, selectedOption: selectedPaymentMethod, variant: "solid" })), isAdyenPayment && cart.billTo && (jsx(AdyenPayment, { amount: cart.orderGrandTotal, cartId: cart.trackId, countryCode: countryCode, currencyCode: currencyCode, customerId: cart.billTo.id, dropinRef: dropinRef, environment: isProductionEnvironment ? 'live' : 'test', isDisabled: isDisabled, onComplete: onComplete, onError: onError, orderAmount: cart.orderGrandTotal, returnUrl:
|
|
248
|
+
/* eslint-disable ssr-friendly/no-dom-globals-in-react-fc */
|
|
249
|
+
typeof window === 'undefined'
|
|
250
|
+
? ''
|
|
251
|
+
: `${window.location.pathname}${window.location.search}` })), Boolean(paymentError) && (jsx("div", { className: styles['error-message'], children: jsx(FormattedMessage, { id: "An error occurred while processing your payment. Please try again." }) })), jsx(InfoDisplay, { id: "shipping-and-invoice-information", label: t('Billing and shipping address'), value: jsx(Accordion, { variant: "select", children: jsx(AccordionItem, { "data-test-selector": "billingAndShippingInformation", id: "invoice-and-shipping", isDisabled: isDisabled, title: t('Billing and shipping information'), children: jsx(BillingAndInvoiceInformation, { billToAddress: cart.billTo && {
|
|
252
252
|
address1: cart.billTo.address1,
|
|
253
253
|
address2: cart.billTo.address2,
|
|
254
254
|
address3: cart.billTo.address3,
|