@inttegro/react 0.1.0 → 0.4.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/README.md CHANGED
@@ -16,3 +16,11 @@ export function Payment({ orderId }: { orderId: string }) {
16
16
  )
17
17
  }
18
18
  ```
19
+
20
+ Pass `purchaseIntentId` instead of `orderId` when the Buy link uses a
21
+ `customer_selected_amount` price. The same component renders the amount picker
22
+ before continuing to Checkout:
23
+
24
+ ```tsx
25
+ <Checkout purchaseIntentId={purchaseIntentId} presentation="modal" />
26
+ ```
package/dist/index.cjs CHANGED
@@ -32,25 +32,47 @@ var Checkout = (0, import_react.forwardRef)(
32
32
  function Checkout2({
33
33
  appearance,
34
34
  className,
35
+ features,
35
36
  locale,
37
+ onCanceled,
36
38
  onCompleted,
37
39
  onError,
38
40
  onEvent,
39
41
  onReady,
40
42
  orderId,
43
+ purchaseIntentId,
44
+ presentation = "embedded",
41
45
  style,
42
46
  timeout,
43
47
  title
44
48
  }, forwardedRef) {
45
49
  const containerRef = (0, import_react.useRef)(null);
46
50
  const checkoutRef = (0, import_react.useRef)(null);
47
- const callbacksRef = (0, import_react.useRef)({ onCompleted, onError, onEvent, onReady });
51
+ const callbacksRef = (0, import_react.useRef)({
52
+ onCanceled,
53
+ onCompleted,
54
+ onError,
55
+ onEvent,
56
+ onReady
57
+ });
48
58
  const updateOptionsRef = (0, import_react.useRef)({ appearance, locale });
49
- callbacksRef.current = { onCompleted, onError, onEvent, onReady };
59
+ const hasFeatureOverrides = features !== void 0;
60
+ const showLineItems = features?.showLineItems;
61
+ const showInvoiceDownload = features?.showInvoiceDownload;
62
+ const showReceiptDownload = features?.showReceiptDownload;
63
+ const allowPaymentMethodChange = features?.allowPaymentMethodChange;
64
+ callbacksRef.current = {
65
+ onCanceled,
66
+ onCompleted,
67
+ onError,
68
+ onEvent,
69
+ onReady
70
+ };
50
71
  updateOptionsRef.current = { appearance, locale };
51
72
  (0, import_react.useImperativeHandle)(
52
73
  forwardedRef,
53
74
  () => ({
75
+ dismiss: () => checkoutRef.current?.dismiss(),
54
76
  focus: () => checkoutRef.current?.focus(),
55
77
  update: (options) => checkoutRef.current?.update(options)
56
78
  }),
@@ -58,8 +80,9 @@ var Checkout = (0, import_react.forwardRef)(
58
80
  );
59
81
  (0, import_react.useEffect)(() => {
60
82
  const target = containerRef.current;
61
- if (!target) return;
83
+ if (presentation === "embedded" && !target) return;
62
84
  let active = true;
85
+ let canceled = false;
63
86
  let checkout;
64
87
  let unsubscribe;
65
88
  void (0, import_js.loadInttegro)().then(async (inttegro) => {
@@ -67,7 +90,14 @@ var Checkout = (0, import_react.forwardRef)(
67
90
  const instance = inttegro.createCheckout(
68
91
  definedOptions({
69
92
  ...updateOptionsRef.current,
93
+ features: hasFeatureOverrides ? definedOptions({
94
+ allowPaymentMethodChange,
95
+ showInvoiceDownload,
96
+ showLineItems,
97
+ showReceiptDownload
98
+ }) : void 0,
70
99
  orderId,
100
+ purchaseIntentId,
71
101
  timeout,
72
102
  title
73
103
  })
@@ -80,14 +110,20 @@ var Checkout = (0, import_react.forwardRef)(
80
110
  checkoutRef.current = instance;
81
111
  unsubscribe = instance.onEvent((event) => {
82
112
  callbacksRef.current.onEvent?.(event);
113
+ if (event.type === "canceled") {
114
+ canceled = true;
115
+ callbacksRef.current.onCanceled?.(event);
116
+ }
83
117
  if (event.type === "ready") callbacksRef.current.onReady?.(event);
84
118
  if (event.type === "completed")
85
119
  callbacksRef.current.onCompleted?.(event);
86
120
  if (event.type === "error") callbacksRef.current.onError?.(event);
87
121
  });
88
- await instance.mount(target);
122
+ if (presentation === "modal") await instance.present();
123
+ else await instance.mount(target);
89
124
  }).catch((error) => {
90
- if (active) callbacksRef.current.onError?.(asError(error));
125
+ if (active && !canceled)
126
+ callbacksRef.current.onError?.(asError(error));
91
127
  });
92
128
  return () => {
93
129
  active = false;
@@ -95,7 +131,18 @@ var Checkout = (0, import_react.forwardRef)(
95
131
  checkout?.destroy();
96
132
  if (checkoutRef.current === checkout) checkoutRef.current = null;
97
133
  };
98
- }, [orderId, timeout, title]);
134
+ }, [
135
+ allowPaymentMethodChange,
136
+ hasFeatureOverrides,
137
+ orderId,
138
+ purchaseIntentId,
139
+ presentation,
140
+ showInvoiceDownload,
141
+ showLineItems,
142
+ showReceiptDownload,
143
+ timeout,
144
+ title
145
+ ]);
99
146
  (0, import_react.useEffect)(() => {
100
147
  checkoutRef.current?.update(definedOptions({ appearance, locale }));
101
148
  }, [appearance, locale]);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Checkout.tsx"],"sourcesContent":["/**\n * React component adapter for Inttegro-hosted Checkout.\n *\n * @module @inttegro/react\n */\nexport { Checkout, type CheckoutHandle, type CheckoutProps } from './Checkout'\nexport type {\n CheckoutAppearance,\n CheckoutErrorEvent,\n CheckoutEvent,\n CheckoutTheme,\n} from '@inttegro/js'\n","import {\n loadInttegro,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n type CheckoutOptions,\n} from '@inttegro/js'\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n type CSSProperties,\n} from 'react'\n\n/**\n * Props for {@link Checkout}.\n *\n * `orderId`, `timeout`, and `title` identify the embedded experience. Changing\n * one replaces the underlying controller. `appearance` and `locale` update the\n * existing controller without discarding payer progress.\n *\n * @category React\n */\nexport interface CheckoutProps extends CheckoutOptions {\n /** CSS class applied to the outer container owned by your React application. */\n className?: string\n /** Inline styles applied to the outer container, never to controls inside Checkout. */\n style?: CSSProperties\n /**\n * Called after Checkout reports its successful terminal state.\n * Use this to navigate or refresh server-owned Order state, not as the sole\n * signal for fulfillment.\n */\n onCompleted?: (event: Extract<CheckoutEvent, { type: 'completed' }>) => void\n /**\n * Called for loader/mount errors and sanitized hosted errors.\n * Use `error instanceof InttegroCheckoutError` or check for an event `type`\n * before reading framework-independent details.\n */\n onError?: (event: CheckoutErrorEvent | Error) => void\n /** Called for every sanitized lifecycle event, including events above. */\n onEvent?: (event: CheckoutEvent) => void\n /** Called once the iframe is interactive and its mount promise has resolved. */\n onReady?: (event: Extract<CheckoutEvent, { type: 'ready' }>) => void\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a React ref.\n *\n * Prefer props for normal updates. Use the handle for focus management in\n * dialogs or for updates driven by imperative host integrations.\n *\n * @category React\n */\nexport interface CheckoutHandle {\n /** Moves focus into Checkout when its controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when the controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Embeds Inttegro-hosted Checkout in a React application.\n *\n * The component renders an empty `div`, loads the executable runtime from\n * Inttegro's fixed origin after mount, creates a controller for `orderId`, and\n * destroys it during cleanup. Server rendering is safe because no runtime is\n * loaded until the effect runs in a browser.\n *\n * Changing `orderId`, `timeout`, or `title` starts a fresh hosted experience.\n * Changing `appearance` or `locale` updates the active experience in place.\n * Keep the component mounted while a payment is pending or confirmation is in\n * progress.\n *\n * @example Handle success, failure, and focus in a dialog\n * ```tsx\n * import { useRef } from 'react'\n * import { Checkout, type CheckoutHandle } from '@inttegro/react'\n *\n * function Payment({ orderId }: { orderId: string }) {\n * const checkout = useRef<CheckoutHandle>(null)\n *\n * return (\n * <dialog open onTransitionEnd={() => checkout.current?.focus()}>\n * <Checkout\n * ref={checkout}\n * orderId={orderId}\n * appearance={{ theme: 'system' }}\n * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}\n * onError={(error) => reportCheckoutError(error)}\n * />\n * </dialog>\n * )\n * }\n * ```\n *\n * @category React\n */\nexport const Checkout = forwardRef<CheckoutHandle, CheckoutProps>(\n function Checkout(\n {\n appearance,\n className,\n locale,\n onCompleted,\n onError,\n onEvent,\n onReady,\n orderId,\n style,\n timeout,\n title,\n },\n forwardedRef,\n ) {\n const containerRef = useRef<HTMLDivElement>(null)\n const checkoutRef = useRef<CheckoutController | null>(null)\n const callbacksRef = useRef({ onCompleted, onError, onEvent, onReady })\n const updateOptionsRef = useRef({ appearance, locale })\n callbacksRef.current = { onCompleted, onError, onEvent, onReady }\n updateOptionsRef.current = { appearance, locale }\n\n useImperativeHandle(\n forwardedRef,\n () => ({\n focus: () => checkoutRef.current?.focus(),\n update: (options) => checkoutRef.current?.update(options),\n }),\n [],\n )\n\n useEffect(() => {\n const target = containerRef.current\n if (!target) return\n\n let active = true\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n\n void loadInttegro()\n .then(async (inttegro) => {\n if (!active || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n ...updateOptionsRef.current,\n orderId,\n timeout,\n title,\n }),\n )\n if (!active) {\n instance.destroy()\n return\n }\n checkout = instance\n checkoutRef.current = instance\n unsubscribe = instance.onEvent((event) => {\n callbacksRef.current.onEvent?.(event)\n if (event.type === 'ready') callbacksRef.current.onReady?.(event)\n if (event.type === 'completed')\n callbacksRef.current.onCompleted?.(event)\n if (event.type === 'error') callbacksRef.current.onError?.(event)\n })\n await instance.mount(target)\n })\n .catch((error: unknown) => {\n if (active) callbacksRef.current.onError?.(asError(error))\n })\n\n return () => {\n active = false\n unsubscribe?.()\n checkout?.destroy()\n if (checkoutRef.current === checkout) checkoutRef.current = null\n }\n }, [orderId, timeout, title])\n\n useEffect(() => {\n checkoutRef.current?.update(definedOptions({ appearance, locale }))\n }, [appearance, locale])\n\n return <div className={className} ref={containerRef} style={style} />\n },\n)\n\nfunction definedOptions<Value extends object>(options: Value): Value {\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as Value\n}\n\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error('Checkout failed to load.')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAMO;AACP,mBAMO;AAyKI;AAnFJ,IAAM,eAAW;AAAA,EACtB,SAASA,UACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AA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7B,CAAC,EACA,MAAM,CAAC,UAAmB;AACzB,YAAI,OAAQ,cAAa,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,MAC3D,CAAC;AAEH,aAAO,MAAM;AACX,iBAAS;AACT,sBAAc;AACd,kBAAU,QAAQ;AAClB,YAAI,YAAY,YAAY,SAAU,aAAY,UAAU;AAAA,MAC9D;AAAA,IACF,GAAG,CAAC,SAAS,SAAS,KAAK,CAAC;AAE5B,gCAAU,MAAM;AACd,kBAAY,SAAS,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,IACpE,GAAG,CAAC,YAAY,MAAM,CAAC;AAEvB,WAAO,4CAAC,SAAI,WAAsB,KAAK,cAAc,OAAc;AAAA,EACrE;AACF;AAEA,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;AAEA,SAAS,QAAQ,OAAuB;AACtC,SAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,0BAA0B;AAC9E;","names":["Checkout"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/Checkout.tsx"],"sourcesContent":["/**\n * React component adapter for Inttegro-hosted Checkout.\n *\n * @module @inttegro/react\n */\nexport { Checkout, type CheckoutHandle, type CheckoutProps } from './Checkout'\nexport type {\n CheckoutAppearance,\n CheckoutErrorEvent,\n CheckoutEvent,\n CheckoutFeatures,\n CheckoutPresentation,\n CheckoutTheme,\n} from '@inttegro/js'\n","import {\n loadInttegro,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n type CheckoutOptions,\n type CheckoutPresentation,\n} from '@inttegro/js'\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n type CSSProperties,\n} from 'react'\n\n/**\n * Props for {@link Checkout}.\n *\n * `features`, the Checkout reference, `presentation`, `timeout`, and `title`\n * identify the experience. Changing one replaces the underlying controller.\n * `appearance` and `locale` update the existing controller without discarding\n * payer progress.\n *\n * @category React\n */\nexport type CheckoutProps = CheckoutOptions & {\n /** CSS class applied to the outer container owned by your React application. */\n className?: string\n /** Inline styles applied to the outer container, never to controls inside Checkout. */\n style?: CSSProperties\n /** Displays Checkout inline by default or in an Inttegro-managed modal. */\n presentation?: CheckoutPresentation\n /** Called when a payer dismisses managed modal Checkout before completion. */\n onCanceled?: (event: Extract<CheckoutEvent, { type: 'canceled' }>) => void\n /**\n * Called after Checkout reports its successful terminal state.\n * Use this to navigate or refresh server-owned Order state, not as the sole\n * signal for fulfillment.\n */\n onCompleted?: (event: Extract<CheckoutEvent, { type: 'completed' }>) => void\n /**\n * Called for loader/mount errors and sanitized hosted errors.\n * Use `error instanceof InttegroCheckoutError` or check for an event `type`\n * before reading framework-independent details.\n */\n onError?: (event: CheckoutErrorEvent | Error) => void\n /** Called for every sanitized lifecycle event, including events above. */\n onEvent?: (event: CheckoutEvent) => void\n /** Called once the iframe is interactive and its mount promise has resolved. */\n onReady?: (event: Extract<CheckoutEvent, { type: 'ready' }>) => void\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a React ref.\n *\n * Prefer props for normal updates. Use the handle for focus management in\n * dialogs or for updates driven by imperative host integrations.\n *\n * @category React\n */\nexport interface CheckoutHandle {\n /** Closes managed modal Checkout when it is open. */\n dismiss(): void\n /** Moves focus into Checkout when its controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when the controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Displays Inttegro-hosted Checkout in a React application.\n *\n * The component renders an empty `div`, loads the executable runtime from\n * Inttegro's fixed origin after mount, creates a controller for an `orderId` or\n * `purchaseIntentId`, and destroys it during cleanup. Server rendering is safe\n * because no runtime is loaded until the effect runs in a browser.\n *\n * Changing `features`, the Checkout reference, `presentation`, `timeout`, or\n * `title` starts a fresh hosted experience. Changing `appearance` or `locale`\n * updates the active experience in place. Keep the component mounted while a\n * payment is pending or confirmation is in progress.\n *\n * @example Present Checkout without building a dialog\n * ```tsx\n * import { Checkout } from '@inttegro/react'\n *\n * function Payment({ orderId }: { orderId: string }) {\n * return (\n * <Checkout\n * orderId={orderId}\n * presentation=\"modal\"\n * appearance={{ theme: 'system' }}\n * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}\n * onError={(error) => reportCheckoutError(error)}\n * />\n * )\n * }\n * ```\n *\n * @category React\n */\nexport const Checkout = forwardRef<CheckoutHandle, CheckoutProps>(\n function Checkout(\n {\n appearance,\n className,\n features,\n locale,\n onCanceled,\n onCompleted,\n onError,\n onEvent,\n onReady,\n orderId,\n purchaseIntentId,\n presentation = 'embedded',\n style,\n timeout,\n title,\n },\n forwardedRef,\n ) {\n const containerRef = useRef<HTMLDivElement>(null)\n const checkoutRef = useRef<CheckoutController | null>(null)\n const callbacksRef = useRef({\n onCanceled,\n onCompleted,\n onError,\n onEvent,\n onReady,\n })\n const updateOptionsRef = useRef({ appearance, locale })\n const hasFeatureOverrides = features !== undefined\n const showLineItems = features?.showLineItems\n const showInvoiceDownload = features?.showInvoiceDownload\n const showReceiptDownload = features?.showReceiptDownload\n const allowPaymentMethodChange = features?.allowPaymentMethodChange\n callbacksRef.current = {\n onCanceled,\n onCompleted,\n onError,\n onEvent,\n onReady,\n }\n updateOptionsRef.current = { appearance, locale }\n\n useImperativeHandle(\n forwardedRef,\n () => ({\n dismiss: () => checkoutRef.current?.dismiss(),\n focus: () => checkoutRef.current?.focus(),\n update: (options) => checkoutRef.current?.update(options),\n }),\n [],\n )\n\n useEffect(() => {\n const target = containerRef.current\n if (presentation === 'embedded' && !target) return\n\n let active = true\n let canceled = false\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n\n void loadInttegro()\n .then(async (inttegro) => {\n if (!active || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n ...updateOptionsRef.current,\n features: hasFeatureOverrides\n ? definedOptions({\n allowPaymentMethodChange,\n showInvoiceDownload,\n showLineItems,\n showReceiptDownload,\n })\n : undefined,\n orderId,\n purchaseIntentId,\n timeout,\n title,\n }) as CheckoutOptions,\n )\n if (!active) {\n instance.destroy()\n return\n }\n checkout = instance\n checkoutRef.current = instance\n unsubscribe = instance.onEvent((event) => {\n callbacksRef.current.onEvent?.(event)\n if (event.type === 'canceled') {\n canceled = true\n callbacksRef.current.onCanceled?.(event)\n }\n if (event.type === 'ready') callbacksRef.current.onReady?.(event)\n if (event.type === 'completed')\n callbacksRef.current.onCompleted?.(event)\n if (event.type === 'error') callbacksRef.current.onError?.(event)\n })\n if (presentation === 'modal') await instance.present()\n else await instance.mount(target!)\n })\n .catch((error: unknown) => {\n if (active && !canceled)\n callbacksRef.current.onError?.(asError(error))\n })\n\n return () => {\n active = false\n unsubscribe?.()\n checkout?.destroy()\n if (checkoutRef.current === checkout) checkoutRef.current = null\n }\n }, [\n allowPaymentMethodChange,\n hasFeatureOverrides,\n orderId,\n purchaseIntentId,\n presentation,\n showInvoiceDownload,\n showLineItems,\n showReceiptDownload,\n timeout,\n title,\n ])\n\n useEffect(() => {\n checkoutRef.current?.update(definedOptions({ appearance, locale }))\n }, [appearance, locale])\n\n return <div className={className} ref={containerRef} style={style} />\n },\n)\n\nfunction definedOptions<Value extends object>(options: Value): Value {\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as Value\n}\n\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error('Checkout failed to load.')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAOO;AACP,mBAMO;AA4NI;AApIJ,IAAM,eAAW;AAAA,EACtB,SAASA,UACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA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AQ,IAAI,MAAM,0BAA0B;AAC9E;","names":["Checkout"]}
package/dist/index.d.cts CHANGED
@@ -1,22 +1,29 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties } from 'react';
3
- import { CheckoutOptions, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
4
- export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutTheme } from '@inttegro/js';
3
+ import { CheckoutOptions, CheckoutPresentation, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
4
+ export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutPresentation, CheckoutTheme } from '@inttegro/js';
5
5
 
