@flopay/vue 1.19.1 → 1.20.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
@@ -193,6 +193,12 @@ h(FloPayCheckout, {
193
193
  });
194
194
  ```
195
195
 
196
+ ### Stripe account switch
197
+
198
+ `@flopay/react`'s `FloPayCheckout` re-mounts its wallet buttons when a claim moves the checkout to another Stripe account, and tells the billing API it can. The Vue port of that Stripe account switch follows with SDK 2.0, and `FloPayCheckout` here gets no account-switch code before then.
199
+
200
+ Until then `@flopay/vue` does not send the `stripe-account-switch-v1` capability, so when a claim would change the Stripe account the billing API hides Apple Pay and Google Pay for the Vue checkout, as it does today; card and PayPal stay available. The detached create's `routingProducts` hint (the cart's product codes) comes from `@flopay/js` and is sent by the Vue checkout too, so a cart whose products use another Stripe account normally starts on that account from the first response and the claim does not move it.
201
+
196
202
  ## Errors
197
203
 
198
204
  Errors are `FloPayError` instances from `@flopay/shared`, emitted through `@error`.
@@ -0,0 +1,111 @@
1
+ import type { CheckoutRuntimeEvent } from '@flopay/js';
2
+ import { FloPayError } from '@flopay/shared';
3
+ import type { PropType } from 'vue';
4
+ /** The props of {@link FloPayRuntimeCheckout}, the same as @flopay/react's component. */
5
+ export interface FloPayRuntimeCheckoutProps {
6
+ publishableKey: string;
7
+ /** A session the merchant's server created. */
8
+ sessionId?: string;
9
+ nonce?: string;
10
+ /**
11
+ * An inline-created session, used when there is no `sessionId`: the billing API's create
12
+ * body, passed to the runtime as given (see `CheckoutRuntimeMountOptions.createSession`).
13
+ */
14
+ createSession?: Record<string, unknown>;
15
+ appearance?: Record<string, unknown>;
16
+ /** Merchant wording overrides, applied by the runtime over the strings the API returns. */
17
+ strings?: Record<string, string>;
18
+ /** The Flo-origin runtime script. */
19
+ runtimeUrl: string;
20
+ /** How long the runtime has to load before the `error` emit. Defaults to 10 seconds. */
21
+ runtimeTimeoutMs?: number;
22
+ }
23
+ /**
24
+ * A card checkout that runs from the Flo-hosted runtime. The component holds no checkout
25
+ * logic: it loads the runtime, mounts it in a container, passes its props through, relays the
26
+ * runtime's events as `event` emits, and reports a runtime that cannot load as an `error` emit.
27
+ * A change to the session (`sessionId`, `nonce`, `createSession`), the key or the runtime
28
+ * mounts the checkout again; `appearance` and `strings` update the mounted checkout.
29
+ */
30
+ export declare const FloPayRuntimeCheckout: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
31
+ publishableKey: {
32
+ type: StringConstructor;
33
+ required: true;
34
+ };
35
+ sessionId: {
36
+ type: StringConstructor;
37
+ default: undefined;
38
+ };
39
+ nonce: {
40
+ type: StringConstructor;
41
+ default: undefined;
42
+ };
43
+ createSession: {
44
+ type: PropType<Record<string, unknown>>;
45
+ default: undefined;
46
+ };
47
+ appearance: {
48
+ type: PropType<Record<string, unknown>>;
49
+ default: undefined;
50
+ };
51
+ strings: {
52
+ type: PropType<Record<string, string>>;
53
+ default: undefined;
54
+ };
55
+ runtimeUrl: {
56
+ type: StringConstructor;
57
+ required: true;
58
+ };
59
+ runtimeTimeoutMs: {
60
+ type: NumberConstructor;
61
+ default: undefined;
62
+ };
63
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
64
+ [key: string]: any;
65
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
66
+ event: (_event: CheckoutRuntimeEvent) => true;
67
+ error: (_error: FloPayError) => true;
68
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
69
+ publishableKey: {
70
+ type: StringConstructor;
71
+ required: true;
72
+ };
73
+ sessionId: {
74
+ type: StringConstructor;
75
+ default: undefined;
76
+ };
77
+ nonce: {
78
+ type: StringConstructor;
79
+ default: undefined;
80
+ };
81
+ createSession: {
82
+ type: PropType<Record<string, unknown>>;
83
+ default: undefined;
84
+ };
85
+ appearance: {
86
+ type: PropType<Record<string, unknown>>;
87
+ default: undefined;
88
+ };
89
+ strings: {
90
+ type: PropType<Record<string, string>>;
91
+ default: undefined;
92
+ };
93
+ runtimeUrl: {
94
+ type: StringConstructor;
95
+ required: true;
96
+ };
97
+ runtimeTimeoutMs: {
98
+ type: NumberConstructor;
99
+ default: undefined;
100
+ };
101
+ }>> & Readonly<{
102
+ onError?: ((_error: FloPayError) => any) | undefined;
103
+ onEvent?: ((_event: CheckoutRuntimeEvent) => any) | undefined;
104
+ }>, {
105
+ sessionId: string;
106
+ nonce: string;
107
+ createSession: Record<string, unknown>;
108
+ appearance: Record<string, unknown>;
109
+ strings: Record<string, string>;
110
+ runtimeTimeoutMs: number;
111
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
package/dist/index.cjs CHANGED
@@ -1109,15 +1109,16 @@ __export(index_exports, {
1109
1109
  FloPayCheckout: () => FloPayCheckout,
1110
1110
  FloPayPaymentMethodSetup: () => FloPayPaymentMethodSetup,
1111
1111
  FloPayProvider: () => FloPayProvider,
1112
+ FloPayRuntimeCheckout: () => FloPayRuntimeCheckout,
1112
1113
  SplitCardForm: () => SplitCardForm,
1113
1114
  VaultCardFields: () => VaultCardFields,
1114
- dropThirdPartyOnlyError: () => import_shared15.dropThirdPartyOnlyError,
1115
+ dropThirdPartyOnlyError: () => import_shared16.dropThirdPartyOnlyError,
1115
1116
  useCheckout: () => useCheckout,
1116
1117
  useFloPay: () => useFloPay,
1117
1118
  usePayPalFloPay: () => usePayPalFloPay
1118
1119
  });
1119
1120
  module.exports = __toCommonJS(index_exports);
1120
- var import_shared15 = require("@flopay/shared");
1121
+ var import_shared16 = require("@flopay/shared");
1121
1122
 
1122
1123
  // src/automatic-payment-button.ts
1123
1124
  var import_js3 = require("@flopay/js");
@@ -3961,7 +3962,10 @@ var FloPayCheckout = (0, import_vue7.defineComponent)({
3961
3962
  };
3962
3963
  Object.assign(params, {
3963
3964
  checkoutType: "embedded_checkout",
3964
- checkoutLayout: props.layout,
3965
+ // The API accepts only `default_layout` / `buttons_layout` /
3966
+ // `custom_layout`: map the prop through the shared rule React uses for
3967
+ // its create request (a filled `layout` slot is React's children).
3968
+ checkoutLayout: (0, import_shared9.resolveCheckoutLogLayout)(Boolean(slots.layout), props.layout),
3965
3969
  // AVS analytics metadata, as React sends it.
3966
3970
  ...props.enableAVS ? {
3967
3971
  avsCheck: true,
@@ -5338,17 +5342,104 @@ var FloPayPaymentMethodSetup = (0, import_vue13.defineComponent)({
5338
5342
  }
5339
5343
  });
5340
5344
 
5341
- // src/hooks.ts
5345
+ // src/flopay-runtime-checkout.ts
5346
+ var import_js4 = require("@flopay/js");
5347
+ var import_shared15 = require("@flopay/shared");
5342
5348
  var import_vue14 = require("vue");
5349
+ function asFloPayError(caught) {
5350
+ if (caught instanceof import_shared15.FloPayError) return caught;
5351
+ return new import_shared15.FloPayError("The checkout runtime failed to load.", "network_error", {
5352
+ code: "runtime_load_failed",
5353
+ cause: caught
5354
+ });
5355
+ }
5356
+ var FloPayRuntimeCheckout = (0, import_vue14.defineComponent)({
5357
+ name: "FloPayRuntimeCheckout",
5358
+ props: {
5359
+ publishableKey: { type: String, required: true },
5360
+ sessionId: { type: String, default: void 0 },
5361
+ nonce: { type: String, default: void 0 },
5362
+ createSession: { type: Object, default: void 0 },
5363
+ appearance: { type: Object, default: void 0 },
5364
+ strings: { type: Object, default: void 0 },
5365
+ runtimeUrl: { type: String, required: true },
5366
+ runtimeTimeoutMs: { type: Number, default: void 0 }
5367
+ },
5368
+ emits: {
5369
+ event: (_event) => true,
5370
+ error: (_error) => true
5371
+ },
5372
+ setup(props, { emit }) {
5373
+ const container = (0, import_vue14.ref)(null);
5374
+ let handle = null;
5375
+ let run = 0;
5376
+ const stop = () => {
5377
+ run += 1;
5378
+ handle?.unmount();
5379
+ handle = null;
5380
+ };
5381
+ const start = () => {
5382
+ stop();
5383
+ const current = run;
5384
+ (0, import_js4.loadCheckoutRuntime)({ runtimeUrl: props.runtimeUrl, timeoutMs: props.runtimeTimeoutMs }).then(
5385
+ (runtime) => {
5386
+ if (current !== run || !container.value) return;
5387
+ handle = runtime.mount(container.value, {
5388
+ publishableKey: props.publishableKey,
5389
+ sessionId: props.sessionId,
5390
+ nonce: props.nonce,
5391
+ createSession: props.createSession,
5392
+ appearance: props.appearance,
5393
+ strings: props.strings,
5394
+ onEvent: (event) => emit("event", event)
5395
+ });
5396
+ },
5397
+ (caught) => {
5398
+ if (current === run) emit("error", asFloPayError(caught));
5399
+ }
5400
+ );
5401
+ };
5402
+ (0, import_vue14.onMounted)(start);
5403
+ (0, import_vue14.watch)(
5404
+ [
5405
+ () => props.publishableKey,
5406
+ () => props.sessionId,
5407
+ () => props.nonce,
5408
+ // By value, so a new object with the same session does not mount again.
5409
+ () => props.createSession === void 0 ? void 0 : JSON.stringify(props.createSession),
5410
+ () => props.runtimeUrl,
5411
+ () => props.runtimeTimeoutMs
5412
+ ],
5413
+ () => start()
5414
+ );
5415
+ (0, import_vue14.watch)(
5416
+ () => props.appearance,
5417
+ (appearance) => {
5418
+ if (appearance !== void 0) handle?.update({ appearance });
5419
+ }
5420
+ );
5421
+ (0, import_vue14.watch)(
5422
+ () => props.strings,
5423
+ (strings) => {
5424
+ if (strings !== void 0) handle?.update({ strings });
5425
+ }
5426
+ );
5427
+ (0, import_vue14.onBeforeUnmount)(stop);
5428
+ return () => (0, import_vue14.h)("div", { ref: container, "data-flopay-runtime-checkout": "" });
5429
+ }
5430
+ });
5431
+
5432
+ // src/hooks.ts
5433
+ var import_vue15 = require("vue");
5343
5434
  init_context();
5344
5435
  function useFloPay() {
5345
- return (0, import_vue14.inject)(FLOPAY_CONTEXT, null)?.flopay ?? (0, import_vue14.shallowRef)(null);
5436
+ return (0, import_vue15.inject)(FLOPAY_CONTEXT, null)?.flopay ?? (0, import_vue15.shallowRef)(null);
5346
5437
  }
5347
5438
  function usePayPalFloPay() {
5348
- return (0, import_vue14.inject)(FLOPAY_CONTEXT, null)?.paypalFlopay ?? (0, import_vue14.shallowRef)(null);
5439
+ return (0, import_vue15.inject)(FLOPAY_CONTEXT, null)?.paypalFlopay ?? (0, import_vue15.shallowRef)(null);
5349
5440
  }
5350
5441
  function useCheckout() {
5351
- return (0, import_vue14.inject)(CHECKOUT_STATE, null) ?? (0, import_vue14.reactive)({ session: null, loading: false, error: null });
5442
+ return (0, import_vue15.inject)(CHECKOUT_STATE, null) ?? (0, import_vue15.reactive)({ session: null, loading: false, error: null });
5352
5443
  }
5353
5444
 
5354
5445
  // src/index.ts
@@ -5362,6 +5453,7 @@ init_provider();
5362
5453
  FloPayCheckout,
5363
5454
  FloPayPaymentMethodSetup,
5364
5455
  FloPayProvider,
5456
+ FloPayRuntimeCheckout,
5365
5457
  SplitCardForm,
5366
5458
  VaultCardFields,
5367
5459
  dropThirdPartyOnlyError,
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export type { FloPayCheckoutProps } from './flopay-checkout.js';
10
10
  export { FloPayCheckout } from './flopay-checkout.js';
11
11
  export type { FloPayPaymentMethodSetupCancelEvent, FloPayPaymentMethodSetupCompleteEvent, FloPayPaymentMethodSetupDeclineEvent, FloPayPaymentMethodSetupProps, } from './flopay-payment-method-setup-main.js';
12
12
  export { FloPayPaymentMethodSetup } from './flopay-payment-method-setup-main.js';
13
+ export type { FloPayRuntimeCheckoutProps } from './flopay-runtime-checkout.js';
14
+ export { FloPayRuntimeCheckout } from './flopay-runtime-checkout.js';
13
15
  export type { CheckoutState } from './hooks.js';
14
16
  export { useCheckout, useFloPay, usePayPalFloPay } from './hooks.js';
15
17
  export type { FloPayProviderProps } from './provider.js';
package/dist/index.mjs CHANGED
@@ -2862,7 +2862,10 @@ var FloPayCheckout = defineComponent4({
2862
2862
  };
2863
2863
  Object.assign(params, {
2864
2864
  checkoutType: "embedded_checkout",
2865
- checkoutLayout: props.layout,
2865
+ // The API accepts only `default_layout` / `buttons_layout` /
2866
+ // `custom_layout`: map the prop through the shared rule React uses for
2867
+ // its create request (a filled `layout` slot is React's children).
2868
+ checkoutLayout: resolveCheckoutLogLayout(Boolean(slots.layout), props.layout),
2866
2869
  // AVS analytics metadata, as React sends it.
2867
2870
  ...props.enableAVS ? {
2868
2871
  avsCheck: true,
@@ -3472,6 +3475,93 @@ var FloPayAutomaticPaymentButton = defineComponent5({
3472
3475
  }
3473
3476
  });
3474
3477
 
3478
+ // src/flopay-runtime-checkout.ts
3479
+ import { loadCheckoutRuntime } from "@flopay/js";
3480
+ import { FloPayError as FloPayError6 } from "@flopay/shared";
3481
+ import { defineComponent as defineComponent6, h as h6, onBeforeUnmount as onBeforeUnmount6, onMounted as onMounted4, ref as ref6, watch as watch4 } from "vue";
3482
+ function asFloPayError(caught) {
3483
+ if (caught instanceof FloPayError6) return caught;
3484
+ return new FloPayError6("The checkout runtime failed to load.", "network_error", {
3485
+ code: "runtime_load_failed",
3486
+ cause: caught
3487
+ });
3488
+ }
3489
+ var FloPayRuntimeCheckout = defineComponent6({
3490
+ name: "FloPayRuntimeCheckout",
3491
+ props: {
3492
+ publishableKey: { type: String, required: true },
3493
+ sessionId: { type: String, default: void 0 },
3494
+ nonce: { type: String, default: void 0 },
3495
+ createSession: { type: Object, default: void 0 },
3496
+ appearance: { type: Object, default: void 0 },
3497
+ strings: { type: Object, default: void 0 },
3498
+ runtimeUrl: { type: String, required: true },
3499
+ runtimeTimeoutMs: { type: Number, default: void 0 }
3500
+ },
3501
+ emits: {
3502
+ event: (_event) => true,
3503
+ error: (_error) => true
3504
+ },
3505
+ setup(props, { emit }) {
3506
+ const container = ref6(null);
3507
+ let handle = null;
3508
+ let run = 0;
3509
+ const stop = () => {
3510
+ run += 1;
3511
+ handle?.unmount();
3512
+ handle = null;
3513
+ };
3514
+ const start = () => {
3515
+ stop();
3516
+ const current = run;
3517
+ loadCheckoutRuntime({ runtimeUrl: props.runtimeUrl, timeoutMs: props.runtimeTimeoutMs }).then(
3518
+ (runtime) => {
3519
+ if (current !== run || !container.value) return;
3520
+ handle = runtime.mount(container.value, {
3521
+ publishableKey: props.publishableKey,
3522
+ sessionId: props.sessionId,
3523
+ nonce: props.nonce,
3524
+ createSession: props.createSession,
3525
+ appearance: props.appearance,
3526
+ strings: props.strings,
3527
+ onEvent: (event) => emit("event", event)
3528
+ });
3529
+ },
3530
+ (caught) => {
3531
+ if (current === run) emit("error", asFloPayError(caught));
3532
+ }
3533
+ );
3534
+ };
3535
+ onMounted4(start);
3536
+ watch4(
3537
+ [
3538
+ () => props.publishableKey,
3539
+ () => props.sessionId,
3540
+ () => props.nonce,
3541
+ // By value, so a new object with the same session does not mount again.
3542
+ () => props.createSession === void 0 ? void 0 : JSON.stringify(props.createSession),
3543
+ () => props.runtimeUrl,
3544
+ () => props.runtimeTimeoutMs
3545
+ ],
3546
+ () => start()
3547
+ );
3548
+ watch4(
3549
+ () => props.appearance,
3550
+ (appearance) => {
3551
+ if (appearance !== void 0) handle?.update({ appearance });
3552
+ }
3553
+ );
3554
+ watch4(
3555
+ () => props.strings,
3556
+ (strings) => {
3557
+ if (strings !== void 0) handle?.update({ strings });
3558
+ }
3559
+ );
3560
+ onBeforeUnmount6(stop);
3561
+ return () => h6("div", { ref: container, "data-flopay-runtime-checkout": "" });
3562
+ }
3563
+ });
3564
+
3475
3565
  // src/hooks.ts
3476
3566
  import { inject as inject3, reactive as reactive2, shallowRef as shallowRef4 } from "vue";
3477
3567
  function useFloPay() {
@@ -3491,6 +3581,7 @@ export {
3491
3581
  FloPayCheckout,
3492
3582
  FloPayPaymentMethodSetup,
3493
3583
  FloPayProvider,
3584
+ FloPayRuntimeCheckout,
3494
3585
  SplitCardForm,
3495
3586
  VaultCardFields,
3496
3587
  dropThirdPartyOnlyError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/vue",
3
- "version": "1.19.1",
3
+ "version": "1.20.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -36,8 +36,8 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@flopay/js": "1.19.1",
40
- "@flopay/shared": "1.19.1",
39
+ "@flopay/js": "1.20.1",
40
+ "@flopay/shared": "1.20.1",
41
41
  "@paypal/paypal-js": "^11.3.0",
42
42
  "@stripe/stripe-js": "^10.3.0"
43
43
  },