@inttegro/vue 0.2.0 → 0.5.1

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
@@ -13,3 +13,10 @@ import { Checkout } from '@inttegro/vue'
13
13
  <Checkout :order-id="orderId" @completed="onCompleted" />
14
14
  </template>
15
15
  ```
16
+
17
+ For a `customer_selected_amount` Buy link, pass `purchase-intent-id` instead of
18
+ `order-id`. This works in both embedded and modal presentations:
19
+
20
+ ```vue
21
+ <Checkout :purchase-intent-id="purchaseIntentId" presentation="modal" />
22
+ ```
package/dist/index.cjs CHANGED
@@ -33,13 +33,20 @@ var Checkout = (0, import_vue.defineComponent)({
33
33
  appearance: Object,
34
34
  features: Object,
35
35
  locale: String,
36
- orderId: { type: String, required: true },
36
+ orderId: String,
37
+ purchaseIntentId: String,
38
+ presentation: {
39
+ type: String,
40
+ default: "embedded"
41
+ },
37
42
  timeout: Number,
38
43
  title: String
39
44
  },
40
45
  emits: {
46
+ canceled: (_event) => true,
41
47
  completed: (_event) => true,
42
- error: (_event) => true,
48
+ failed: (_event) => true,
49
+ error: (_error) => true,
43
50
  event: (_event) => true,
44
51
  ready: (_event) => true
45
52
  },
@@ -59,6 +66,8 @@ var Checkout = (0, import_vue.defineComponent)({
59
66
  destroyCheckout();
60
67
  const target = container.value;
61
68
  const currentGeneration = generation;
69
+ let canceled = false;
70
+ let failed = false;
62
71
  if (!target) return;
63
72
  try {
64
73
  const inttegro = await (0, import_js.loadInttegro)();
@@ -69,6 +78,7 @@ var Checkout = (0, import_vue.defineComponent)({
69
78
  features: props.features,
70
79
  locale: props.locale,
71
80
  orderId: props.orderId,
81
+ purchaseIntentId: props.purchaseIntentId,
72
82
  timeout: props.timeout,
73
83
  title: props.title
74
84
  })
@@ -80,13 +90,21 @@ var Checkout = (0, import_vue.defineComponent)({
80
90
  checkout = instance;
81
91
  unsubscribe = instance.onEvent((event) => {
82
92
  emit("event", event);
93
+ if (event.type === "canceled") {
94
+ canceled = true;
95
+ emit("canceled", event);
96
+ }
83
97
  if (event.type === "ready") emit("ready", event);
84
98
  if (event.type === "completed") emit("completed", event);
85
- if (event.type === "error") emit("error", event);
99
+ if (event.type === "failed") {
100
+ failed = true;
101
+ emit("failed", event);
102
+ }
86
103
  });
87
- await instance.mount(target);
104
+ if (props.presentation === "modal") await instance.present();
105
+ else await instance.mount(target);
88
106
  } catch (error) {
89
- if (generation !== currentGeneration) return;
107
+ if (generation !== currentGeneration || canceled || failed) return;
90
108
  emit(
91
109
  "error",
92
110
  error instanceof Error ? error : new Error("Checkout failed to load.")
@@ -96,7 +114,14 @@ var Checkout = (0, import_vue.defineComponent)({
96
114
  (0, import_vue.onMounted)(mountCheckout);
97
115
  (0, import_vue.onBeforeUnmount)(destroyCheckout);
98
116
  (0, import_vue.watch)(
99
- () => [props.features, props.orderId, props.timeout, props.title],
117
+ () => [
118
+ props.features,
119
+ props.orderId,
120
+ props.purchaseIntentId,
121
+ props.presentation,
122
+ props.timeout,
123
+ props.title
124
+ ],
100
125
  () => void mountCheckout()
101
126
  );
102
127
  (0, import_vue.watch)(
@@ -107,6 +132,7 @@ var Checkout = (0, import_vue.defineComponent)({
107
132
  { deep: true }
108
133
  );
109
134
  expose({
135
+ dismiss: () => checkout?.dismiss(),
110
136
  focus: () => checkout?.focus(),
111
137
  update: (options) => checkout?.update(options)
112
138
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Checkout.ts"],"sourcesContent":["/**\n * Vue component adapter for Inttegro-hosted Checkout.\n *\n * @module @inttegro/vue\n */\nexport { Checkout, type CheckoutExposed, type CheckoutProps } from './Checkout'\nexport type {\n CheckoutAppearance,\n CheckoutErrorEvent,\n CheckoutEvent,\n CheckoutFeatures,\n CheckoutTheme,\n} from '@inttegro/js'\n","import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n type CheckoutFeatures,\n} from '@inttegro/js'\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n type PropType,\n} from 'vue'\n\n/**\n * Props accepted by the Inttegro {@link Checkout} component.\n *\n * Changing `features`, `orderId`, `timeout`, or `title` replaces the hosted\n * controller. Changing `appearance` or `locale` updates it in place,\n * preserving payer progress where the hosted flow permits.\n *\n * @category Vue\n */\nexport interface CheckoutProps {\n /** Initial and reactive theme preference for hosted Checkout. */\n appearance?: CheckoutAppearance | undefined\n /** Hosted Checkout content and actions. Changing it replaces the controller. */\n features?: CheckoutFeatures | undefined\n /** Initial and reactive BCP 47 locale preference. */\n locale?: string | undefined\n /** Client-safe reference for the finalized Order being paid. */\n orderId: string\n /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */\n timeout?: number | undefined\n /** Accessible iframe title; defaults to `Checkout`. */\n title?: string | undefined\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a Vue template ref.\n *\n * @category Vue\n */\nexport interface CheckoutExposed {\n /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when a controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Embeds Inttegro-hosted Checkout in a Vue application.\n *\n * The component owns the loader and controller lifecycle. It emits:\n *\n * - `ready` once the iframe is interactive;\n * - `event` for every sanitized Checkout lifecycle event;\n * - `completed` at the successful hosted terminal state; and\n * - `error` for loader/mount failures or sanitized hosted errors.\n *\n * Keep the component mounted while payment or confirmation is pending. On\n * unmount it removes its event subscription and permanently destroys the\n * controller.\n *\n * @example Use native Vue events\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { Checkout, type CheckoutExposed } from '@inttegro/vue'\n *\n * const props = defineProps<{ orderId: string }>()\n * const checkout = ref<CheckoutExposed>()\n * </script>\n *\n * <template>\n * <Checkout\n * ref=\"checkout\"\n * :order-id=\"props.orderId\"\n * :appearance=\"{ theme: 'system' }\"\n * @ready=\"checkout?.focus()\"\n * @completed=\"$router.push('/orders/complete')\"\n * @error=\"reportCheckoutError\"\n * />\n * </template>\n * ```\n *\n * @category Vue\n */\nexport const Checkout = defineComponent({\n name: 'InttegroCheckout',\n props: {\n appearance: Object as PropType<CheckoutAppearance>,\n features: Object as PropType<CheckoutFeatures>,\n locale: String,\n orderId: { type: String, required: true },\n timeout: Number,\n title: String,\n },\n emits: {\n completed: (_event: Extract<CheckoutEvent, { type: 'completed' }>) => true,\n error: (_event: CheckoutErrorEvent | Error) => true,\n event: (_event: CheckoutEvent) => true,\n ready: (_event: Extract<CheckoutEvent, { type: 'ready' }>) => true,\n },\n setup(props, { emit, expose }) {\n const container = ref<HTMLElement>()\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n let generation = 0\n\n function destroyCheckout() {\n generation += 1\n unsubscribe?.()\n unsubscribe = undefined\n checkout?.destroy()\n checkout = undefined\n }\n\n async function mountCheckout() {\n destroyCheckout()\n const target = container.value\n const currentGeneration = generation\n if (!target) return\n try {\n const inttegro = await loadInttegro()\n if (generation !== currentGeneration || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n appearance: props.appearance,\n features: props.features,\n locale: props.locale,\n orderId: props.orderId,\n timeout: props.timeout,\n title: props.title,\n }),\n )\n if (generation !== currentGeneration) {\n instance.destroy()\n return\n }\n checkout = instance\n unsubscribe = instance.onEvent((event) => {\n emit('event', event)\n if (event.type === 'ready') emit('ready', event)\n if (event.type === 'completed') emit('completed', event)\n if (event.type === 'error') emit('error', event)\n })\n await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration) return\n emit(\n 'error',\n error instanceof Error\n ? error\n : new Error('Checkout failed to load.'),\n )\n }\n }\n\n onMounted(mountCheckout)\n onBeforeUnmount(destroyCheckout)\n\n watch(\n () => [props.features, props.orderId, props.timeout, props.title],\n () => void mountCheckout(),\n )\n watch(\n () => [props.appearance, props.locale] as const,\n ([appearance, locale]) => {\n checkout?.update(definedOptions({ appearance, locale }))\n },\n { deep: true },\n )\n\n expose({\n focus: () => checkout?.focus(),\n update: (options: Parameters<CheckoutController['update']>[0]) =>\n checkout?.update(options),\n })\n\n return () => h('div', { ref: container })\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAOO;AACP,iBAQO;AA4EA,IAAM,eAAW,4BAAgB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACxC,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA,IACL,WAAW,CAAC,WAA0D;AAAA,IACtE,OAAO,CAAC,WAAuC;AAAA,IAC/C,OAAO,CAAC,WAA0B;AAAA,IAClC,OAAO,CAAC,WAAsD;AAAA,EAChE;AAAA,EACA,MAAM,OAAO,EAAE,MAAM,OAAO,GAAG;AAC7B,UAAM,gBAAY,gBAAiB;AACnC,QAAI;AACJ,QAAI;AACJ,QAAI,aAAa;AAEjB,aAAS,kBAAkB;AACzB,oBAAc;AACd,oBAAc;AACd,oBAAc;AACd,gBAAU,QAAQ;AAClB,iBAAW;AAAA,IACb;AAEA,mBAAe,gBAAgB;AAC7B,sBAAgB;AAChB,YAAM,SAAS,UAAU;AACzB,YAAM,oBAAoB;AAC1B,UAAI,CAAC,OAAQ;AACb,UAAI;AACF,cAAM,WAAW,UAAM,wBAAa;AACpC,YAAI,eAAe,qBAAqB,CAAC,SAAU;AACnD,cAAM,WAAW,SAAS;AAAA,UACxB,eAAe;AAAA,YACb,YAAY,MAAM;AAAA,YAClB,UAAU,MAAM;AAAA,YAChB,QAAQ,MAAM;AAAA,YACd,SAAS,MAAM;AAAA,YACf,SAAS,MA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AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/Checkout.ts"],"sourcesContent":["/**\n * Vue component adapter for Inttegro-hosted Checkout.\n *\n * @module @inttegro/vue\n */\nexport {\n Checkout,\n type CheckoutExposed,\n type CheckoutProps,\n type CheckoutPropsBase,\n} from './Checkout'\nexport type {\n CheckoutAppearance,\n CheckoutEvent,\n CheckoutFailedEvent,\n CheckoutOrder,\n CheckoutFeatures,\n CheckoutPresentation,\n CheckoutTheme,\n} from '@inttegro/js'\n","import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutEvent,\n type CheckoutFeatures,\n type CheckoutOptions,\n type CheckoutPresentation,\n} from '@inttegro/js'\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n type PropType,\n} from 'vue'\n\n/**\n * Props accepted by the Inttegro {@link Checkout} component.\n *\n * Changing `features`, the Checkout reference, `presentation`, `timeout`, or\n * `title` replaces the hosted controller. Changing `appearance` or `locale`\n * updates it in place, preserving payer progress where the hosted flow permits.\n *\n * @category Vue\n */\nexport interface CheckoutPropsBase {\n /** Initial and reactive theme preference for hosted Checkout. */\n appearance?: CheckoutAppearance | undefined\n /** Hosted Checkout content and actions. Changing it replaces the controller. */\n features?: CheckoutFeatures | undefined\n /** Initial and reactive BCP 47 locale preference. */\n locale?: string | undefined\n /** Displays Checkout inline by default or in an Inttegro-managed modal. */\n presentation?: CheckoutPresentation | undefined\n /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */\n timeout?: number | undefined\n /** Accessible iframe title; defaults to `Checkout`. */\n title?: string | undefined\n}\n\nexport type CheckoutProps = CheckoutPropsBase &\n (\n | { orderId: string; purchaseIntentId?: never }\n | { orderId?: never; purchaseIntentId: string }\n )\n\n/**\n * Imperative operations exposed by {@link Checkout} through a Vue template ref.\n *\n * @category Vue\n */\nexport interface CheckoutExposed {\n /** Closes managed modal Checkout when it is open. */\n dismiss(): void\n /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when a controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Displays Inttegro-hosted Checkout in a Vue application.\n *\n * The component owns the loader and controller lifecycle. It emits:\n *\n * - `ready` once the iframe is interactive;\n * - `event` for every sanitized Checkout lifecycle event;\n * - `canceled` when a payer dismisses managed modal Checkout;\n * - `completed` at the successful hosted terminal state; and\n * - `failed` for terminal Checkout failure.\n * - `error` for loader or mount failures.\n *\n * Keep the component mounted while payment or confirmation is pending. On\n * unmount it removes its event subscription and permanently destroys the\n * controller.\n *\n * @example Use native Vue events\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { Checkout, type CheckoutExposed } from '@inttegro/vue'\n *\n * const props = defineProps<{ orderId: string }>()\n * const checkout = ref<CheckoutExposed>()\n * </script>\n *\n * <template>\n * <Checkout\n * ref=\"checkout\"\n * :order-id=\"props.orderId\"\n * presentation=\"modal\"\n * :appearance=\"{ theme: 'system' }\"\n * @ready=\"checkout?.focus()\"\n * @completed=\"$router.push('/orders/complete')\"\n * @error=\"reportCheckoutError\"\n * />\n * </template>\n * ```\n *\n * @category Vue\n */\nexport const Checkout = defineComponent({\n name: 'InttegroCheckout',\n props: {\n appearance: Object as PropType<CheckoutAppearance>,\n features: Object as PropType<CheckoutFeatures>,\n locale: String,\n orderId: String,\n purchaseIntentId: String,\n presentation: {\n type: String as PropType<CheckoutPresentation>,\n default: 'embedded',\n },\n timeout: Number,\n title: String,\n },\n emits: {\n canceled: (_event: Extract<CheckoutEvent, { type: 'canceled' }>) => true,\n completed: (_event: Extract<CheckoutEvent, { type: 'completed' }>) => true,\n failed: (_event: Extract<CheckoutEvent, { type: 'failed' }>) => true,\n error: (_error: Error) => true,\n event: (_event: CheckoutEvent) => true,\n ready: (_event: Extract<CheckoutEvent, { type: 'ready' }>) => true,\n },\n setup(props, { emit, expose }) {\n const container = ref<HTMLElement>()\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n let generation = 0\n\n function destroyCheckout() {\n generation += 1\n unsubscribe?.()\n unsubscribe = undefined\n checkout?.destroy()\n checkout = undefined\n }\n\n async function mountCheckout() {\n destroyCheckout()\n const target = container.value\n const currentGeneration = generation\n let canceled = false\n let failed = false\n if (!target) return\n try {\n const inttegro = await loadInttegro()\n if (generation !== currentGeneration || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n appearance: props.appearance,\n features: props.features,\n locale: props.locale,\n orderId: props.orderId,\n purchaseIntentId: props.purchaseIntentId,\n timeout: props.timeout,\n title: props.title,\n }) as CheckoutOptions,\n )\n if (generation !== currentGeneration) {\n instance.destroy()\n return\n }\n checkout = instance\n unsubscribe = instance.onEvent((event) => {\n emit('event', event)\n if (event.type === 'canceled') {\n canceled = true\n emit('canceled', event)\n }\n if (event.type === 'ready') emit('ready', event)\n if (event.type === 'completed') emit('completed', event)\n if (event.type === 'failed') {\n failed = true\n emit('failed', event)\n }\n })\n if (props.presentation === 'modal') await instance.present()\n else await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration || canceled || failed) return\n emit(\n 'error',\n error instanceof Error\n ? error\n : new Error('Checkout failed to load.'),\n )\n }\n }\n\n onMounted(mountCheckout)\n onBeforeUnmount(destroyCheckout)\n\n watch(\n () => [\n props.features,\n props.orderId,\n props.purchaseIntentId,\n props.presentation,\n props.timeout,\n props.title,\n ],\n () => void mountCheckout(),\n )\n watch(\n () => [props.appearance, props.locale] as const,\n ([appearance, locale]) => {\n checkout?.update(definedOptions({ appearance, locale }))\n },\n { deep: true },\n )\n\n expose({\n dismiss: () => checkout?.dismiss(),\n focus: () => checkout?.focus(),\n update: (options: Parameters<CheckoutController['update']>[0]) =>\n checkout?.update(options),\n })\n\n return () => h('div', { ref: container })\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"],"mappings":";;;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,CAAC;AAED,WAAO,UAAM,cAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,52 +1,63 @@
1
1
  import * as _inttegro_js from '@inttegro/js';
