@authvia/payment-method-create

中文文档
2.2.2发布于 2026/11/06MITTypeScriptESM + CJS近 30 天下载 1917

Authvia Payment Method Form Web Component - Payment method form built with Vue 3 and Vuetify 3

原始使用文档
文档目录23 节
  1. Requirements
  2. Installation
  3. Features (summary)
  4. Vue: register the plugin
  5. Vue: use the component
  6. Web component
  7. Web component events
  8. Sentry behavior
  9. Props (overview)
  10. paymentMethodDisplay
  11. Paze ( paze )
  12. PayPal / Venmo
  13. Stable styling hook classes (overrides)
  14. CSS variables
  15. Development
  16. Bundle and assets
  17. Browser support
  18. Changelog
  19. Version 1.0.3
  20. Version 1.0.2
  21. Documentation (current)
  22. License
  23. Support

Authvia Payment Method Form

Vue 3 + Vuetify 3 component and standalone web component for adding a saved payment method (card, ACH, PayPal, Venmo, Paze, and related options). You choose which methods to expose; only enabled methods appear. On success the host receives a payment method id.

Full prop and behavior notes live in Storybook (AuthviaPaymentMethodForm story docs) and in exported TypeScript types.

Requirements

  • Vue >= 3.4.0
  • Vuetify 3.x (your app creates the Vuetify instance; this package does not)
  • MDI font CSS on the host page (Material Design Icons)

If Vue, Vuetify, or styles are missing in a web-component embed, the element may emit authvia:dependency-missing.

Installation

npm install @authvia/payment-method-create

Exports:

  • Vue plugin / module: @authvia/payment-method-create (default build)
  • Standalone web component: @authvia/payment-method-create/web-component

Features (summary)

  • Token: A valid JWT is required for the inner form to render. The token must include https://authvia.com/uuid and payment_methods:create in scope. Missing, empty, invalid, or expired tokens keep the form hidden; the wrapper emits error as { phase: 'init', error } and logs a warning, and does not emit ready. ready is emitted only after the token passes validation.
  • Enabled methods: Props such as card, ach, paypal, venmo, and paze control what appears. Methods you do not configure stay off the list.
  • Runtime errors: Failures while saving emit error with a payload that usually includes a message string (shape is not { phase: 'init', … }). Incomplete Paze or PayPal/Venmo (for non-payouts intent) config hides those methods in the list instead of erroring on open. The embed usually stays mounted so the user can retry.
  • Sentry: Supports standalone widget ownership (VITE_WIDGET_SENTRY_DSN) and host-owned ownership (VITE_SENTRY_EMBED_MODE=lock or window.__AUTHVIA_EMBED__.sentry='host') without double-init.
  • Success: success carries payment method details (see Events). The host decides navigation or hiding the embed.
  • Styling: Accent color, border radius, and field variant are configurable; CSS variables use the --avwc-* prefix on the form root.

Vue: register the plugin

Your application must call createVuetify() (and load Vuetify styles + MDI) before registering this plugin.

import { createApp } from 'vue';
import { createVuetify } from 'vuetify';
import AuthviaPaymentMethodFormPlugin from '@authvia/payment-method-create';
import App from './App.vue';

const app = createApp(App);
const vuetify = createVuetify();

app.use(vuetify);
app.use(AuthviaPaymentMethodFormPlugin);
app.mount('#app');

Named export AuthviaPaymentMethodFormPlugin is also available for explicit imports.

Vue: use the component

<template>
  <AuthviaPaymentMethodForm
    :token="token"
    merchant-id="demo-merchant"
    customer-ref="demo-customer"
    intent="payments"
    :card="{ demoMode: false }"
    :ach="{ demoMode: false, online: true }"
    @ready="onReady"
    @success="onSuccess"
    @error="onError"
  />
</template>

<script setup lang="ts">
import { AuthviaPaymentMethodForm } from '@authvia/payment-method-create';

function onReady(): void {
  /* JWT passed validation; inner form can render */
}

function onSuccess(detail: unknown): void {
  /* includes paymentMethodId — see types */
}

function onError(detail: unknown): void {
  /* init: { phase: 'init', error }; runtime: often { message } */
}
</script>

Web component

Load Vue 3, Vuetify CSS, and MDI before the bundle. Use the data- prefix for attributes; object props are JSON strings on the element.

See demo.html in this repo for a full page example.