6
6
  /**
7
7
  * Props for {@link Checkout}.
8
8
  *
9
- * `orderId`, `timeout`, and `title` identify the embedded experience. Changing
10
- * one replaces the underlying controller. `appearance` and `locale` update the
11
- * existing controller without discarding payer progress.
9
+ * `features`, the Checkout reference, `presentation`, `timeout`, and `title`
10
+ * identify the experience. Changing one replaces the underlying controller.
11
+ * `appearance` and `locale` update the existing controller without discarding
12
+ * payer progress.
12
13
  *
13
14
  * @category React
14
15
  */
15
- interface CheckoutProps extends CheckoutOptions {
16
+ type CheckoutProps = CheckoutOptions & {
16
17
  /** CSS class applied to the outer container owned by your React application. */
17
18
  className?: string;
18
19
  /** Inline styles applied to the outer container, never to controls inside Checkout. */
19
20
  style?: CSSProperties;
21
+ /** Displays Checkout inline by default or in an Inttegro-managed modal. */
22
+ presentation?: CheckoutPresentation;
23
+ /** Called when a payer dismisses managed modal Checkout before completion. */
24
+ onCanceled?: (event: Extract<CheckoutEvent, {
25
+ type: 'canceled';
26
+ }>) => void;
20
27
  /**
21
28
  * Called after Checkout reports its successful terminal state.
22
29
  * Use this to navigate or refresh server-owned Order state, not as the sole
@@ -37,7 +44,7 @@ interface CheckoutProps extends CheckoutOptions {
37
44
  onReady?: (event: Extract<CheckoutEvent, {
38
45
  type: 'ready';
39
46
  }>) => void;
40
- }
47
+ };
41
48
  /**
42
49
  * Imperative operations exposed by {@link Checkout} through a React ref.
43
50
  *
@@ -47,42 +54,39 @@ interface CheckoutProps extends CheckoutOptions {
47
54
  * @category React
48
55
  */
49
56
  interface CheckoutHandle {
57
+ /** Closes managed modal Checkout when it is open. */
58
+ dismiss(): void;
50
59
  /** Moves focus into Checkout when its controller is ready; otherwise does nothing. */
51
60
  focus(): void;
52
61
  /** Applies a new locale or theme when the controller exists. */
53
62
  update(options: Parameters<CheckoutController['update']>[0]): void;
54
63
  }
55
64
  /**
56
- * Embeds Inttegro-hosted Checkout in a React application.
65
+ * Displays Inttegro-hosted Checkout in a React application.
57
66
  *
58
67
  * The component renders an empty `div`, loads the executable runtime from
59
- * Inttegro's fixed origin after mount, creates a controller for `orderId`, and
60
- * destroys it during cleanup. Server rendering is safe because no runtime is
61
- * loaded until the effect runs in a browser.
68
+ * Inttegro's fixed origin after mount, creates a controller for an `orderId` or
69
+ * `purchaseIntentId`, and destroys it during cleanup. Server rendering is safe
70
+ * because no runtime is loaded until the effect runs in a browser.
62
71
  *
63
- * Changing `orderId`, `timeout`, or `title` starts a fresh hosted experience.
64
- * Changing `appearance` or `locale` updates the active experience in place.
65
- * Keep the component mounted while a payment is pending or confirmation is in
66
- * progress.
72
+ * Changing `features`, the Checkout reference, `presentation`, `timeout`, or
73
+ * `title` starts a fresh hosted experience. Changing `appearance` or `locale`
74
+ * updates the active experience in place. Keep the component mounted while a
75
+ * payment is pending or confirmation is in progress.
67
76
  *
68
- * @example Handle success, failure, and focus in a dialog
77
+ * @example Present Checkout without building a dialog
69
78
  * ```tsx
70
- * import { useRef } from 'react'
71
- * import { Checkout, type CheckoutHandle } from '@inttegro/react'
79
+ * import { Checkout } from '@inttegro/react'
72
80
  *
73
81
  * function Payment({ orderId }: { orderId: string }) {
74
- * const checkout = useRef<CheckoutHandle>(null)
75
- *
76
82
  * return (
77
- * <dialog open onTransitionEnd={() => checkout.current?.focus()}>
78
- * <Checkout
79
- * ref={checkout}
80
- * orderId={orderId}
81
- * appearance={{ theme: 'system' }}
82
- * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}
83
- * onError={(error) => reportCheckoutError(error)}
84
- * />
85
- * </dialog>
83
+ * <Checkout
84
+ * orderId={orderId}
85
+ * presentation="modal"
86
+ * appearance={{ theme: 'system' }}
87
+ * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}
88
+ * onError={(error) => reportCheckoutError(error)}
89
+ * />
86
90
  * )
87
91
  * }
88
92
  * ```
package/dist/index.d.ts CHANGED
@@ -1,22 +1,29 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties } from 'react';
3
- import { CheckoutOptions, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
4
- export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutTheme } from '@inttegro/js';
3
+ import { CheckoutOptions, CheckoutPresentation, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
4
+ export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutPresentation, CheckoutTheme } from '@inttegro/js';
5
5
 
6
6
  /**
7
7
  * Props for {@link Checkout}.
8
8
  *
9
- * `orderId`, `timeout`, and `title` identify the embedded experience. Changing
10
- * one replaces the underlying controller. `appearance` and `locale` update the
11
- * existing controller without discarding payer progress.
9
+ * `features`, the Checkout reference, `presentation`, `timeout`, and `title`
10
+ * identify the experience. Changing one replaces the underlying controller.
11
+ * `appearance` and `locale` update the existing controller without discarding
12
+ * payer progress.
12
13
  *
13
14
  * @category React
14
15
  */
15
- interface CheckoutProps extends CheckoutOptions {
16
+ type CheckoutProps = CheckoutOptions & {
16
17
  /** CSS class applied to the outer container owned by your React application. */
17
18
  className?: string;
18
19
  /** Inline styles applied to the outer container, never to controls inside Checkout. */
19
20
  style?: CSSProperties;
21
+ /** Displays Checkout inline by default or in an Inttegro-managed modal. */
22
+ presentation?: CheckoutPresentation;
23
+ /** Called when a payer dismisses managed modal Checkout before completion. */
24
+ onCanceled?: (event: Extract<CheckoutEvent, {
25
+ type: 'canceled';
26
+ }>) => void;
20
27
  /**
21
28
  * Called after Checkout reports its successful terminal state.
22
29
  * Use this to navigate or refresh server-owned Order state, not as the sole
@@ -37,7 +44,7 @@ interface CheckoutProps extends CheckoutOptions {
37
44
  onReady?: (event: Extract<CheckoutEvent, {
38
45
  type: 'ready';
39
46
  }>) => void;
40
- }
47
+ };
41
48
  /**
42
49
  * Imperative operations exposed by {@link Checkout} through a React ref.
43
50
  *
@@ -47,42 +54,39 @@ interface CheckoutProps extends CheckoutOptions {
47
54
  * @category React
48
55
  */
49
56
  interface CheckoutHandle {
57
+ /** Closes managed modal Checkout when it is open. */
58
+ dismiss(): void;
50
59
  /** Moves focus into Checkout when its controller is ready; otherwise does nothing. */
51
60
  focus(): void;
52
61
  /** Applies a new locale or theme when the controller exists. */
53
62
  update(options: Parameters<CheckoutController['update']>[0]): void;
54
63
  }
55
64
  /**
56
- * Embeds Inttegro-hosted Checkout in a React application.
65
+ * Displays Inttegro-hosted Checkout in a React application.
57
66
  *
58
67
  * The component renders an empty `div`, loads the executable runtime from
59
- * Inttegro's fixed origin after mount, creates a controller for `orderId`, and
60
- * destroys it during cleanup. Server rendering is safe because no runtime is
61
- * loaded until the effect runs in a browser.
68
+ * Inttegro's fixed origin after mount, creates a controller for an `orderId` or
69
+ * `purchaseIntentId`, and destroys it during cleanup. Server rendering is safe
70
+ * because no runtime is loaded until the effect runs in a browser.
62
71
  *
63
- * Changing `orderId`, `timeout`, or `title` starts a fresh hosted experience.
64
- * Changing `appearance` or `locale` updates the active experience in place.
65
- * Keep the component mounted while a payment is pending or confirmation is in
66
- * progress.
72
+ * Changing `features`, the Checkout reference, `presentation`, `timeout`, or
73
+ * `title` starts a fresh hosted experience. Changing `appearance` or `locale`
74
+ * updates the active experience in place. Keep the component mounted while a
75
+ * payment is pending or confirmation is in progress.
67
76
  *
68
- * @example Handle success, failure, and focus in a dialog
77
+ * @example Present Checkout without building a dialog
69
78
  * ```tsx
70
- * import { useRef } from 'react'
71
- * import { Checkout, type CheckoutHandle } from '@inttegro/react'
79
+ * import { Checkout } from '@inttegro/react'
72
80
  *
73
81
  * function Payment({ orderId }: { orderId: string }) {
74
- * const checkout = useRef<CheckoutHandle>(null)
75
- *
76
82
  * return (
77
- * <dialog open onTransitionEnd={() => checkout.current?.focus()}>
78
- * <Checkout
79
- * ref={checkout}
80
- * orderId={orderId}
81
- * appearance={{ theme: 'system' }}
82
- * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}
83
- * onError={(error) => reportCheckoutError(error)}
84
- * />
85
- * </dialog>
83
+ * <Checkout
84
+ * orderId={orderId}
85
+ * presentation="modal"
86
+ * appearance={{ theme: 'system' }}
87
+ * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}
88
+ * onError={(error) => reportCheckoutError(error)}
89
+ * />
86
90
  * )
87
91
  * }
88
92
  * ```
package/dist/index.js CHANGED
@@ -13,25 +13,47 @@ var Checkout = forwardRef(
13
13
  function Checkout2({
14
14
  appearance,
15
15
  className,
16
+ features,
16
17
  locale,
18
+ onCanceled,
17
19
  onCompleted,
18
20
  onError,
19
21
  onEvent,
20
22
  onReady,
21
23
  orderId,
24
+ purchaseIntentId,
25
+ presentation = "embedded",
22
26
  style,
23
27
  timeout,
24
28
  title
25
29
  }, forwardedRef) {
26
30
  const containerRef = useRef(null);
27
31
  const checkoutRef = useRef(null);
28
- const callbacksRef = useRef({ onCompleted, onError, onEvent, onReady });
32
+ const callbacksRef = useRef({
33
+ onCanceled,
34
+ onCompleted,
35
+ onError,
36
+ onEvent,
37
+ onReady
38
+ });
29
39
  const updateOptionsRef = useRef({ appearance, locale });
30
- callbacksRef.current = { onCompleted, onError, onEvent, onReady };
40
+ const hasFeatureOverrides = features !== void 0;
41
+ const showLineItems = features?.showLineItems;
42
+ const showInvoiceDownload = features?.showInvoiceDownload;
43
+ const showReceiptDownload = features?.showReceiptDownload;
44
+ const allowPaymentMethodChange = features?.allowPaymentMethodChange;
45
+ callbacksRef.current = {
46
+ onCanceled,
47
+ onCompleted,
48
+ onError,
49
+ onEvent,
50
+ onReady
51
+ };
31
52
  updateOptionsRef.current = { appearance, locale };
32
53
  useImperativeHandle(
33
54
  forwardedRef,
34
55
  () => ({
56
+ dismiss: () => checkoutRef.current?.dismiss(),
35
57
  focus: () => checkoutRef.current?.focus(),
36
58
  update: (options) => checkoutRef.current?.update(options)
37
59
  }),
@@ -39,8 +61,9 @@ var Checkout = forwardRef(
39
61
  );
40
62
  useEffect(() => {
41
63
  const target = containerRef.current;
42
- if (!target) return;
64
+ if (presentation === "embedded" && !target) return;
43
65
  let active = true;
66
+ let canceled = false;
44
67
  let checkout;
45
68
  let unsubscribe;
46
69
  void loadInttegro().then(async (inttegro) => {
@@ -48,7 +71,14 @@ var Checkout = forwardRef(
48
71
  const instance = inttegro.createCheckout(
49
72
  definedOptions({
50
73
  ...updateOptionsRef.current,
74
+ features: hasFeatureOverrides ? definedOptions({
75
+ allowPaymentMethodChange,
76
+ showInvoiceDownload,
77
+ showLineItems,
78
+ showReceiptDownload
79
+ }) : void 0,
51
80
  orderId,
81
+ purchaseIntentId,
52
82
  timeout,
53
83
  title
54
84
  })
@@ -61,14 +91,20 @@ var Checkout = forwardRef(
61
91
  checkoutRef.current = instance;
62
92
  unsubscribe = instance.onEvent((event) => {
63
93
  callbacksRef.current.onEvent?.(event);
94
+ if (event.type === "canceled") {
95
+ canceled = true;
96
+ callbacksRef.current.onCanceled?.(event);
97
+ }
64
98
  if (event.type === "ready") callbacksRef.current.onReady?.(event);
65
99
  if (event.type === "completed")
66
100
  callbacksRef.current.onCompleted?.(event);
67
101
  if (event.type === "error") callbacksRef.current.onError?.(event);
68
102
  });
69
- await instance.mount(target);
103
+ if (presentation === "modal") await instance.present();
104
+ else await instance.mount(target);
70
105
  }).catch((error) => {
71
- if (active) callbacksRef.current.onError?.(asError(error));
106
+ if (active && !canceled)
107
+ callbacksRef.current.onError?.(asError(error));
72
108
  });
73
109
  return () => {
74
110
  active = false;
@@ -76,7 +112,18 @@ var Checkout = forwardRef(
76
112
  checkout?.destroy();
77
113
  if (checkoutRef.current === checkout) checkoutRef.current = null;
78
114
  };
79
- }, [orderId, timeout, title]);
115
+ }, [
116
+ allowPaymentMethodChange,
117
+ hasFeatureOverrides,
118
+ orderId,
119
+ purchaseIntentId,
120
+ presentation,
121
+ showInvoiceDownload,
122
+ showLineItems,
123
+ showReceiptDownload,
124
+ timeout,
125
+ title
126
+ ]);
80
127
  useEffect(() => {
81
128
  checkoutRef.current?.update(definedOptions({ appearance, locale }));
82
129
  }, [appearance, locale]);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Checkout.tsx"],"sourcesContent":["import {\n loadInttegro,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n type CheckoutOptions,\n} from '@inttegro/js'\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n type CSSProperties,\n} from 'react'\n\n/**\n * Props for {@link Checkout}.\n *\n * `orderId`, `timeout`, and `title` identify the embedded experience. Changing\n * one replaces the underlying controller. `appearance` and `locale` update the\n * existing controller without discarding payer progress.\n *\n * @category React\n */\nexport interface CheckoutProps extends CheckoutOptions {\n /** CSS class applied to the outer container owned by your React application. */\n className?: string\n /** Inline styles applied to the outer container, never to controls inside Checkout. */\n style?: CSSProperties\n /**\n * Called after Checkout reports its successful terminal state.\n * Use this to navigate or refresh server-owned Order state, not as the sole\n * signal for fulfillment.\n */\n onCompleted?: (event: Extract<CheckoutEvent, { type: 'completed' }>) => void\n /**\n * Called for loader/mount errors and sanitized hosted errors.\n * Use `error instanceof InttegroCheckoutError` or check for an event `type`\n * before reading framework-independent details.\n */\n onError?: (event: CheckoutErrorEvent | Error) => void\n /** Called for every sanitized lifecycle event, including events above. */\n onEvent?: (event: CheckoutEvent) => void\n /** Called once the iframe is interactive and its mount promise has resolved. */\n onReady?: (event: Extract<CheckoutEvent, { type: 'ready' }>) => void\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a React ref.\n *\n * Prefer props for normal updates. Use the handle for focus management in\n * dialogs or for updates driven by imperative host integrations.\n *\n * @category React\n */\nexport interface CheckoutHandle {\n /** Moves focus into Checkout when its controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when the controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Embeds Inttegro-hosted Checkout in a React application.\n *\n * The component renders an empty `div`, loads the executable runtime from\n * Inttegro's fixed origin after mount, creates a controller for `orderId`, and\n * destroys it during cleanup. Server rendering is safe because no runtime is\n * loaded until the effect runs in a browser.\n *\n * Changing `orderId`, `timeout`, or `title` starts a fresh hosted experience.\n * Changing `appearance` or `locale` updates the active experience in place.\n * Keep the component mounted while a payment is pending or confirmation is in\n * progress.\n *\n * @example Handle success, failure, and focus in a dialog\n * ```tsx\n * import { useRef } from 'react'\n * import { Checkout, type CheckoutHandle } from '@inttegro/react'\n *\n * function Payment({ orderId }: { orderId: string }) {\n * const checkout = useRef<CheckoutHandle>(null)\n *\n * return (\n * <dialog open onTransitionEnd={() => checkout.current?.focus()}>\n * <Checkout\n * ref={checkout}\n * orderId={orderId}\n * appearance={{ theme: 'system' }}\n * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}\n * onError={(error) => reportCheckoutError(error)}\n * />\n * </dialog>\n * )\n * }\n * ```\n *\n * @category React\n */\nexport const Checkout = forwardRef<CheckoutHandle, CheckoutProps>(\n function Checkout(\n {\n appearance,\n className,\n locale,\n onCompleted,\n onError,\n onEvent,\n onReady,\n orderId,\n style,\n timeout,\n title,\n },\n forwardedRef,\n ) {\n const containerRef = useRef<HTMLDivElement>(null)\n const checkoutRef = useRef<CheckoutController | null>(null)\n const callbacksRef = useRef({ onCompleted, onError, onEvent, onReady })\n const updateOptionsRef = useRef({ appearance, locale })\n callbacksRef.current = { onCompleted, onError, onEvent, onReady }\n updateOptionsRef.current = { appearance, locale }\n\n useImperativeHandle(\n forwardedRef,\n () => ({\n focus: () => checkoutRef.current?.focus(),\n update: (options) => checkoutRef.current?.update(options),\n }),\n [],\n )\n\n useEffect(() => {\n const target = containerRef.current\n if (!target) return\n\n let active = true\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n\n void loadInttegro()\n .then(async (inttegro) => {\n if (!active || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n ...updateOptionsRef.current,\n orderId,\n timeout,\n title,\n }),\n )\n if (!active) {\n instance.destroy()\n return\n }\n checkout = instance\n checkoutRef.current = instance\n unsubscribe = instance.onEvent((event) => {\n callbacksRef.current.onEvent?.(event)\n if (event.type === 'ready') callbacksRef.current.onReady?.(event)\n if (event.type === 'completed')\n callbacksRef.current.onCompleted?.(event)\n if (event.type === 'error') callbacksRef.current.onError?.(event)\n })\n await instance.mount(target)\n })\n .catch((error: unknown) => {\n if (active) callbacksRef.current.onError?.(asError(error))\n })\n\n return () => {\n active = false\n unsubscribe?.()\n checkout?.destroy()\n if (checkoutRef.current === checkout) checkoutRef.current = null\n }\n }, [orderId, timeout, title])\n\n useEffect(() => {\n checkoutRef.current?.update(definedOptions({ appearance, locale }))\n }, [appearance, locale])\n\n return <div className={className} ref={containerRef} style={style} />\n },\n)\n\nfunction definedOptions<Value extends object>(options: Value): Value {\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as Value\n}\n\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error('Checkout failed to load.')\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAKK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAyKI;AAnFJ,IAAM,WAAW;AAAA,EACtB,SAASA,UACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAC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AAC;AAAA,MAC3D,CAAC;AAEH,aAAO,MAAM;AACX,iBAAS;AACT,sBAAc;AACd,kBAAU,QAAQ;AAClB,YAAI,YAAY,YAAY,SAAU,aAAY,UAAU;AAAA,MAC9D;AAAA,IACF,GAAG,CAAC,SAAS,SAAS,KAAK,CAAC;AAE5B,cAAU,MAAM;AACd,kBAAY,SAAS,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,IACpE,GAAG,CAAC,YAAY,MAAM,CAAC;AAEvB,WAAO,oBAAC,SAAI,WAAsB,KAAK,cAAc,OAAc;AAAA,EACrE;AACF;AAEA,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;AAEA,SAAS,QAAQ,OAAuB;AACtC,SAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,0BAA0B;AAC9E;","names":["Checkout"]}
1
+ {"version":3,"sources":["../src/Checkout.tsx"],"sourcesContent":["import {\n loadInttegro,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n type CheckoutOptions,\n type CheckoutPresentation,\n} from '@inttegro/js'\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n type CSSProperties,\n} from 'react'\n\n/**\n * Props for {@link Checkout}.\n *\n * `features`, the Checkout reference, `presentation`, `timeout`, and `title`\n * identify the experience. Changing one replaces the underlying controller.\n * `appearance` and `locale` update the existing controller without discarding\n * payer progress.\n *\n * @category React\n */\nexport type CheckoutProps = CheckoutOptions & {\n /** CSS class applied to the outer container owned by your React application. */\n className?: string\n /** Inline styles applied to the outer container, never to controls inside Checkout. */\n style?: CSSProperties\n /** Displays Checkout inline by default or in an Inttegro-managed modal. */\n presentation?: CheckoutPresentation\n /** Called when a payer dismisses managed modal Checkout before completion. */\n onCanceled?: (event: Extract<CheckoutEvent, { type: 'canceled' }>) => void\n /**\n * Called after Checkout reports its successful terminal state.\n * Use this to navigate or refresh server-owned Order state, not as the sole\n * signal for fulfillment.\n */\n onCompleted?: (event: Extract<CheckoutEvent, { type: 'completed' }>) => void\n /**\n * Called for loader/mount errors and sanitized hosted errors.\n * Use `error instanceof InttegroCheckoutError` or check for an event `type`\n * before reading framework-independent details.\n */\n onError?: (event: CheckoutErrorEvent | Error) => void\n /** Called for every sanitized lifecycle event, including events above. */\n onEvent?: (event: CheckoutEvent) => void\n /** Called once the iframe is interactive and its mount promise has resolved. */\n onReady?: (event: Extract<CheckoutEvent, { type: 'ready' }>) => void\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a React ref.\n *\n * Prefer props for normal updates. Use the handle for focus management in\n * dialogs or for updates driven by imperative host integrations.\n *\n * @category React\n */\nexport interface CheckoutHandle {\n /** Closes managed modal Checkout when it is open. */\n dismiss(): void\n /** Moves focus into Checkout when its controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when the controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Displays Inttegro-hosted Checkout in a React application.\n *\n * The component renders an empty `div`, loads the executable runtime from\n * Inttegro's fixed origin after mount, creates a controller for an `orderId` or\n * `purchaseIntentId`, and destroys it during cleanup. Server rendering is safe\n * because no runtime is loaded until the effect runs in a browser.\n *\n * Changing `features`, the Checkout reference, `presentation`, `timeout`, or\n * `title` starts a fresh hosted experience. Changing `appearance` or `locale`\n * updates the active experience in place. Keep the component mounted while a\n * payment is pending or confirmation is in progress.\n *\n * @example Present Checkout without building a dialog\n * ```tsx\n * import { Checkout } from '@inttegro/react'\n *\n * function Payment({ orderId }: { orderId: string }) {\n * return (\n * <Checkout\n * orderId={orderId}\n * presentation=\"modal\"\n * appearance={{ theme: 'system' }}\n * onCompleted={() => location.assign(`/orders/${orderId}/complete`)}\n * onError={(error) => reportCheckoutError(error)}\n * />\n * )\n * }\n * ```\n *\n * @category React\n */\nexport const Checkout = forwardRef<CheckoutHandle, CheckoutProps>(\n function Checkout(\n {\n appearance,\n className,\n features,\n locale,\n onCanceled,\n onCompleted,\n onError,\n onEvent,\n onReady,\n orderId,\n purchaseIntentId,\n presentation = 'embedded',\n style,\n timeout,\n title,\n },\n forwardedRef,\n ) {\n const containerRef = useRef<HTMLDivElement>(null)\n const checkoutRef = useRef<CheckoutController | null>(null)\n const callbacksRef = useRef({\n onCanceled,\n onCompleted,\n onError,\n onEvent,\n onReady,\n })\n const updateOptionsRef = useRef({ appearance, locale })\n const hasFeatureOverrides = features !== undefined\n const showLineItems = features?.showLineItems\n const showInvoiceDownload = features?.showInvoiceDownload\n const showReceiptDownload = features?.showReceiptDownload\n const allowPaymentMethodChange = features?.allowPaymentMethodChange\n callbacksRef.current = {\n onCanceled,\n onCompleted,\n onError,\n onEvent,\n onReady,\n }\n updateOptionsRef.current = { appearance, locale }\n\n useImperativeHandle(\n forwardedRef,\n () => ({\n dismiss: () => checkoutRef.current?.dismiss(),\n focus: () => checkoutRef.current?.focus(),\n update: (options) => checkoutRef.current?.update(options),\n }),\n [],\n )\n\n useEffect(() => {\n const target = containerRef.current\n if (presentation === 'embedded' && !target) return\n\n let active = true\n let canceled = false\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n\n void loadInttegro()\n .then(async (inttegro) => {\n if (!active || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n ...updateOptionsRef.current,\n features: hasFeatureOverrides\n ? definedOptions({\n allowPaymentMethodChange,\n showInvoiceDownload,\n showLineItems,\n showReceiptDownload,\n })\n : undefined,\n orderId,\n purchaseIntentId,\n timeout,\n title,\n }) as CheckoutOptions,\n )\n if (!active) {\n instance.destroy()\n return\n }\n checkout = instance\n checkoutRef.current = instance\n unsubscribe = instance.onEvent((event) => {\n callbacksRef.current.onEvent?.(event)\n if (event.type === 'canceled') {\n canceled = true\n callbacksRef.current.onCanceled?.(event)\n }\n if (event.type === 'ready') callbacksRef.current.onReady?.(event)\n if (event.type === 'completed')\n callbacksRef.current.onCompleted?.(event)\n if (event.type === 'error') callbacksRef.current.onError?.(event)\n })\n if (presentation === 'modal') await instance.present()\n else await instance.mount(target!)\n })\n .catch((error: unknown) => {\n if (active && !canceled)\n callbacksRef.current.onError?.(asError(error))\n })\n\n return () => {\n active = false\n unsubscribe?.()\n checkout?.destroy()\n if (checkoutRef.current === checkout) checkoutRef.current = null\n }\n }, [\n allowPaymentMethodChange,\n hasFeatureOverrides,\n orderId,\n purchaseIntentId,\n presentation,\n showInvoiceDownload,\n showLineItems,\n showReceiptDownload,\n timeout,\n title,\n ])\n\n useEffect(() => {\n checkoutRef.current?.update(definedOptions({ appearance, locale }))\n }, [appearance, locale])\n\n return <div className={className} ref={containerRef} style={style} />\n },\n)\n\nfunction definedOptions<Value extends object>(options: Value): Value {\n return Object.fromEntries(\n Object.entries(options).filter(([, value]) => value !== undefined),\n ) as Value\n}\n\nfunction asError(error: unknown): Error {\n return error instanceof Error ? error : new Error('Checkout failed to load.')\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAMK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA4NI;AApIJ,IAAM,WAAW;AAAA,EACtB,SAASA,UACP;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,EACF,GACA,cACA;AACA,UAAM,eAAe,OAAuB,IAAI;AAChD,UAAM,cAAc,OAAkC,IAAI;AAC1D,UAAM,eAAe,OAAO;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,mBAAmB,OAAO,EAAE,YAAY,OAAO,CAAC;AACtD,UAAM,sBAAsB,aAAa;AACzC,UAAM,gBAAgB,UAAU;AAChC,UAAM,s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I,MAAM,SAAS,QAAS,cAAa,QAAQ,UAAU,KAAK;AAAA,QAClE,CAAC;AACD,YAAI,iBAAiB,QAAS,OAAM,SAAS,QAAQ;AAAA,YAChD,OAAM,SAAS,MAAM,MAAO;AAAA,MACnC,CAAC,EACA,MAAM,CAAC,UAAmB;AACzB,YAAI,UAAU,CAAC;AACb,uBAAa,QAAQ,UAAU,QAAQ,KAAK,CAAC;AAAA,MACjD,CAAC;AAEH,aAAO,MAAM;AACX,iBAAS;AACT,sBAAc;AACd,kBAAU,QAAQ;AAClB,YAAI,YAAY,YAAY,SAAU,aAAY,UAAU;AAAA,MAC9D;AAAA,IACF,GAAG;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,cAAU,MAAM;AACd,kBAAY,SAAS,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,IACpE,GAAG,CAAC,YAAY,MAAM,CAAC;AAEvB,WAAO,oBAAC,SAAI,WAAsB,KAAK,cAAc,OAAc;AAAA,EACrE;AACF;AAEA,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;AAEA,SAAS,QAAQ,OAAuB;AACtC,SAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,0BAA0B;AAC9E;","names":["Checkout"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inttegro/react",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "React components for Inttegro hosted workflows",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -32,14 +32,14 @@
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@inttegro/js": "0.1.0"
35
+ "@inttegro/js": "0.4.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": ">=18"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",
42
- "url": "git+https://github.com/zebodotdev/js.git",
42
+ "url": "git+https://github.com/inttegro/js.git",
43
43
  "directory": "packages/react"
44
44
  },
45
45
  "homepage": "https://studio.inttegro.com/web/react",