@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 CHANGED
@@ -117,6 +117,8 @@ interface ReevitTheme {
117
117
  darkMode?: boolean;
118
118
  /** Custom logo URL to display in checkout header */
119
119
  logoUrl?: string;
120
+ /** Company or organization name to display in checkout header */
121
+ companyName?: string;
120
122
  /** PSP selector background color */
121
123
  pspSelectorBgColor?: string;
122
124
  /** PSP selector text color */
package/dist/index.d.ts CHANGED
@@ -117,6 +117,8 @@ interface ReevitTheme {
117
117
  darkMode?: boolean;
118
118
  /** Custom logo URL to display in checkout header */
119
119
  logoUrl?: string;
120
+ /** Company or organization name to display in checkout header */
121
+ companyName?: string;
120
122
  /** PSP selector background color */
121
123
  pspSelectorBgColor?: string;
122
124
  /** PSP selector text color */
package/dist/index.js CHANGED
@@ -366,6 +366,36 @@ function mapAvailableProviders(providers) {
366
366
  };
367
367
  }).filter((provider) => provider.methods.length > 0);
368
368
  }
369
+ function normalizeBranding(branding) {
370
+ if (!branding) {
371
+ return {};
372
+ }
373
+ const raw = branding;
374
+ const theme = { ...raw };
375
+ const getString = (value) => typeof value === "string" ? value : void 0;
376
+ const getBoolean = (value) => typeof value === "boolean" ? value : void 0;
377
+ const setIf = (key, value) => {
378
+ if (value !== void 0) {
379
+ theme[key] = value;
380
+ }
381
+ };
382
+ setIf("logoUrl", getString(raw.logoUrl ?? raw.logo_url));
383
+ setIf("companyName", getString(raw.companyName ?? raw.company_name));
384
+ setIf("primaryColor", getString(raw.primaryColor ?? raw.primary_color));
385
+ setIf("primaryForegroundColor", getString(raw.primaryForegroundColor ?? raw.primary_foreground_color));
386
+ setIf("backgroundColor", getString(raw.backgroundColor ?? raw.background_color));
387
+ setIf("surfaceColor", getString(raw.surfaceColor ?? raw.surface_color));
388
+ setIf("textColor", getString(raw.textColor ?? raw.text_color));
389
+ setIf("mutedTextColor", getString(raw.mutedTextColor ?? raw.muted_text_color));
390
+ setIf("borderRadius", getString(raw.borderRadius ?? raw.border_radius));
391
+ setIf("fontFamily", getString(raw.fontFamily ?? raw.font_family));
392
+ setIf("darkMode", getBoolean(raw.darkMode ?? raw.dark_mode));
393
+ setIf("pspSelectorBgColor", getString(raw.pspSelectorBgColor ?? raw.psp_selector_bg_color));
394
+ setIf("pspSelectorTextColor", getString(raw.pspSelectorTextColor ?? raw.psp_selector_text_color));
395
+ setIf("pspSelectorBorderColor", getString(raw.pspSelectorBorderColor ?? raw.psp_selector_border_color));
396
+ setIf("pspSelectorUseBorder", getBoolean(raw.pspSelectorUseBorder ?? raw.psp_selector_use_border));
397
+ return theme;
398
+ }
369
399
  function mapToPaymentIntent(response, config) {
370
400
  return {
371
401
  id: response.id,
@@ -385,7 +415,7 @@ function mapToPaymentIntent(response, config) {
385
415
  netAmount: response.net_amount,
386
416
  metadata: config.metadata,
387
417
  availableProviders: mapAvailableProviders(response.available_psps),
388
- branding: response.branding
418
+ branding: normalizeBranding(response.branding)
389
419
  };
390
420
  }
391
421
  function useReevit(options) {
@@ -398,6 +428,7 @@ function useReevit(options) {
398
428
  });
399
429
  const apiClientRef = react.useRef(null);
400
430
  const initializingRef = react.useRef(!!config.initialPaymentIntent);
431
+ const initRequestIdRef = react.useRef(0);
401
432
  react.useEffect(() => {
402
433
  if (config.initialPaymentIntent) {
403
434
  if (!state.paymentIntent || state.paymentIntent.id !== config.initialPaymentIntent.id) {
@@ -421,11 +452,11 @@ function useReevit(options) {
421
452
  return;
422
453
  }
423
454
  initializingRef.current = true;
455
+ const requestId = ++initRequestIdRef.current;
424
456
  dispatch({ type: "INIT_START" });
425
457
  try {
426
458
  const apiClient = apiClientRef.current;
427
459
  if (!apiClient) {
428
- initializingRef.current = false;
429
460
  throw new Error("API client not initialized");
430
461
  }
431
462
  const reference = config.reference || generateReference();
@@ -474,6 +505,9 @@ function useReevit(options) {
474
505
  data = result.data;
475
506
  error = result.error;
476
507
  }
508
+ if (requestId !== initRequestIdRef.current) {
509
+ return;
510
+ }
477
511
  if (error) {
478
512
  dispatch({ type: "INIT_ERROR", payload: error });
479
513
  onError?.(error);
@@ -493,6 +527,9 @@ function useReevit(options) {
493
527
  const paymentIntent = mapToPaymentIntent(data, { ...config, reference });
494
528
  dispatch({ type: "INIT_SUCCESS", payload: paymentIntent });
495
529
  } catch (err) {
530
+ if (requestId !== initRequestIdRef.current) {
531
+ return;
532
+ }
496
533
  const error = {
497
534
  code: "INIT_FAILED",
498
535
  message: err instanceof Error ? err.message : "Failed to initialize checkout",
@@ -574,6 +611,7 @@ function useReevit(options) {
574
611
  );
575
612
  const reset = react.useCallback(() => {
576
613
  initializingRef.current = false;
614
+ initRequestIdRef.current += 1;
577
615
  dispatch({ type: "RESET" });
578
616
  }, []);
579
617
  const close = react.useCallback(async () => {
@@ -2184,6 +2222,7 @@ function ReevitCheckout({
2184
2222
  };
2185
2223
  }, [paymentIntent?.branding, theme]);
2186
2224
  const themeStyles = resolvedTheme ? createThemeVariables(resolvedTheme) : {};
2225
+ const brandName = resolvedTheme?.companyName;
2187
2226
  const themeMode = resolvedTheme?.darkMode;
2188
2227
  const dataTheme = react.useMemo(() => {
2189
2228
  if (typeof themeMode === "boolean") {
@@ -2426,7 +2465,17 @@ function ReevitCheckout({
2426
2465
  "aria-modal": "true",
2427
2466
  children: [
2428
2467
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "reevit-modal__header", children: [
2429
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "reevit-modal__branding", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: resolvedTheme?.logoUrl || "https://i.imgur.com/bzUR5Lm.png", alt: "Checkout", className: "reevit-modal__logo" }) }),
2468
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "reevit-modal__branding", children: [
2469
+ /* @__PURE__ */ jsxRuntime.jsx(
2470
+ "img",
2471
+ {
2472
+ src: resolvedTheme?.logoUrl || "https://i.imgur.com/bzUR5Lm.png",
2473
+ alt: brandName || "Reevit",
2474
+ className: "reevit-modal__logo"
2475
+ }
2476
+ ),
2477
+ brandName && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "reevit-modal__brand-name", children: brandName })
2478
+ ] }),
2430
2479
  /* @__PURE__ */ jsxRuntime.jsx("button", { className: "reevit-modal__close", onClick: handleClose, "aria-label": "Close", children: "\u2715" })
2431
2480
  ] }),
2432
2481
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "reevit-modal__amount", children: [