<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" data-vuetify />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" data-mdi />
<authvia-create-payment-method-form
  data-token="YOUR_JWT"
  data-merchant-id="demo-merchant"
  data-customer-ref="demo-customer"
  data-intent="payments"
  data-card='{"demoMode":false,"submitBtnText":"Add card"}'
  data-color="#4CAF50"
  data-border-radius="1rem"
></authvia-create-payment-method-form>

Load the built script after Vue (for example the output of npm run build:wc):

<script type="module" src="https://cdn.authvia.com/web-components/authvia-payment-method-create/authvia-payment-method-create.js"></script>

Web component events

Listen on the custom element for:

Eventdetail
readyEmitted only when the JWT passes validation (non-empty, parseable, not expired, required scope). Not emitted for missing, invalid, expired, or under-scoped tokens; use error with { phase: 'init', error } instead.
submitEmitted from some inner flows (for example ACH / PayPal) with form-related payloads.
successSaved payment method; includes paymentMethodId in the normalized payload.
errorInit failures: { phase: 'init', error }. Runtime: often { message: string } or similar.
authvia:dependency-missingHost is missing Vue, Vuetify, or required styles.
<script>
  const component = document.querySelector('authvia-create-payment-method-form');
  component?.addEventListener('ready', () => { /* … */ });
  component?.addEventListener('success', (e) => { console.log(e.detail); });
  component?.addEventListener('error', (e) => { console.log(e.detail); });
</script>

Sentry behavior

The package uses a single-client ownership model:

  • Standalone widget mode: set VITE_WIDGET_SENTRY_DSN; the widget calls Sentry.init once and tags events with component=payment-method-create and integration=standalone-web-component.
  • Embedded host mode (Lock or another host): set VITE_SENTRY_EMBED_MODE=lock at build time, or set window.__AUTHVIA_EMBED__.sentry = 'host' before widget mount; the widget skips Sentry.init and attaches handlers to the active host client.
  • No active Sentry client: capture helpers are safe no-ops.

Supported Sentry env vars:

VariablePurposeDefault
VITE_WIDGET_SENTRY_DSNDSN for standalone widget ownershipunset
VITE_SENTRY_EMBED_MODESet to lock to force host-owned modeunset
VITE_SENTRY_RELEASEOptional release version sent to Sentryunset
VITE_SENTRY_REPLAY_SESSION_SAMPLE_RATESession replay sample rate (0..1)0
VITE_SENTRY_REPLAY_ON_ERROR_SAMPLE_RATEReplay-on-error sample rate (0..1)1

Props (overview)

Details and examples match Storybook (src/components/AuthviaPaymentMethodForm.stories.ts).

AreaProps
Auth / contexttoken, merchantId, customerRef, intent
Methodscard, ach, paypal, venmo, paze
List UIpaymentMethodDisplay (titles, subtitles, order; optional root gap)
Legal / footerterms (privacy + terms links)
BehaviorforgetHidden, forgetDefault
Stylingcolor (default #4CAF50, from DEFAULT_AVWC_PRIMARY_COLOR), borderRadius (default 1rem, from DEFAULT_AVWC_BORDER_RADIUS), variant (default outlined, from DEFAULT_AVWC_FIELD_VARIANT), vuetifyOverrides (web component: plain CSS string for Shadow DOM)

paymentMethodDisplay

Controls the payment method picker list (labels and order). It does not turn methods on or off; use card, ach, paypal, etc. for that.

FieldDescription
gap (root, optional)Vertical space between option rows. Any CSS length (1rem, 12px, …). If omitted, this prop does not add spacing; layout matches the previous behavior (no list-level gap from this object).
card, ach, paypal, venmo, pazeOptional title, subtitle, and order. Lower order values appear higher in the list.

Vue

:payment-method-display="{
  gap: '1rem',
  card: { title: 'Credit / debit card', subtitle: '…', order: 1 },
  ach: { title: 'Bank account', subtitle: '…', order: 2 }
}"

Web component (data-payment-method-display): pass a single JSON object string. Use commas between properties. Invalid JSON is ignored (check the console).

data-payment-method-display='{"gap":"1rem","card":{"title":"Card","order":1},"ach":{"title":"Bank","order":2}}'

Paze (paze)

Requires amount, clientId, profileId, and name on the object you pass; all must be non-empty (after trim). If any are missing or blank, Paze is not shown in the picker. The inner flow runs in two steps: Initializing Paze (SDK load) then Processing Paze payment (checkout → complete → create). Failures emit error and return the user to the payment method list without an inline error banner on that step; details are logged for developers.

