@inttegro/svelte 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 +7 -0
- package/dist/Checkout.svelte +43 -5
- package/dist/Checkout.svelte.d.ts +6 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/types.d.ts +21 -7
- package/package.json +3 -3
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
|
+
```
|
package/dist/Checkout.svelte
CHANGED
|
@@ -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'
|
|
@@ -10,12 +12,16 @@
|
|
|
10
12
|
let {
|
|
11
13
|
appearance,
|
|
12
14
|
class: className,
|
|
15
|
+
features,
|
|
13
16
|
locale,
|
|
17
|
+
onCanceled,
|
|
14
18
|
onCompleted,
|
|
15
19
|
onError,
|
|
16
20
|
onEvent,
|
|
17
21
|
onReady,
|
|
18
22
|
orderId,
|
|
23
|
+
purchaseIntentId,
|
|
24
|
+
presentation = 'embedded',
|
|
19
25
|
timeout,
|
|
20
26
|
title,
|
|
21
27
|
}: CheckoutProps = $props()
|
|
@@ -23,11 +29,34 @@
|
|
|
23
29
|
let container: HTMLDivElement
|
|
24
30
|
let checkout = $state<CheckoutController>()
|
|
25
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
|
+
|
|
26
47
|
$effect(() => {
|
|
27
|
-
const identity = {
|
|
48
|
+
const identity = {
|
|
49
|
+
features,
|
|
50
|
+
orderId,
|
|
51
|
+
purchaseIntentId,
|
|
52
|
+
presentation,
|
|
53
|
+
timeout,
|
|
54
|
+
title,
|
|
55
|
+
}
|
|
28
56
|
if (!container) return
|
|
29
57
|
|
|
30
58
|
let active = true
|
|
59
|
+
let canceled = false
|
|
31
60
|
let instance: CheckoutController | undefined
|
|
32
61
|
let unsubscribe: (() => void) | undefined
|
|
33
62
|
|
|
@@ -36,10 +65,14 @@
|
|
|
36
65
|
if (!active || !inttegro) return
|
|
37
66
|
instance = inttegro.createCheckout(
|
|
38
67
|
definedOptions({
|
|
39
|
-
...identity,
|
|
40
68
|
appearance: untrack(() => appearance),
|
|
69
|
+
features: identity.features,
|
|
41
70
|
locale: untrack(() => locale),
|
|
42
|
-
|
|
71
|
+
orderId: identity.orderId,
|
|
72
|
+
purchaseIntentId: identity.purchaseIntentId,
|
|
73
|
+
timeout: identity.timeout,
|
|
74
|
+
title: identity.title,
|
|
75
|
+
}) as CheckoutOptions,
|
|
43
76
|
)
|
|
44
77
|
if (!active) {
|
|
45
78
|
instance.destroy()
|
|
@@ -48,14 +81,19 @@
|
|
|
48
81
|
checkout = instance
|
|
49
82
|
unsubscribe = instance.onEvent((event) => {
|
|
50
83
|
onEvent?.(event)
|
|
84
|
+
if (event.type === 'canceled') {
|
|
85
|
+
canceled = true
|
|
86
|
+
onCanceled?.(event)
|
|
87
|
+
}
|
|
51
88
|
if (event.type === 'ready') onReady?.(event)
|
|
52
89
|
if (event.type === 'completed') onCompleted?.(event)
|
|
53
90
|
if (event.type === 'error') onError?.(event)
|
|
54
91
|
})
|
|
55
|
-
await instance.
|
|
92
|
+
if (identity.presentation === 'modal') await instance.present()
|
|
93
|
+
else await instance.mount(container)
|
|
56
94
|
})
|
|
57
95
|
.catch((error: unknown) => {
|
|
58
|
-
if (active) {
|
|
96
|
+
if (active && !canceled) {
|
|
59
97
|
onError?.(
|
|
60
98
|
error instanceof Error
|
|
61
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, 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
package/dist/types.d.ts
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import type { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent } 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
|
-
* `
|
|
6
|
-
*
|
|
7
|
-
* `locale` update the
|
|
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
|
|
12
|
+
export interface CheckoutPropsBase {
|
|
12
13
|
/** Initial and reactive theme preference for hosted Checkout. */
|
|
13
14
|
appearance?: CheckoutAppearance | undefined;
|
|
15
|
+
/** Hosted Checkout content and actions. Changing it replaces the controller. */
|
|
16
|
+
features?: CheckoutFeatures | undefined;
|
|
14
17
|
/** CSS class applied to the outer container owned by your Svelte application. */
|
|
15
18
|
class?: string | undefined;
|
|
16
19
|
/** Initial and reactive BCP 47 locale preference. */
|
|
17
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;
|
|
18
25
|
/**
|
|
19
26
|
* Called after the successful hosted terminal state. Reconcile the Order on
|
|
20
27
|
* your server before fulfillment.
|
|
@@ -30,10 +37,17 @@ export interface CheckoutProps {
|
|
|
30
37
|
onReady?: ((event: Extract<CheckoutEvent, {
|
|
31
38
|
type: 'ready';
|
|
32
39
|
}>) => void) | undefined;
|
|
33
|
-
/**
|
|
34
|
-
|
|
40
|
+
/** Displays Checkout inline by default or in an Inttegro-managed modal. */
|
|
41
|
+
presentation?: CheckoutPresentation | undefined;
|
|
35
42
|
/** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
|
|
36
43
|
timeout?: number | undefined;
|
|
37
44
|
/** Accessible iframe title; defaults to `Checkout`. */
|
|
38
45
|
title?: string | undefined;
|
|
39
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.
|
|
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.
|
|
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/
|
|
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",
|