@reevit/react 0.4.6 → 0.4.8
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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +52 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -3
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +6 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -360,6 +360,36 @@ function mapAvailableProviders(providers) {
|
|
|
360
360
|
};
|
|
361
361
|
}).filter((provider) => provider.methods.length > 0);
|
|
362
362
|
}
|
|
363
|
+
function normalizeBranding(branding) {
|
|
364
|
+
if (!branding) {
|
|
365
|
+
return {};
|
|
366
|
+
}
|
|
367
|
+
const raw = branding;
|
|
368
|
+
const theme = { ...raw };
|
|
369
|
+
const getString = (value) => typeof value === "string" ? value : void 0;
|
|
370
|
+
const getBoolean = (value) => typeof value === "boolean" ? value : void 0;
|
|
371
|
+
const setIf = (key, value) => {
|
|
372
|
+
if (value !== void 0) {
|
|
373
|
+
theme[key] = value;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
setIf("logoUrl", getString(raw.logoUrl ?? raw.logo_url));
|
|
377
|
+
setIf("companyName", getString(raw.companyName ?? raw.company_name));
|
|
378
|
+
setIf("primaryColor", getString(raw.primaryColor ?? raw.primary_color));
|
|
379
|
+
setIf("primaryForegroundColor", getString(raw.primaryForegroundColor ?? raw.primary_foreground_color));
|
|
380
|
+
setIf("backgroundColor", getString(raw.backgroundColor ?? raw.background_color));
|
|
381
|
+
setIf("surfaceColor", getString(raw.surfaceColor ?? raw.surface_color));
|
|
382
|
+
setIf("textColor", getString(raw.textColor ?? raw.text_color));
|
|
383
|
+
setIf("mutedTextColor", getString(raw.mutedTextColor ?? raw.muted_text_color));
|
|
384
|
+
setIf("borderRadius", getString(raw.borderRadius ?? raw.border_radius));
|
|
385
|
+
setIf("fontFamily", getString(raw.fontFamily ?? raw.font_family));
|
|
386
|
+
setIf("darkMode", getBoolean(raw.darkMode ?? raw.dark_mode));
|
|
387
|
+
setIf("pspSelectorBgColor", getString(raw.pspSelectorBgColor ?? raw.psp_selector_bg_color));
|
|
388
|
+
setIf("pspSelectorTextColor", getString(raw.pspSelectorTextColor ?? raw.psp_selector_text_color));
|
|
389
|
+
setIf("pspSelectorBorderColor", getString(raw.pspSelectorBorderColor ?? raw.psp_selector_border_color));
|
|
390
|
+
setIf("pspSelectorUseBorder", getBoolean(raw.pspSelectorUseBorder ?? raw.psp_selector_use_border));
|
|
391
|
+
return theme;
|
|
392
|
+
}
|
|
363
393
|
function mapToPaymentIntent(response, config) {
|
|
364
394
|
return {
|
|
365
395
|
id: response.id,
|
|
@@ -379,7 +409,7 @@ function mapToPaymentIntent(response, config) {
|
|
|
379
409
|
netAmount: response.net_amount,
|
|
380
410
|
metadata: config.metadata,
|
|
381
411
|
availableProviders: mapAvailableProviders(response.available_psps),
|
|
382
|
-
branding: response.branding
|
|
412
|
+
branding: normalizeBranding(response.branding)
|
|
383
413
|
};
|
|
384
414
|
}
|
|
385
415
|
function useReevit(options) {
|
|
@@ -392,6 +422,7 @@ function useReevit(options) {
|
|
|
392
422
|
});
|
|
393
423
|
const apiClientRef = useRef(null);
|
|
394
424
|
const initializingRef = useRef(!!config.initialPaymentIntent);
|
|
425
|
+
const initRequestIdRef = useRef(0);
|
|
395
426
|
useEffect(() => {
|
|
396
427
|
if (config.initialPaymentIntent) {
|
|
397
428
|
if (!state.paymentIntent || state.paymentIntent.id !== config.initialPaymentIntent.id) {
|
|
@@ -415,11 +446,11 @@ function useReevit(options) {
|
|
|
415
446
|
return;
|
|
416
447
|
}
|
|
417
448
|
initializingRef.current = true;
|
|
449
|
+
const requestId = ++initRequestIdRef.current;
|
|
418
450
|
dispatch({ type: "INIT_START" });
|
|
419
451
|
try {
|
|
420
452
|
const apiClient = apiClientRef.current;
|
|
421
453
|
if (!apiClient) {
|
|
422
|
-
initializingRef.current = false;
|
|
423
454
|
throw new Error("API client not initialized");
|
|
424
455
|
}
|
|
425
456
|
const reference = config.reference || generateReference();
|
|
@@ -468,6 +499,9 @@ function useReevit(options) {
|
|
|
468
499
|
data = result.data;
|
|
469
500
|
error = result.error;
|
|
470
501
|
}
|
|
502
|
+
if (requestId !== initRequestIdRef.current) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
471
505
|
if (error) {
|
|
472
506
|
dispatch({ type: "INIT_ERROR", payload: error });
|
|
473
507
|
onError?.(error);
|
|
@@ -487,6 +521,9 @@ function useReevit(options) {
|
|
|
487
521
|
const paymentIntent = mapToPaymentIntent(data, { ...config, reference });
|
|
488
522
|
dispatch({ type: "INIT_SUCCESS", payload: paymentIntent });
|
|
489
523
|
} catch (err) {
|
|
524
|
+
if (requestId !== initRequestIdRef.current) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
490
527
|
const error = {
|
|
491
528
|
code: "INIT_FAILED",
|
|
492
529
|
message: err instanceof Error ? err.message : "Failed to initialize checkout",
|
|
@@ -568,6 +605,7 @@ function useReevit(options) {
|
|
|
568
605
|
);
|
|
569
606
|
const reset = useCallback(() => {
|
|
570
607
|
initializingRef.current = false;
|
|
608
|
+
initRequestIdRef.current += 1;
|
|
571
609
|
dispatch({ type: "RESET" });
|
|
572
610
|
}, []);
|
|
573
611
|
const close = useCallback(async () => {
|
|
@@ -2178,6 +2216,7 @@ function ReevitCheckout({
|
|
|
2178
2216
|
};
|
|
2179
2217
|
}, [paymentIntent?.branding, theme]);
|
|
2180
2218
|
const themeStyles = resolvedTheme ? createThemeVariables(resolvedTheme) : {};
|
|
2219
|
+
const brandName = resolvedTheme?.companyName;
|
|
2181
2220
|
const themeMode = resolvedTheme?.darkMode;
|
|
2182
2221
|
const dataTheme = useMemo(() => {
|
|
2183
2222
|
if (typeof themeMode === "boolean") {
|
|
@@ -2420,7 +2459,17 @@ function ReevitCheckout({
|
|
|
2420
2459
|
"aria-modal": "true",
|
|
2421
2460
|
children: [
|
|
2422
2461
|
/* @__PURE__ */ jsxs("div", { className: "reevit-modal__header", children: [
|
|
2423
|
-
/* @__PURE__ */
|
|
2462
|
+
/* @__PURE__ */ jsxs("div", { className: "reevit-modal__branding", children: [
|
|
2463
|
+
/* @__PURE__ */ jsx(
|
|
2464
|
+
"img",
|
|
2465
|
+
{
|
|
2466
|
+
src: resolvedTheme?.logoUrl || "https://i.imgur.com/bzUR5Lm.png",
|
|
2467
|
+
alt: brandName || "Reevit",
|
|
2468
|
+
className: "reevit-modal__logo"
|
|
2469
|
+
}
|
|
2470
|
+
),
|
|
2471
|
+
brandName && /* @__PURE__ */ jsx("span", { className: "reevit-modal__brand-name", children: brandName })
|
|
2472
|
+
] }),
|
|
2424
2473
|
/* @__PURE__ */ jsx("button", { className: "reevit-modal__close", onClick: handleClose, "aria-label": "Close", children: "\u2715" })
|
|
2425
2474
|
] }),
|
|
2426
2475
|
/* @__PURE__ */ jsxs("div", { className: "reevit-modal__amount", children: [
|