@flopay/vue

中文文档
1.14.11发布于 2026/11/14TypeScriptESM + CJS近 30 天下载 2640

Vue 3 components and composables for FloPay checkout, card setup and one-click payments: the Vue counterpart of @flopay/react, with the same props, events and behaviour.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Examples
  4. Public API
  5. PayPal buyer cancel
  6. Errors

@flopay/vue

Vue 3 components and composables for FloPay checkout, card setup and one-click payments: the Vue counterpart of @flopay/react, with the same props, events and behaviour.

Installation

npm install @flopay/vue

vue (>=3.3.0) is a peer dependency. @flopay/js and @flopay/shared are installed with the package.

Usage

Render FloPayCheckout with a session the merchant server created, or with an inline createSession draft. Notification callbacks are Vue events: React's onComplete is @complete in templates and onComplete in h().

import { FloPayCheckout } from '@flopay/vue';
import { h } from 'vue';

export default {
  setup() {
    return () =>
      h(FloPayCheckout, {
        sessionId: 'sess_123',
        nonce: 'nonce_123',
        onComplete: (result) => console.log(result.status),
        onDecline: (decline) => console.log(decline.message),
      });
  },
};

Browser work (session reads, SDK loading, the hosted card widget) starts in onMounted, so server rendering never touches window and renders the loading state.

Examples

Card setup from the Stripe-free subpath:

import { FloPayCardSetup } from '@flopay/vue/card-setup';
import { h } from 'vue';

const render = () =>
  h(FloPayCardSetup, {
    sessionId: 'sess_setup_123',
    nonce: 'nonce_setup_123',
    onComplete: (event) => console.log(event.sessionId),
  });

One-click payment with the buyer's saved payment method:

import { FloPayAutomaticPaymentButton } from '@flopay/vue';
import { h } from 'vue';

const render = () =>
  h(FloPayAutomaticPaymentButton, {
    clientId: 'client_123',
    account: { userId: 'user_123', email: '[email protected]' },
    products: [{ code: 'pro-monthly', quantity: 1 }],
    successUrl: 'https://example.com/success',
    cancelUrl: 'https://example.com/cancel',
    onSuccess: (event) => console.log(event.autoCompleted),
  });

Public API

Every @flopay/react component and hook has a same-name Vue export. React's notification callbacks are Vue events with the same payloads.

ExportReact (@flopay/react)Vue (@flopay/vue)
FloPayProvider<FloPayProvider>FloPayProvider, provided to descendants; @instrument
FloPayCheckout<FloPayCheckout>FloPayCheckout: @complete, @decline, @cancel, @error, @button-click
SplitCardForm<SplitCardForm>SplitCardForm: @complete, @decline, @cancel, @error
VaultCardFields<VaultCardFields>VaultCardFields: @ready, @error, @validation
DirectPayPalButton<DirectPayPalButton>DirectPayPalButton: @complete, @decline, @cancel, @error
FloPayAutomaticPaymentButton<FloPayAutomaticPaymentButton>FloPayAutomaticPaymentButton: @success, @error, @decline
FloPayCardSetup<FloPayCardSetup>FloPayCardSetup: @ready, @complete, @decline, @cancel, @error
FloPayPaymentMethodSetup<FloPayPaymentMethodSetup>FloPayPaymentMethodSetup
useFloPayuseFloPay()useFloPay(): a ref, null until loadFloPay() resolves
usePayPalFloPayusePayPalFloPay()usePayPalFloPay(): a ref
useCheckoutuseCheckout()useCheckout(): a reactive checkout state
FloPayCardSetupErrorFloPayCardSetupErrorFloPayCardSetupError
dropThirdPartyOnlyErrordropThirdPartyOnlyErrordropThirdPartyOnlyError

React children and custom layouts are slots. FloPayCheckout's layout slot replaces the built-in form, and a SplitCardForm inside it receives the session, nonce and submitLabel unless it sets them itself.