PayPal / Venmo

  • intent="payouts": paypal and venmo can be booleans; PayPal and Venmo stay listed even when merchantId is incomplete (same as before for payouts).
  • intent="payments" (and any intent other than payouts): PayPal and Venmo appear in the picker only when merchantId is non-empty on the resolved wallet settings and the build defines VITE_APP_PAYPAL_CLIENT_ID. Otherwise those rows are hidden (same rules as the former click-time error, without showing a dead option).
  • Pass merchantId and optional redirectUrl on the paypal / venmo object when you want the payments flow to succeed.

Stable styling hook classes (overrides)

Use these hooks in data-vuetify-overrides (web component) or host CSS. Canonical strings live in src/constants/avwcStylingHooks.ts (avwcPaymentMethodFormHooks).

ClassWhere
avwc-payment-method-form__rootMain form wrapper (AuthviaPaymentMethodForm)
avwc-payment-method-form__options-rootOptions container (AuthviaPaymentMethodOptions v-container)
avwc-payment-method-form__options-cardPayment method selection v-card
avwc-payment-method-form__options-listList area wrapping picker rows
avwc-payment-method-form__method-dialogEach payment-method v-dialog content v-card
avwc-payment-method-form__method-rowEach picker row (AuthviaPaymentMethodCard)
avwc-payment-method-form__credit-card-sectionCredit card block inside the card/PayPal dialog
avwc-payment-method-form__ach-rootACH add-bank flow root (AuthviaPaymentMethodAddAch)

Inside each picker row (data-vuetify-overrides): combine with the row hook, e.g. .avwc-payment-method-form__method-row .payment-method-card__title { color: #1565c0 !important; } for title text, .payment-method-card__logo-slot for icon tint, .payment-method-card__subtitle for the description line.

CSS variables

The form root sets theming variables, including:

  • --avwc-color (accent; mirrors color prop, default #4CAF50 from DEFAULT_AVWC_PRIMARY_COLOR)
  • --avwc-border-radius (mirrors borderRadius, default 1rem from DEFAULT_AVWC_BORDER_RADIUS)

Additional tokens (for example --avwc-text-color-light) are documented in variables.css and Storybook.

Development

Prerequisites: Node.js 18+, npm 9+.

npm install
npm run dev              # app dev server
npm run build            # Vue module
npm run build:wc         # web component
npm run type-check
npm run lint
npm test

Bundle and assets

  • The Vue module expects Vue and Vuetify as peer dependencies; your app supplies Vuetify and MDI.
  • The standalone web component bundles Vuetify JavaScript but expects Vuetify CSS + MDI from the host (same as demo.html).
  • Component styles ship with the JS; add Vuetify + MDI at the app level.

Browser support

Chrome 88+, Firefox 85+, Safari 14+, Edge 88+.

Changelog

Version 1.0.3

Added Storybook stories and expanded unit tests; fixed duplicate tender-type filtering in useWalletMerchantService. See git history for details.

Version 1.0.2

Unified success payloads for ACH and card ({ type, paymentMethodId, use }), --avwc-* CSS variables with backward-compatible fallbacks, and named plugin export.

Documentation (current)

README aligned with AuthviaPaymentMethodForm.stories.ts (including paymentMethodDisplay.gap), demo.html, and package exports (@authvia/payment-method-create).

License

MIT License — see the LICENSE file.

Support

For support and questions, contact the Authvia UI Team.

版本与发布记录

@authvia/payment-method-create 共发布 51 个版本,首次发布于 2026/03/23;过去 12 个月发布了 51 个版本。

版本发布日期距今
2.2.2latest2026/11/062 天前
2.2.12026/11/044 天前
2.2.02026/10/299 天前
2.1.52026/10/2316 天前
2.1.42026/10/2216 天前
2.1.32026/10/2217 天前

关于 @authvia/payment-method-create 的常见问题

@authvia/payment-method-create 是什么?

Authvia Payment Method Form Web Component - Payment method form built with Vue 3 and Vuetify 3

如何安装 @authvia/payment-method-create?

在项目目录运行 npm install @authvia/payment-method-create,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(^3.4.0)、vuetify(^3.5.0)、@mdi/font(^7.4.47)、@sentry/vue(>=8.42.0 <11)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@authvia/payment-method-create 支持 TypeScript 吗?

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

@authvia/payment-method-create 支持 ESM 还是 CommonJS?

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

@authvia/payment-method-create 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@authvia/payment-method-create 可以商用吗?

@authvia/payment-method-create 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@authvia/payment-method-create 的下载量有多少?

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

@authvia/payment-method-create 还在维护吗?

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