2
- import { CheckoutAppearance, CheckoutFeatures, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
3
- export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutTheme } from '@inttegro/js';
2
+ import { CheckoutAppearance, CheckoutFeatures, CheckoutPresentation, CheckoutEvent, CheckoutController } from '@inttegro/js';
3
+ export { CheckoutAppearance, CheckoutEvent, CheckoutFailedEvent, CheckoutFeatures, CheckoutOrder, CheckoutPresentation, CheckoutTheme } from '@inttegro/js';
4
4
  import * as vue from 'vue';
5
5
  import { PropType } from 'vue';
6
6
 
7
7
  /**
8
8
  * Props accepted by the Inttegro {@link Checkout} component.
9
9
  *
10
- * Changing `features`, `orderId`, `timeout`, or `title` replaces the hosted
11
- * controller. Changing `appearance` or `locale` updates it in place,
12
- * preserving payer progress where the hosted flow permits.
10
+ * Changing `features`, the Checkout reference, `presentation`, `timeout`, or
11
+ * `title` replaces the hosted controller. Changing `appearance` or `locale`
12
+ * updates it in place, preserving payer progress where the hosted flow permits.
13
13
  *
14
14
  * @category Vue
15
15
  */
16
- interface CheckoutProps {
16
+ interface CheckoutPropsBase {
17
17
  /** Initial and reactive theme preference for hosted Checkout. */
18
18
  appearance?: CheckoutAppearance | undefined;
19
19
  /** Hosted Checkout content and actions. Changing it replaces the controller. */
20
20
  features?: CheckoutFeatures | undefined;
21
21
  /** Initial and reactive BCP 47 locale preference. */
22
22
  locale?: string | undefined;
23
- /** Client-safe reference for the finalized Order being paid. */
24
- orderId: string;
23
+ /** Displays Checkout inline by default or in an Inttegro-managed modal. */
24
+ presentation?: CheckoutPresentation | undefined;
25
25
  /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
26
26
  timeout?: number | undefined;
27
27
  /** Accessible iframe title; defaults to `Checkout`. */
28
28
  title?: string | undefined;
29
29
  }
30
+ type CheckoutProps = CheckoutPropsBase & ({
31
+ orderId: string;
32
+ purchaseIntentId?: never;
33
+ } | {
34
+ orderId?: never;
35
+ purchaseIntentId: string;
36
+ });
30
37
  /**
31
38
  * Imperative operations exposed by {@link Checkout} through a Vue template ref.
32
39
  *
33
40
  * @category Vue
34
41
  */
35
42
  interface CheckoutExposed {
43
+ /** Closes managed modal Checkout when it is open. */
44
+ dismiss(): void;
36
45
  /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */
37
46
  focus(): void;
38
47
  /** Applies a new locale or theme when a controller exists. */
39
48
  update(options: Parameters<CheckoutController['update']>[0]): void;
40
49
  }
41
50
  /**
42
- * Embeds Inttegro-hosted Checkout in a Vue application.
51
+ * Displays Inttegro-hosted Checkout in a Vue application.
43
52
  *
44
53
  * The component owns the loader and controller lifecycle. It emits:
45
54
  *
46
55
  * - `ready` once the iframe is interactive;
47
56
  * - `event` for every sanitized Checkout lifecycle event;
57
+ * - `canceled` when a payer dismisses managed modal Checkout;
48
58
  * - `completed` at the successful hosted terminal state; and
49
- * - `error` for loader/mount failures or sanitized hosted errors.
59
+ * - `failed` for terminal Checkout failure.
60
+ * - `error` for loader or mount failures.
50
61
  *
51
62
  * Keep the component mounted while payment or confirmation is pending. On
52
63
  * unmount it removes its event subscription and permanently destroys the
@@ -66,6 +77,7 @@ interface CheckoutExposed {
66
77
  * <Checkout
67
78
  * ref="checkout"
68
79
  * :order-id="props.orderId"
80
+ * presentation="modal"
69
81
  * :appearance="{ theme: 'system' }"
70
82
  * @ready="checkout?.focus()"
71
83
  * @completed="$router.push('/orders/complete')"
@@ -80,19 +92,27 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
80
92
  appearance: PropType<CheckoutAppearance>;
81
93
  features: PropType<CheckoutFeatures>;
82
94
  locale: StringConstructor;
83
- orderId: {
84
- type: StringConstructor;
85
- required: true;
95
+ orderId: StringConstructor;
96
+ purchaseIntentId: StringConstructor;
97
+ presentation: {
98
+ type: PropType<CheckoutPresentation>;
99
+ default: string;
86
100
  };
87
101
  timeout: NumberConstructor;
88
102
  title: StringConstructor;
89
103
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
90
104
  [key: string]: any;
91
105
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
106
+ canceled: (_event: Extract<CheckoutEvent, {
107
+ type: "canceled";
108
+ }>) => true;
92
109
  completed: (_event: Extract<CheckoutEvent, {
93
110
  type: "completed";
94
111
  }>) => true;
95
- error: (_event: CheckoutErrorEvent | Error) => true;
112
+ failed: (_event: Extract<CheckoutEvent, {
113
+ type: "failed";
114
+ }>) => true;
115
+ error: (_error: Error) => true;
96
116
  event: (_event: CheckoutEvent) => true;
97
117
  ready: (_event: Extract<CheckoutEvent, {
98
118
  type: "ready";
@@ -101,17 +121,23 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
101
121
  appearance: PropType<CheckoutAppearance>;
102
122
  features: PropType<CheckoutFeatures>;
103
123
  locale: StringConstructor;
104
- orderId: {
105
- type: StringConstructor;
106
- required: true;
124
+ orderId: StringConstructor;
125
+ purchaseIntentId: StringConstructor;
126
+ presentation: {
127
+ type: PropType<CheckoutPresentation>;
128
+ default: string;
107
129
  };
108
130
  timeout: NumberConstructor;
109
131
  title: StringConstructor;
110
132
  }>> & Readonly<{
111
- onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
133
+ onCanceled?: (_event: _inttegro_js.CheckoutCanceledEvent) => any;
112
134
  onReady?: (_event: _inttegro_js.CheckoutReadyEvent) => any;
113
- onError?: (_event: CheckoutErrorEvent | Error) => any;
135
+ onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
136
+ onFailed?: (_event: _inttegro_js.CheckoutFailedEvent) => any;
137
+ onError?: (_error: Error) => any;
114
138
  onEvent?: (_event: CheckoutEvent) => any;
115
- }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
139
+ }>, {
140
+ presentation: CheckoutPresentation;
141
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
116
142
 
117
- export { Checkout, type CheckoutExposed, type CheckoutProps };
143
+ export { Checkout, type CheckoutExposed, type CheckoutProps, type CheckoutPropsBase };
package/dist/index.d.ts CHANGED
@@ -1,52 +1,63 @@
1
1
  import * as _inttegro_js from '@inttegro/js';
2
- import { CheckoutAppearance, CheckoutFeatures, CheckoutEvent, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
3
- export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, CheckoutTheme } from '@inttegro/js';
2
+ import { CheckoutAppearance, CheckoutFeatures, CheckoutPresentation, CheckoutEvent, CheckoutController } from '@inttegro/js';
3
+ export { CheckoutAppearance, CheckoutEvent, CheckoutFailedEvent, CheckoutFeatures, CheckoutOrder, CheckoutPresentation, CheckoutTheme } from '@inttegro/js';
4
4
  import * as vue from 'vue';
5
5
  import { PropType } from 'vue';
6
6
 
7
7
  /**
8
8
  * Props accepted by the Inttegro {@link Checkout} component.
9
9
  *
10
- * Changing `features`, `orderId`, `timeout`, or `title` replaces the hosted
11
- * controller. Changing `appearance` or `locale` updates it in place,
12
- * preserving payer progress where the hosted flow permits.
10
+ * Changing `features`, the Checkout reference, `presentation`, `timeout`, or
11
+ * `title` replaces the hosted controller. Changing `appearance` or `locale`
12
+ * updates it in place, preserving payer progress where the hosted flow permits.
13
13
  *
14
14
  * @category Vue
15
15
  */
16
- interface CheckoutProps {
16
+ interface CheckoutPropsBase {
17
17
  /** Initial and reactive theme preference for hosted Checkout. */
18
18
  appearance?: CheckoutAppearance | undefined;
19
19
  /** Hosted Checkout content and actions. Changing it replaces the controller. */
20
20
  features?: CheckoutFeatures | undefined;
21
21
  /** Initial and reactive BCP 47 locale preference. */
22
22
  locale?: string | undefined;
23
- /** Client-safe reference for the finalized Order being paid. */
24
- orderId: string;
23
+ /** Displays Checkout inline by default or in an Inttegro-managed modal. */
24
+ presentation?: CheckoutPresentation | undefined;
25
25
  /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */
26
26
  timeout?: number | undefined;
27
27
  /** Accessible iframe title; defaults to `Checkout`. */
28
28
  title?: string | undefined;
29
29
  }
30
+ type CheckoutProps = CheckoutPropsBase & ({
31
+ orderId: string;
32
+ purchaseIntentId?: never;
33
+ } | {
34
+ orderId?: never;
35
+ purchaseIntentId: string;
36
+ });
30
37
  /**
31
38
  * Imperative operations exposed by {@link Checkout} through a Vue template ref.
32
39
  *
33
40
  * @category Vue
34
41
  */
35
42
  interface CheckoutExposed {
43
+ /** Closes managed modal Checkout when it is open. */
44
+ dismiss(): void;
36
45
  /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */
37
46
  focus(): void;
38
47
  /** Applies a new locale or theme when a controller exists. */
39
48
  update(options: Parameters<CheckoutController['update']>[0]): void;
40
49
  }
41
50
  /**
42
- * Embeds Inttegro-hosted Checkout in a Vue application.
51
+ * Displays Inttegro-hosted Checkout in a Vue application.
43
52
  *
44
53
  * The component owns the loader and controller lifecycle. It emits:
45
54
  *
46
55
  * - `ready` once the iframe is interactive;
47
56
  * - `event` for every sanitized Checkout lifecycle event;
57
+ * - `canceled` when a payer dismisses managed modal Checkout;
48
58
  * - `completed` at the successful hosted terminal state; and
49
- * - `error` for loader/mount failures or sanitized hosted errors.
59
+ * - `failed` for terminal Checkout failure.
60
+ * - `error` for loader or mount failures.
50
61
  *
51
62
  * Keep the component mounted while payment or confirmation is pending. On
52
63
  * unmount it removes its event subscription and permanently destroys the
@@ -66,6 +77,7 @@ interface CheckoutExposed {
66
77
  * <Checkout
67
78
  * ref="checkout"
68
79
  * :order-id="props.orderId"
80
+ * presentation="modal"
69
81
  * :appearance="{ theme: 'system' }"
70
82
  * @ready="checkout?.focus()"
71
83
  * @completed="$router.push('/orders/complete')"
@@ -80,19 +92,27 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
80
92
  appearance: PropType<CheckoutAppearance>;
81
93
  features: PropType<CheckoutFeatures>;
82
94
  locale: StringConstructor;
83
- orderId: {
84
- type: StringConstructor;
85
- required: true;
95
+ orderId: StringConstructor;
96
+ purchaseIntentId: StringConstructor;
97
+ presentation: {
98
+ type: PropType<CheckoutPresentation>;
99
+ default: string;
86
100
  };
87
101
  timeout: NumberConstructor;
88
102
  title: StringConstructor;
89
103
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
90
104
  [key: string]: any;
91
105
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
106
+ canceled: (_event: Extract<CheckoutEvent, {
107
+ type: "canceled";
108
+ }>) => true;
92
109
  completed: (_event: Extract<CheckoutEvent, {
93
110
  type: "completed";
94
111
  }>) => true;
95
- error: (_event: CheckoutErrorEvent | Error) => true;
112
+ failed: (_event: Extract<CheckoutEvent, {
113
+ type: "failed";
114
+ }>) => true;
115
+ error: (_error: Error) => true;
96
116
  event: (_event: CheckoutEvent) => true;
97
117
  ready: (_event: Extract<CheckoutEvent, {
98
118
  type: "ready";
@@ -101,17 +121,23 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
101
121
  appearance: PropType<CheckoutAppearance>;
102
122
  features: PropType<CheckoutFeatures>;
103
123
  locale: StringConstructor;
104
- orderId: {
105
- type: StringConstructor;
106
- required: true;
124
+ orderId: StringConstructor;
125
+ purchaseIntentId: StringConstructor;
126
+ presentation: {
127
+ type: PropType<CheckoutPresentation>;
128
+ default: string;
107
129
  };
108
130
  timeout: NumberConstructor;
109
131
  title: StringConstructor;
110
132
  }>> & Readonly<{
111
- onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
133
+ onCanceled?: (_event: _inttegro_js.CheckoutCanceledEvent) => any;
112
134
  onReady?: (_event: _inttegro_js.CheckoutReadyEvent) => any;
113
- onError?: (_event: CheckoutErrorEvent | Error) => any;
135
+ onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
136
+ onFailed?: (_event: _inttegro_js.CheckoutFailedEvent) => any;
137
+ onError?: (_error: Error) => any;
114
138
  onEvent?: (_event: CheckoutEvent) => any;
115
- }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
139
+ }>, {
140
+ presentation: CheckoutPresentation;
141
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
116
142
 
117
- export { Checkout, type CheckoutExposed, type CheckoutProps };
143
+ export { Checkout, type CheckoutExposed, type CheckoutProps, type CheckoutPropsBase };
package/dist/index.js CHANGED
@@ -16,13 +16,20 @@ var Checkout = defineComponent({
16
16
  appearance: Object,
17
17
  features: Object,
18
18
  locale: String,
19
- orderId: { type: String, required: true },
19
+ orderId: String,
20
+ purchaseIntentId: String,
21
+ presentation: {
22
+ type: String,
23
+ default: "embedded"
24
+ },
20
25
  timeout: Number,
21
26
  title: String
22
27
  },
23
28
  emits: {
29
+ canceled: (_event) => true,
24
30
  completed: (_event) => true,
25
- error: (_event) => true,
31
+ failed: (_event) => true,
32
+ error: (_error) => true,
26
33
  event: (_event) => true,
27
34
  ready: (_event) => true
28
35
  },
@@ -42,6 +49,8 @@ var Checkout = defineComponent({
42
49
  destroyCheckout();
43
50
  const target = container.value;
44
51
  const currentGeneration = generation;
52
+ let canceled = false;
53
+ let failed = false;
45
54
  if (!target) return;
46
55
  try {
47
56
  const inttegro = await loadInttegro();
@@ -52,6 +61,7 @@ var Checkout = defineComponent({
52
61
  features: props.features,
53
62
  locale: props.locale,
54
63
  orderId: props.orderId,
64
+ purchaseIntentId: props.purchaseIntentId,
55
65
  timeout: props.timeout,
56
66
  title: props.title
57
67
  })
@@ -63,13 +73,21 @@ var Checkout = defineComponent({
63
73
  checkout = instance;
64
74
  unsubscribe = instance.onEvent((event) => {
65
75
  emit("event", event);
76
+ if (event.type === "canceled") {
77
+ canceled = true;
78
+ emit("canceled", event);
79
+ }
66
80
  if (event.type === "ready") emit("ready", event);
67
81
  if (event.type === "completed") emit("completed", event);
68
- if (event.type === "error") emit("error", event);
82
+ if (event.type === "failed") {
83
+ failed = true;
84
+ emit("failed", event);
85
+ }
69
86
  });
70
- await instance.mount(target);
87
+ if (props.presentation === "modal") await instance.present();
88
+ else await instance.mount(target);
71
89
  } catch (error) {
72
- if (generation !== currentGeneration) return;
90
+ if (generation !== currentGeneration || canceled || failed) return;
73
91
  emit(
74
92
  "error",
75
93
  error instanceof Error ? error : new Error("Checkout failed to load.")
@@ -79,7 +97,14 @@ var Checkout = defineComponent({
79
97
  onMounted(mountCheckout);
80
98
  onBeforeUnmount(destroyCheckout);
81
99
  watch(
82
- () => [props.features, props.orderId, props.timeout, props.title],
100
+ () => [
101
+ props.features,
102
+ props.orderId,
103
+ props.purchaseIntentId,
104
+ props.presentation,
105
+ props.timeout,
106
+ props.title
107
+ ],
83
108
  () => void mountCheckout()
84
109
  );
85
110
  watch(
@@ -90,6 +115,7 @@ var Checkout = defineComponent({
90
115
  { deep: true }
91
116
  );
92
117
  expose({
118
+ dismiss: () => checkout?.dismiss(),
93
119
  focus: () => checkout?.focus(),
94
120
  update: (options) => checkout?.update(options)
95
121
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Checkout.ts"],"sourcesContent":["import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutErrorEvent,\n type CheckoutEvent,\n type CheckoutFeatures,\n} from '@inttegro/js'\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n type PropType,\n} from 'vue'\n\n/**\n * Props accepted by the Inttegro {@link Checkout} component.\n *\n * Changing `features`, `orderId`, `timeout`, or `title` replaces the hosted\n * controller. Changing `appearance` or `locale` updates it in place,\n * preserving payer progress where the hosted flow permits.\n *\n * @category Vue\n */\nexport interface CheckoutProps {\n /** Initial and reactive theme preference for hosted Checkout. */\n appearance?: CheckoutAppearance | undefined\n /** Hosted Checkout content and actions. Changing it replaces the controller. */\n features?: CheckoutFeatures | undefined\n /** Initial and reactive BCP 47 locale preference. */\n locale?: string | undefined\n /** Client-safe reference for the finalized Order being paid. */\n orderId: string\n /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */\n timeout?: number | undefined\n /** Accessible iframe title; defaults to `Checkout`. */\n title?: string | undefined\n}\n\n/**\n * Imperative operations exposed by {@link Checkout} through a Vue template ref.\n *\n * @category Vue\n */\nexport interface CheckoutExposed {\n /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when a controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Embeds Inttegro-hosted Checkout in a Vue application.\n *\n * The component owns the loader and controller lifecycle. It emits:\n *\n * - `ready` once the iframe is interactive;\n * - `event` for every sanitized Checkout lifecycle event;\n * - `completed` at the successful hosted terminal state; and\n * - `error` for loader/mount failures or sanitized hosted errors.\n *\n * Keep the component mounted while payment or confirmation is pending. On\n * unmount it removes its event subscription and permanently destroys the\n * controller.\n *\n * @example Use native Vue events\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { Checkout, type CheckoutExposed } from '@inttegro/vue'\n *\n * const props = defineProps<{ orderId: string }>()\n * const checkout = ref<CheckoutExposed>()\n * </script>\n *\n * <template>\n * <Checkout\n * ref=\"checkout\"\n * :order-id=\"props.orderId\"\n * :appearance=\"{ theme: 'system' }\"\n * @ready=\"checkout?.focus()\"\n * @completed=\"$router.push('/orders/complete')\"\n * @error=\"reportCheckoutError\"\n * />\n * </template>\n * ```\n *\n * @category Vue\n */\nexport const Checkout = defineComponent({\n name: 'InttegroCheckout',\n props: {\n appearance: Object as PropType<CheckoutAppearance>,\n features: Object as PropType<CheckoutFeatures>,\n locale: String,\n orderId: { type: String, required: true },\n timeout: Number,\n title: String,\n },\n emits: {\n completed: (_event: Extract<CheckoutEvent, { type: 'completed' }>) => true,\n error: (_event: CheckoutErrorEvent | Error) => true,\n event: (_event: CheckoutEvent) => true,\n ready: (_event: Extract<CheckoutEvent, { type: 'ready' }>) => true,\n },\n setup(props, { emit, expose }) {\n const container = ref<HTMLElement>()\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n let generation = 0\n\n function destroyCheckout() {\n generation += 1\n unsubscribe?.()\n unsubscribe = undefined\n checkout?.destroy()\n checkout = undefined\n }\n\n async function mountCheckout() {\n destroyCheckout()\n const target = container.value\n const currentGeneration = generation\n if (!target) return\n try {\n const inttegro = await loadInttegro()\n if (generation !== currentGeneration || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n appearance: props.appearance,\n features: props.features,\n locale: props.locale,\n orderId: props.orderId,\n timeout: props.timeout,\n title: props.title,\n }),\n )\n if (generation !== currentGeneration) {\n instance.destroy()\n return\n }\n checkout = instance\n unsubscribe = instance.onEvent((event) => {\n emit('event', event)\n if (event.type === 'ready') emit('ready', event)\n if (event.type === 'completed') emit('completed', event)\n if (event.type === 'error') emit('error', event)\n })\n await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration) return\n emit(\n 'error',\n error instanceof Error\n ? error\n : new Error('Checkout failed to load.'),\n )\n }\n }\n\n onMounted(mountCheckout)\n onBeforeUnmount(destroyCheckout)\n\n watch(\n () => [props.features, props.orderId, props.timeout, props.title],\n () => void mountCheckout(),\n )\n watch(\n () => [props.appearance, props.locale] as const,\n ([appearance, locale]) => {\n checkout?.update(definedOptions({ appearance, locale }))\n },\n { deep: true },\n )\n\n expose({\n focus: () => checkout?.focus(),\n update: (options: Parameters<CheckoutController['update']>[0]) =>\n checkout?.update(options),\n })\n\n return () => h('div', { ref: container })\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"],"mappings":";AAAA;AAAA,EACE;AAAA,OAMK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AA4EA,IAAM,WAAW,gBAAgB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS,EAAE,MAAM,QAAQ,UAAU,KAAK;AAAA,IACxC,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA,IACL,WAAW,CAAC,WAA0D;AAAA,IACtE,OAAO,CAAC,WAAuC;AAAA,IAC/C,OAAO,CAAC,WAA0B;AAAA,IAClC,OAAO,CAAC,WAAsD;AAAA,EAChE;AAAA,EACA,MAAM,OAAO,EAAE,MAAM,OAAO,GAAG;AAC7B,UAAM,YAAY,IAAiB;AACnC,QAAI;AACJ,QAAI;AACJ,QAAI,aAAa;AAEjB,aAAS,kBAAkB;AACzB,oBAAc;AACd,oBAAc;AACd,oBAAc;AACd,gBAAU,QAAQ;AAClB,iBAAW;AAAA,IACb;AAEA,mBAAe,gBAAgB;AAC7B,sBAAgB;AAChB,YAAM,SAAS,UAAU;AACzB,YAAM,oBAAoB;AAC1B,UAAI,CAAC,OAAQ;AACb,UAAI;AACF,cAAM,WAAW,MAAM,aAAa;AACpC,YAAI,eAAe,qBAAqB,CAAC,SAAU;AACnD,cAAM,WAAW,SAAS;AAAA,UACxB,eAAe;AAAA,YACb,YAAY,MAAM;AAAA,YAClB,UAAU,MAAM;AAAA,YAChB,QAAQ,MAAM;AAAA,YACd,SAAS,MAAM;AAAA,YACf,SAAS,MAAM;AAAA,YACf,OAAO,MAAM;AAAA,UACf,CAAC;AAAA,QACH;AACA,YAAI,eAAe,mBAAmB;AACpC,mBAAS,QAAQ;AACjB;AAAA,QACF;AACA,mBAAW;AACX,sBAAc,SAAS,QAAQ,CAAC,UAAU;AACxC,eAAK,SAAS,KAAK;AACnB,cAAI,MAAM,SAAS,QAAS,MAAK,SAAS,KAAK;AAC/C,cAAI,MAAM,SAAS,YAAa,MAAK,aAAa,KAAK;AACvD,cAAI,MAAM,SAAS,QAAS,MAAK,SAAS,KAAK;AAAA,QACjD,CAAC;AACD,cAAM,SAAS,MAAM,MAAM;AAAA,MAC7B,SAAS,OAAgB;AACvB,YAAI,eAAe,kBAAmB;AACtC;AAAA,UACE;AAAA,UACA,iBAAiB,QACb,QACA,IAAI,MAAM,0BAA0B;AAAA,QAC1C;AAAA,MACF;AAAA,IACF;AAEA,cAAU,aAAa;AACvB,oBAAgB,eAAe;AAE/B;AAAA,MACE,MAAM,CAAC,MAAM,UAAU,MAAM,SAAS,MAAM,SAAS,MAAM,KAAK;AAAA,MAChE,MAAM,KAAK,cAAc;AAAA,IAC3B;AACA;AAAA,MACE,MAAM,CAAC,MAAM,YAAY,MAAM,MAAM;AAAA,MACrC,CAAC,CAAC,YAAY,MAAM,MAAM;AACxB,kBAAU,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,MACzD;AAAA,MACA,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,WAAO;AAAA,MACL,OAAO,MAAM,UAAU,MAAM;AAAA,MAC7B,QAAQ,CAAC,YACP,UAAU,OAAO,OAAO;AAAA,IAC5B,CAAC;AAED,WAAO,MAAM,EAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/Checkout.ts"],"sourcesContent":["import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutEvent,\n type CheckoutFeatures,\n type CheckoutOptions,\n type CheckoutPresentation,\n} from '@inttegro/js'\nimport {\n defineComponent,\n h,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n type PropType,\n} from 'vue'\n\n/**\n * Props accepted by the Inttegro {@link Checkout} component.\n *\n * Changing `features`, the Checkout reference, `presentation`, `timeout`, or\n * `title` replaces the hosted controller. Changing `appearance` or `locale`\n * updates it in place, preserving payer progress where the hosted flow permits.\n *\n * @category Vue\n */\nexport interface CheckoutPropsBase {\n /** Initial and reactive theme preference for hosted Checkout. */\n appearance?: CheckoutAppearance | undefined\n /** Hosted Checkout content and actions. Changing it replaces the controller. */\n features?: CheckoutFeatures | undefined\n /** Initial and reactive BCP 47 locale preference. */\n locale?: string | undefined\n /** Displays Checkout inline by default or in an Inttegro-managed modal. */\n presentation?: CheckoutPresentation | undefined\n /** Mount timeout from 1,000–60,000 ms; defaults to 15,000 ms. */\n timeout?: number | undefined\n /** Accessible iframe title; defaults to `Checkout`. */\n title?: string | undefined\n}\n\nexport type CheckoutProps = CheckoutPropsBase &\n (\n | { orderId: string; purchaseIntentId?: never }\n | { orderId?: never; purchaseIntentId: string }\n )\n\n/**\n * Imperative operations exposed by {@link Checkout} through a Vue template ref.\n *\n * @category Vue\n */\nexport interface CheckoutExposed {\n /** Closes managed modal Checkout when it is open. */\n dismiss(): void\n /** Moves focus into Checkout when the controller is ready; otherwise does nothing. */\n focus(): void\n /** Applies a new locale or theme when a controller exists. */\n update(options: Parameters<CheckoutController['update']>[0]): void\n}\n\n/**\n * Displays Inttegro-hosted Checkout in a Vue application.\n *\n * The component owns the loader and controller lifecycle. It emits:\n *\n * - `ready` once the iframe is interactive;\n * - `event` for every sanitized Checkout lifecycle event;\n * - `canceled` when a payer dismisses managed modal Checkout;\n * - `completed` at the successful hosted terminal state; and\n * - `failed` for terminal Checkout failure.\n * - `error` for loader or mount failures.\n *\n * Keep the component mounted while payment or confirmation is pending. On\n * unmount it removes its event subscription and permanently destroys the\n * controller.\n *\n * @example Use native Vue events\n * ```vue\n * <script setup lang=\"ts\">\n * import { ref } from 'vue'\n * import { Checkout, type CheckoutExposed } from '@inttegro/vue'\n *\n * const props = defineProps<{ orderId: string }>()\n * const checkout = ref<CheckoutExposed>()\n * </script>\n *\n * <template>\n * <Checkout\n * ref=\"checkout\"\n * :order-id=\"props.orderId\"\n * presentation=\"modal\"\n * :appearance=\"{ theme: 'system' }\"\n * @ready=\"checkout?.focus()\"\n * @completed=\"$router.push('/orders/complete')\"\n * @error=\"reportCheckoutError\"\n * />\n * </template>\n * ```\n *\n * @category Vue\n */\nexport const Checkout = defineComponent({\n name: 'InttegroCheckout',\n props: {\n appearance: Object as PropType<CheckoutAppearance>,\n features: Object as PropType<CheckoutFeatures>,\n locale: String,\n orderId: String,\n purchaseIntentId: String,\n presentation: {\n type: String as PropType<CheckoutPresentation>,\n default: 'embedded',\n },\n timeout: Number,\n title: String,\n },\n emits: {\n canceled: (_event: Extract<CheckoutEvent, { type: 'canceled' }>) => true,\n completed: (_event: Extract<CheckoutEvent, { type: 'completed' }>) => true,\n failed: (_event: Extract<CheckoutEvent, { type: 'failed' }>) => true,\n error: (_error: Error) => true,\n event: (_event: CheckoutEvent) => true,\n ready: (_event: Extract<CheckoutEvent, { type: 'ready' }>) => true,\n },\n setup(props, { emit, expose }) {\n const container = ref<HTMLElement>()\n let checkout: CheckoutController | undefined\n let unsubscribe: (() => void) | undefined\n let generation = 0\n\n function destroyCheckout() {\n generation += 1\n unsubscribe?.()\n unsubscribe = undefined\n checkout?.destroy()\n checkout = undefined\n }\n\n async function mountCheckout() {\n destroyCheckout()\n const target = container.value\n const currentGeneration = generation\n let canceled = false\n let failed = false\n if (!target) return\n try {\n const inttegro = await loadInttegro()\n if (generation !== currentGeneration || !inttegro) return\n const instance = inttegro.createCheckout(\n definedOptions({\n appearance: props.appearance,\n features: props.features,\n locale: props.locale,\n orderId: props.orderId,\n purchaseIntentId: props.purchaseIntentId,\n timeout: props.timeout,\n title: props.title,\n }) as CheckoutOptions,\n )\n if (generation !== currentGeneration) {\n instance.destroy()\n return\n }\n checkout = instance\n unsubscribe = instance.onEvent((event) => {\n emit('event', event)\n if (event.type === 'canceled') {\n canceled = true\n emit('canceled', event)\n }\n if (event.type === 'ready') emit('ready', event)\n if (event.type === 'completed') emit('completed', event)\n if (event.type === 'failed') {\n failed = true\n emit('failed', event)\n }\n })\n if (props.presentation === 'modal') await instance.present()\n else await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration || canceled || failed) return\n emit(\n 'error',\n error instanceof Error\n ? error\n : new Error('Checkout failed to load.'),\n )\n }\n }\n\n onMounted(mountCheckout)\n onBeforeUnmount(destroyCheckout)\n\n watch(\n () => [\n props.features,\n props.orderId,\n props.purchaseIntentId,\n props.presentation,\n props.timeout,\n props.title,\n ],\n () => void mountCheckout(),\n )\n watch(\n () => [props.appearance, props.locale] as const,\n ([appearance, locale]) => {\n checkout?.update(definedOptions({ appearance, locale }))\n },\n { deep: true },\n )\n\n expose({\n dismiss: () => checkout?.dismiss(),\n focus: () => checkout?.focus(),\n update: (options: Parameters<CheckoutController['update']>[0]) =>\n checkout?.update(options),\n })\n\n return () => h('div', { ref: container })\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"],"mappings":";AAAA;AAAA,EACE;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAuFA,IAAM,WAAW,gBAAgB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,kBAAkB;AAAA,IAClB,cAAc;AAAA,MACZ,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AAAA,EACA,OAAO;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;AACT,iBAAK,UAAU,KAAK;AAAA,UACtB;AAAA,QACF,CAAC;AACD,YAAI,MAAM,iBAAiB,QAAS,OAAM,SAAS,QAAQ;AAAA,YACtD,OAAM,SAAS,MAAM,MAAM;AAAA,MAClC,SAAS,OAAgB;AACvB,YAAI,eAAe,qBAAqB,YAAY,OAAQ;AAC5D;AAAA,UACE;AAAA,UACA,iBAAiB,QACb,QACA,IAAI,MAAM,0BAA0B;AAAA,QAC1C;AAAA,MACF;AAAA,IACF;AAEA,cAAU,aAAa;AACvB,oBAAgB,eAAe;AAE/B;AAAA,MACE,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,MACA,MAAM,KAAK,cAAc;AAAA,IAC3B;AACA;AAAA,MACE,MAAM,CAAC,MAAM,YAAY,MAAM,MAAM;AAAA,MACrC,CAAC,CAAC,YAAY,MAAM,MAAM;AACxB,kBAAU,OAAO,eAAe,EAAE,YAAY,OAAO,CAAC,CAAC;AAAA,MACzD;AAAA,MACA,EAAE,MAAM,KAAK;AAAA,IACf;AAEA,WAAO;AAAA,MACL,SAAS,MAAM,UAAU,QAAQ;AAAA,MACjC,OAAO,MAAM,UAAU,MAAM;AAAA,MAC7B,QAAQ,CAAC,YACP,UAAU,OAAO,OAAO;AAAA,IAC5B,CAAC;AAED,WAAO,MAAM,EAAE,OAAO,EAAE,KAAK,UAAU,CAAC;AAAA,EAC1C;AACF,CAAC;AAED,SAAS,eAAqC,SAAuB;AACnE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAAA,EACnE;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inttegro/vue",
3
- "version": "0.2.0",
3
+ "version": "0.5.1",
4
4
  "description": "Vue 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.2.0"
35
+ "@inttegro/js": "0.5.1"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "vue": ">=3.4"
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/vue"
44
44
  },
45
45
  "homepage": "https://studio.inttegro.com/web/vue",