Entry points: @flopay/vue, @flopay/vue/card-setup and @flopay/vue/payment-method-setup.

PayPal buyer cancel

FloPayCheckout, SplitCardForm and DirectPayPalButton emit cancel (@cancel, React's onCancel) once per click when the buyer closes the PayPal pop-up, or returns from PayPal's app switch, without approving. The payload is a FloPayPaymentCancelEvent: { status: 'cancelled', sessionId, provider: 'paypal', paymentMethodType }. sessionId is the attempt's session (the click-time patch's, otherwise the checkout's), and paymentMethodType is paypal_vaulted when the session advertises an order or setup_token, otherwise paypal.

It is never emitted for an approval, a decline (that stays @decline), a blocked pop-up, a load, render or eligibility failure, or a click your runBeforeButtonClick gate stopped, and a repeated cancel for the same click is ignored. It covers the direct PayPal button only (sessions with gateways.paypal). The button stays rendered for the next click, and nothing changes if you don't listen for it.

A "Didn't work? Pay another way" prompt that moves the buyer to the card form:

import { FloPayCheckout, type FloPayPaymentCancelEvent } from '@flopay/vue';
import { defineComponent, h, ref } from 'vue';

export default defineComponent({
  setup() {
    const cancelled = ref<FloPayPaymentCancelEvent | null>(null);
    const cardForm = ref<HTMLElement | null>(null);
    return () => [
      cancelled.value
        ? h('div', { role: 'status' }, [
            "Didn't work? Pay another way. ",
            h(
              'button',
              { type: 'button', onClick: () => cardForm.value?.focus() },
              'Pay by card or Google Pay',
            ),
          ])
        : null,
      h('div', { ref: cardForm, tabindex: -1 }, [
        h(FloPayCheckout, {
          sessionId: 'sess_123',
          nonce: 'nonce_123',
          onCancel: (event: FloPayPaymentCancelEvent) => {
            cancelled.value = event;
          },
        }),
      ]),
    ];
  },
});

Errors

Errors are FloPayError instances from @flopay/shared, emitted through @error.

CodeMeaning
UnsupportedBackendVaultCapabilityThe session has no hosted vault card form and no other usable method.
stored_payment_method_unsupportedThe buyer's saved method cannot be charged; ask for another method.
MissingCheckoutSessionTokenA session id was given without its nonce.
network_request_failedType network_error. FloPayCheckout could not start because creating or reading the session never got a response, after the SDK's retries. cause holds the original error; sessionId is set when the session already existed.
CheckoutInitializationFailedType api_error. FloPayCheckout could not start for a reason that is not a network failure, with sessionId set once the session exists.

Setup surfaces emit FloPayCardSetupError, whose retryable says whether trying again can help.

版本与发布记录

@flopay/vue 共发布 18 个版本,首次发布于 2026/10/20;过去 12 个月发布了 18 个版本。

版本发布日期距今
1.14.11latest2026/11/141 天前
1.14.102026/11/141 天前
1.14.92026/11/132 天前
1.14.82026/11/123 天前
1.14.72026/11/114 天前
1.14.62026/11/114 天前

关于 @flopay/vue 的常见问题

@flopay/vue 是什么?

Vue 3 components and composables for FloPay checkout, card setup and one-click payments: the Vue counterpart of @flopay/react, with the same props, events and behaviour.

如何安装 @flopay/vue?

在项目目录运行 npm install @flopay/vue,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(>=3.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flopay/vue 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flopay/vue 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flopay/vue 可以商用吗?

@flopay/vue 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@flopay/vue 的下载量有多少?

根据 npm 官方下载统计,@flopay/vue 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,640 次,日均约 88 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flopay/vue 还在维护吗?

最新版本 1.14.11 发布于 2026/11/14(1 天前);至今共发布 18 个版本,其中过去 12 个月发布了 18 个;首次发布于 2026/10/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。