@inttegro/vue 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
@@ -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,11 +33,17 @@ 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
48
  error: (_event) => true,
43
49
  event: (_event) => true,
@@ -59,6 +65,7 @@ var Checkout = (0, import_vue.defineComponent)({
59
65
  destroyCheckout();
60
66
  const target = container.value;
61
67
  const currentGeneration = generation;
68
+ let canceled = false;
62
69
  if (!target) return;
63
70
  try {
64
71
  const inttegro = await (0, import_js.loadInttegro)();
@@ -69,6 +76,7 @@ var Checkout = (0, import_vue.defineComponent)({
69
76
  features: props.features,
70
77
  locale: props.locale,
71
78
  orderId: props.orderId,
79
+ purchaseIntentId: props.purchaseIntentId,
72
80
  timeout: props.timeout,
73
81
  title: props.title
74
82
  })
@@ -80,13 +88,18 @@ var Checkout = (0, import_vue.defineComponent)({
80
88
  checkout = instance;
81
89
  unsubscribe = instance.onEvent((event) => {
82
90
  emit("event", event);
91
+ if (event.type === "canceled") {
92
+ canceled = true;
93
+ emit("canceled", event);
94
+ }
83
95
  if (event.type === "ready") emit("ready", event);
84
96
  if (event.type === "completed") emit("completed", event);
85
97
  if (event.type === "error") emit("error", event);
86
98
  });
87
- await instance.mount(target);
99
+ if (props.presentation === "modal") await instance.present();
100
+ else await instance.mount(target);
88
101
  } catch (error) {
89
- if (generation !== currentGeneration) return;
102
+ if (generation !== currentGeneration || canceled) return;
90
103
  emit(
91
104
  "error",
92
105
  error instanceof Error ? error : new Error("Checkout failed to load.")
@@ -96,7 +109,14 @@ var Checkout = (0, import_vue.defineComponent)({
96
109
  (0, import_vue.onMounted)(mountCheckout);
97
110
  (0, import_vue.onBeforeUnmount)(destroyCheckout);
98
111
  (0, import_vue.watch)(
99
- () => [props.features, props.orderId, props.timeout, props.title],
112
+ () => [
113
+ props.features,
114
+ props.orderId,
115
+ props.purchaseIntentId,
116
+ props.presentation,
117
+ props.timeout,
118
+ props.title
119
+ ],
100
120
  () => void mountCheckout()
101
121
  );
102
122
  (0, import_vue.watch)(
@@ -107,6 +127,7 @@ var Checkout = (0, import_vue.defineComponent)({
107
127
  { deep: true }
108
128
  );
109
129
  expose({
130
+ dismiss: () => checkout?.dismiss(),
110
131
  focus: () => checkout?.focus(),
111
132
  update: (options) => checkout?.update(options)
112
133
  });
@@ -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,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,8BAAU,aAAa;AACvB,oCAAgB,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,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":[]}
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 CheckoutErrorEvent,\n CheckoutEvent,\n CheckoutFeatures,\n CheckoutPresentation,\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 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 * - `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 * 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 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 let canceled = 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 === 'error') emit('error', event)\n })\n if (props.presentation === 'modal') await instance.present()\n else await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration || canceled) 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;AAAA;AAAA;AAAA;;;ACAA,gBASO;AACP,iBAQO;AAsFA,IAAM,eAAW,4BAAgB;AAAA,EACtC,MAAM;AAAA,EACN,OAAO;AAAA,IACL,YAAY;AAAA,IACZ,UAAU;AAAA,IACV,QAAQ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
  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, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
3
+ export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, 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
59
  * - `error` for loader/mount failures or sanitized hosted errors.
50
60
  *
@@ -66,6 +76,7 @@ interface CheckoutExposed {
66
76
  * <Checkout
67
77
  * ref="checkout"
68
78
  * :order-id="props.orderId"
79
+ * presentation="modal"
69
80
  * :appearance="{ theme: 'system' }"
70
81
  * @ready="checkout?.focus()"
71
82
  * @completed="$router.push('/orders/complete')"
@@ -80,15 +91,20 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
80
91
  appearance: PropType<CheckoutAppearance>;
81
92
  features: PropType<CheckoutFeatures>;
82
93
  locale: StringConstructor;
83
- orderId: {
84
- type: StringConstructor;
85
- required: true;
94
+ orderId: StringConstructor;
95
+ purchaseIntentId: StringConstructor;
96
+ presentation: {
97
+ type: PropType<CheckoutPresentation>;
98
+ default: string;
86
99
  };
87
100
  timeout: NumberConstructor;
88
101
  title: StringConstructor;
89
102
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
90
103
  [key: string]: any;
91
104
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
105
+ canceled: (_event: Extract<CheckoutEvent, {
106
+ type: "canceled";
107
+ }>) => true;
92
108
  completed: (_event: Extract<CheckoutEvent, {
93
109
  type: "completed";
94
110
  }>) => true;
@@ -101,17 +117,22 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
101
117
  appearance: PropType<CheckoutAppearance>;
102
118
  features: PropType<CheckoutFeatures>;
103
119
  locale: StringConstructor;
104
- orderId: {
105
- type: StringConstructor;
106
- required: true;
120
+ orderId: StringConstructor;
121
+ purchaseIntentId: StringConstructor;
122
+ presentation: {
123
+ type: PropType<CheckoutPresentation>;
124
+ default: string;
107
125
  };
108
126
  timeout: NumberConstructor;
109
127
  title: StringConstructor;
110
128
  }>> & Readonly<{
111
- onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
129
+ onCanceled?: (_event: _inttegro_js.CheckoutCanceledEvent) => any;
112
130
  onReady?: (_event: _inttegro_js.CheckoutReadyEvent) => any;
131
+ onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
113
132
  onError?: (_event: CheckoutErrorEvent | Error) => any;
114
133
  onEvent?: (_event: CheckoutEvent) => any;
115
- }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
134
+ }>, {
135
+ presentation: CheckoutPresentation;
136
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
116
137
 
117
- export { Checkout, type CheckoutExposed, type CheckoutProps };
138
+ export { Checkout, type CheckoutExposed, type CheckoutProps, type CheckoutPropsBase };
package/dist/index.d.ts CHANGED
@@ -1,50 +1,60 @@
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, CheckoutErrorEvent, CheckoutController } from '@inttegro/js';
3
+ export { CheckoutAppearance, CheckoutErrorEvent, CheckoutEvent, CheckoutFeatures, 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
59
  * - `error` for loader/mount failures or sanitized hosted errors.
50
60
  *
@@ -66,6 +76,7 @@ interface CheckoutExposed {
66
76
  * <Checkout
67
77
  * ref="checkout"
68
78
  * :order-id="props.orderId"
79
+ * presentation="modal"
69
80
  * :appearance="{ theme: 'system' }"
70
81
  * @ready="checkout?.focus()"
71
82
  * @completed="$router.push('/orders/complete')"
@@ -80,15 +91,20 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
80
91
  appearance: PropType<CheckoutAppearance>;
81
92
  features: PropType<CheckoutFeatures>;
82
93
  locale: StringConstructor;
83
- orderId: {
84
- type: StringConstructor;
85
- required: true;
94
+ orderId: StringConstructor;
95
+ purchaseIntentId: StringConstructor;
96
+ presentation: {
97
+ type: PropType<CheckoutPresentation>;
98
+ default: string;
86
99
  };
87
100
  timeout: NumberConstructor;
88
101
  title: StringConstructor;
89
102
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
90
103
  [key: string]: any;
91
104
  }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
105
+ canceled: (_event: Extract<CheckoutEvent, {
106
+ type: "canceled";
107
+ }>) => true;
92
108
  completed: (_event: Extract<CheckoutEvent, {
93
109
  type: "completed";
94
110
  }>) => true;
@@ -101,17 +117,22 @@ declare const Checkout: vue.DefineComponent<vue.ExtractPropTypes<{
101
117
  appearance: PropType<CheckoutAppearance>;
102
118
  features: PropType<CheckoutFeatures>;
103
119
  locale: StringConstructor;
104
- orderId: {
105
- type: StringConstructor;
106
- required: true;
120
+ orderId: StringConstructor;
121
+ purchaseIntentId: StringConstructor;
122
+ presentation: {
123
+ type: PropType<CheckoutPresentation>;
124
+ default: string;
107
125
  };
108
126
  timeout: NumberConstructor;
109
127
  title: StringConstructor;
110
128
  }>> & Readonly<{
111
- onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
129
+ onCanceled?: (_event: _inttegro_js.CheckoutCanceledEvent) => any;
112
130
  onReady?: (_event: _inttegro_js.CheckoutReadyEvent) => any;
131
+ onCompleted?: (_event: _inttegro_js.CheckoutCompletedEvent) => any;
113
132
  onError?: (_event: CheckoutErrorEvent | Error) => any;
114
133
  onEvent?: (_event: CheckoutEvent) => any;
115
- }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
134
+ }>, {
135
+ presentation: CheckoutPresentation;
136
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
116
137
 
117
- export { Checkout, type CheckoutExposed, type CheckoutProps };
138
+ export { Checkout, type CheckoutExposed, type CheckoutProps, type CheckoutPropsBase };
package/dist/index.js CHANGED
@@ -16,11 +16,17 @@ 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
31
  error: (_event) => true,
26
32
  event: (_event) => true,
@@ -42,6 +48,7 @@ var Checkout = defineComponent({
42
48
  destroyCheckout();
43
49
  const target = container.value;
44
50
  const currentGeneration = generation;
51
+ let canceled = false;
45
52
  if (!target) return;
46
53
  try {
47
54
  const inttegro = await loadInttegro();
@@ -52,6 +59,7 @@ var Checkout = defineComponent({
52
59
  features: props.features,
53
60
  locale: props.locale,
54
61
  orderId: props.orderId,
62
+ purchaseIntentId: props.purchaseIntentId,
55
63
  timeout: props.timeout,
56
64
  title: props.title
57
65
  })
@@ -63,13 +71,18 @@ var Checkout = defineComponent({
63
71
  checkout = instance;
64
72
  unsubscribe = instance.onEvent((event) => {
65
73
  emit("event", event);
74
+ if (event.type === "canceled") {
75
+ canceled = true;
76
+ emit("canceled", event);
77
+ }
66
78
  if (event.type === "ready") emit("ready", event);
67
79
  if (event.type === "completed") emit("completed", event);
68
80
  if (event.type === "error") emit("error", event);
69
81
  });
70
- await instance.mount(target);
82
+ if (props.presentation === "modal") await instance.present();
83
+ else await instance.mount(target);
71
84
  } catch (error) {
72
- if (generation !== currentGeneration) return;
85
+ if (generation !== currentGeneration || canceled) return;
73
86
  emit(
74
87
  "error",
75
88
  error instanceof Error ? error : new Error("Checkout failed to load.")
@@ -79,7 +92,14 @@ var Checkout = defineComponent({
79
92
  onMounted(mountCheckout);
80
93
  onBeforeUnmount(destroyCheckout);
81
94
  watch(
82
- () => [props.features, props.orderId, props.timeout, props.title],
95
+ () => [
96
+ props.features,
97
+ props.orderId,
98
+ props.purchaseIntentId,
99
+ props.presentation,
100
+ props.timeout,
101
+ props.title
102
+ ],
83
103
  () => void mountCheckout()
84
104
  );
85
105
  watch(
@@ -90,6 +110,7 @@ var Checkout = defineComponent({
90
110
  { deep: true }
91
111
  );
92
112
  expose({
113
+ dismiss: () => checkout?.dismiss(),
93
114
  focus: () => checkout?.focus(),
94
115
  update: (options) => checkout?.update(options)
95
116
  });
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,MA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,"sources":["../src/Checkout.ts"],"sourcesContent":["import {\n loadInttegro,\n type CheckoutAppearance,\n type CheckoutController,\n type CheckoutErrorEvent,\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 * - `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 * 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 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 let canceled = 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 === 'error') emit('error', event)\n })\n if (props.presentation === 'modal') await instance.present()\n else await instance.mount(target)\n } catch (error: unknown) {\n if (generation !== currentGeneration || canceled) 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,OAQK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAsFA,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,SA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AK;AAAA,QACjD,CAAC;AACD,YAAI,MAAM,iBAAiB,QAAS,OAAM,SAAS,QAAQ;AAAA,YACtD,OAAM,SAAS,MAAM,MAAM;AAAA,MAClC,SAAS,OAAgB;AACvB,YAAI,eAAe,qBAAqB,SAAU;AAClD;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.4.0",
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.4.0"
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",