@inttegro/svelte 0.2.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
@@ -11,3 +11,10 @@ does not bundle the payment-collection runtime.
11
11
 
12
12
  <Checkout {orderId} onCompleted={() => location.assign('/complete')} />
13
13
  ```
14
+
15
+ For a `customer_selected_amount` Buy link, pass `purchaseIntentId` instead of
16
+ `orderId`. This works in both embedded and modal presentations:
17
+
18
+ ```svelte
19
+ <Checkout {purchaseIntentId} presentation="modal" />
20
+ ```
@@ -3,6 +3,8 @@
3
3
  loadInttegro,
4
4
  type CheckoutController,
5
5
  type CheckoutEvent,
6
+ type CheckoutOptions,
7
+ type CheckoutUpdateOptions,
6
8
  } from '@inttegro/js'
7
9
  import { untrack } from 'svelte'
8
10
  import type { CheckoutProps } from './types'
@@ -12,11 +14,14 @@
12
14
  class: className,
13
15
  features,
14
16
  locale,
17
+ onCanceled,
15
18
  onCompleted,
16
19
  onError,
17
20
  onEvent,
18
21
  onReady,
19
22
  orderId,
23
+ purchaseIntentId,
24
+ presentation = 'embedded',
20
25
  timeout,
21
26
  title,
22
27
  }: CheckoutProps = $props()
@@ -24,11 +29,34 @@
24
29
  let container: HTMLDivElement
25
30
  let checkout = $state<CheckoutController>()
26
31
 
32
+ /** Closes managed modal Checkout when it is open. */
33
+ export function dismiss() {
34
+ checkout?.dismiss()
35
+ }
36
+
37
+ /** Moves focus into Checkout when it is ready. */
38
+ export function focus() {
39
+ checkout?.focus()
40
+ }
41
+
42
+ /** Applies a new locale or theme to the active Checkout instance. */
43
+ export function update(options: CheckoutUpdateOptions) {
44
+ checkout?.update(options)
45
+ }
46
+
27
47
  $effect(() => {
28
- const identity = { features, orderId, timeout, title }
48
+ const identity = {
49
+ features,
50
+ orderId,
51
+ purchaseIntentId,
52
+ presentation,
53
+ timeout,
54
+ title,
55
+ }
29
56
  if (!container) return
30
57
 
31
58
  let active = true
59
+ let canceled = false
32
60
  let instance: CheckoutController | undefined
33
61
  let unsubscribe: (() => void) | undefined
34
62
 
@@ -37,10 +65,14 @@
37
65
  if (!active || !inttegro) return
38
66
  instance = inttegro.createCheckout(
39
67
  definedOptions({
40
- ...identity,
41
68
  appearance: untrack(() => appearance),
69
+ features: identity.features,
42
70
  locale: untrack(() => locale),
43
- }),
71
+ orderId: identity.orderId,
72
+ purchaseIntentId: identity.purchaseIntentId,
73
+ timeout: identity.timeout,
74
+ title: identity.title,
75
+ }) as CheckoutOptions,
44
76
  )
45
77
  if (!active) {
46
78
  instance.destroy()
@@ -49,14 +81,19 @@
49
81
  checkout = instance
50
82
  unsubscribe = instance.onEvent((event) => {
51
83
  onEvent?.(event)
84
+ if (event.type === 'canceled') {
85
+ canceled = true
86
+ onCanceled?.(event)
87
+ }
52
88
  if (event.type === 'ready') onReady?.(event)
53
89
  if (event.type === 'completed') onCompleted?.(event)
54
90
  if (event.type === 'error') onError?.(event)
55
91
  })
56
- await instance.mount(container)
92
+ if (identity.presentation === 'modal') await instance.present()
93
+ else await instance.mount(container)
57
94
  })
58
95
  .catch((error: unknown) => {
59
- if (active) {
96
+ if (active && !canceled) {
60
97
  onError?.(
61
98
  error instanceof Error
62
99
  ? error
@@ -1,4 +1,9 @@
1
+ import { type CheckoutUpdateOptions } from '@inttegro/js';
1
2
  import type { CheckoutProps } from './types';
2
- declare const Checkout: import("svelte").Component<CheckoutProps, {}, "">;
3
+ declare const Checkout: import("svelte").Component<CheckoutProps, {
4
+ dismiss: () => void;
5
+ focus: () => void;
6
+ update: (options: CheckoutUpdateOptions) => void;
7
+ }, "">;
3
8
  type Checkout = ReturnType<typeof Checkout>;
4
9
  export default Checkout;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@
14
14
  *
15
15
  * <Checkout
16
16
  * {orderId}
17
+ * presentation="modal"
17
18
  * appearance={{ theme: 'system' }}
18
19
  * onCompleted={() => location.assign('/orders/complete')}
19
20
  * onError={reportCheckoutError}
@@ -23,5 +24,5 @@
23
24
  * @module @inttegro/svelte
24
25
  */
25
26
  export { default as Checkout } from './Checkout.svelte';
26
- export type { CheckoutProps } from './types';
27
- export type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutTheme, } from '@inttegro/js';
27
+ export type { CheckoutProps, CheckoutPropsBase } from './types';
28
+ export type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutPresentation, CheckoutTheme, } from '@inttegro/js';
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@
14
14
  *
15
15
  * <Checkout
16
16
  * {orderId}
17
+ * presentation="modal"
17
18
  * appearance={{ theme: 'system' }}
18
19
  * onCompleted={() => location.assign('/orders/complete')}
19
20
  * onError={reportCheckoutError}
package/dist/types.d.ts CHANGED
@@ -1,14 +1,15 @@
1
- import type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures } from '@inttegro/js';
1
+ import type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutPresentation } from '@inttegro/js';
2
2
  /**
3
3
  * Props accepted by the Inttegro {@link Checkout} component.
4
4
  *
5
- * `features`, `orderId`, `timeout`, and `title` identify a hosted experience;
6
- * changing one destroys the current controller and mounts a new one.
7
- * `appearance` and `locale` update the current controller in place.
5
+ * `features`, the Checkout reference, `presentation`, `timeout`, and `title`
6
+ * identify a hosted experience; changing one destroys the current controller
7
+ * and mounts or presents a new one. `appearance` and `locale` update the
8
+ * current controller in place.
8
9
  *
9
10
  * @category Svelte
10
11
  */
11
- export interface CheckoutProps {
12
+ export interface CheckoutPropsBase {
12
13
  /** Initial and reactive theme preference for hosted Checkout. */
13
14
  appearance?: CheckoutAppearance | undefined;
14
15
  /** Hosted Checkout content and actions. Changing it replaces the controller. */
@@ -17,6 +18,10 @@ export interface CheckoutProps {
17
18
  class?: string | undefined;
18
19
  /** Initial and reactive BCP 47 locale preference. */
19
20
  locale?: string | undefined;
21
+ /** Called when a payer dismisses managed modal Checkout before completion. */
22
+ onCanceled?: ((event: Extract<CheckoutEvent, {
23
+ type: 'canceled';
24
+ }>) => void) | undefined;
20
25
  /**
21
26
  * Called after the successful hosted terminal state. Reconcile the Order on
22
27
  * your server before fulfillment.
@@ -32,10 +37,17 @@ export interface CheckoutProps {
32
37
  onReady?: ((event: Extract<CheckoutEvent, {
33
38
  type: 'ready';
34
39
  }>) => void) | undefined;
35
- /** Client-safe reference for the finalized Order being paid. */
36
- orderId: string;
40
+ /** Displays Checkout inline by default or in an Inttegro-managed modal. */
41
+ presentation?: CheckoutPresentation | undefined;
37
42
  /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
38
43
  timeout?: number | undefined;
39
44
  /** Accessible iframe title; defaults to `Checkout`. */
40
45
  title?: string | undefined;
41
46
  }
47
+ export type CheckoutProps = CheckoutPropsBase & ({
48
+ orderId: string;
49
+ purchaseIntentId?: never;
50
+ } | {
51
+ orderId?: never;
52
+ purchaseIntentId: string;
53
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inttegro/svelte",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Svelte components for Inttegro hosted workflows",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",
@@ -26,14 +26,14 @@
26
26
  "typecheck": "svelte-check --tsconfig ./tsconfig.json"
27
27
  },
28
28
  "dependencies": {
29
- "@inttegro/js": "0.2.0"
29
+ "@inttegro/js": "0.4.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "svelte": ">=5"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
36
- "url": "git+https://github.com/zebodotdev/js.git",
36
+ "url": "git+https://github.com/inttegro/js.git",
37
37
  "directory": "packages/svelte"
38
38
  },
39
39
  "homepage": "https://studio.inttegro.com/web/svelte",