@chargebee/chargebee-js-vue-wrapper

中文文档
0.3.3发布于 2025/10/09MITESM + CJS零依赖近 30 天下载 4.2万

Vue wrapper for Chargebee.js Components

原始使用文档
文档目录10 节
  1. Examples
  2. Live Demo
  3. Installation
  4. Usage
  5. Basic usage
  6. A more complex example:
  7. 3DS Authorization
  8. Components and APIs
  9. Reference:
  10. Support

Chargebee JS Vue Wrapper

Vue wrapper for Chargebee Components

Examples

For detailed examples: Click here

Live Demo

View live demo here

Installation

Install from npm:

npm install @chargebee/chargebee-js-vue-wrapper

Usage

Chargebee Components requires you to initialize chargebee js with site and publishableKey

Wondering where to obtain your publishable API key? Refer here

In your index.html:

<html>
    <head>
      ...
      <script src="https://js.chargebee.com/v2/chargebee.js"></script>
      <script>
        Chargebee.init({
          site: 'your-site'
          publishableKey: 'your-publishable-key'
        })
      </script>
    </head>
    <body>
      <div id="app"></div>
    </body>
</html>

Basic usage

In your vue component

<template>
  <div>
    <div class="cell example example3" id="example-3" style="padding: 1em">
      <form>
        ...
        <card-component ref="cardComponent" />
        <button type="submit" id="tokenize" v-on:click="onSubmit">Submit</button>
        ...
      </form>
    </div>
  </div>
</template>

<script>
import {CardComponent} from '@chargebee/chargebee-js-vue-wrapper';

export default {
  name: 'app',
  components: {
    'card-component': CardComponent,
  },

  methods: {
    onSubmit (e) {
      e.preventDefault()
      this.$refs.cardComponent.tokenize().then(data => {
        console.log('chargebee token', data.token)
      })
    }
  }
}

</script>

A more complex example:

Note: If vue version is 3.2 or less, please add the following line to your Vue application bootstrap app.config.unwrapInjectedRef = true Reference documentation

<template>
  <div>
    <div class="example-3" id="example-3" >
      <form>
          <card-component class="fieldset" ref="cardComponent" 
            :fonts="fonts" 
            :styles="styles" 
            :locale="locale" 
            :classes="classes" 
            @ready="onReady"
            @change="onChange"
          >
            <card-number class="field empty" @focus="onFocus"  :placeholder="'4111 1111 1111 1111'" />
            <card-expiry class="field empty" @focus="onFocus"  :placeholder="'MM / YY'" />
            <card-cvv class="field empty" @focus="onFocus" :placeholder="'CVV'" />
          </card-component>
          <button type="submit" v-on:click="onSubmit">Submit</button>
          <div id="errors">{{errorMessage}}</div>
      </form>
    </div>
  </div>
</template>

<script>
import {CardComponent, CardNumber, CardExpiry, CardCvv} from '@chargebee/chargebee-js-vue-wrapper';

export default {
  name: 'app',
  components: {
    'card-component': CardComponent,
    'card-number': CardNumber,
    'card-expiry': CardExpiry,
    'card-cvv': CardCvv,
  },

  data () {
    return {
      styles: {
        base: {
          color: '#fff',
          fontWeight: 600,
          fontFamily: 'Quicksand, Open Sans, Segoe UI, sans-serif',
          fontSize: '16px',
          fontSmoothing: 'antialiased',

          ':focus': {
            color: '#424770'
          },

          '::placeholder': {
            color: '#9BACC8'
          },

          ':focus::placeholder': {
            color: '#CFD7DF'
          }
        },
        invalid: {
          color: '#fff',
          ':focus': {
            color: '#FA755A'
          },
          '::placeholder': {
            color: '#FFCCA5'
          }
        }
      },
      locale: 'en',
      classes: {
        focus: 'focus',
        complete: 'complete',
        invalid: 'invalid',
        empty: 'empty'
      },
      fonts: [
        {
          src: 'https://mysite.com/assets/my-font.woff',
          fontStyle: 'italic',
          fontFamily: 'Myfont',
          fontWeight: '500'
        },
        'https://fonts.googleapis.com/css?family=Lato'
      ],
      errors: {},
      errorMessage: ''
    }
  },

  methods: {
    onSubmit (e) {
      e.preventDefault()
      this.$refs.cardComponent.tokenize().then(data => {
        console.log('chargebee token', data.token)
      })
    },
    onChange (status) {
      let errors = {
        ...this.errors,
        [status.field]: status.error
      }
      this.errors = errors
      let {message} = Object.values(errors).filter(message => !!message).pop() || {}
      this.errorMessage = message
    },
    onFocus (event) {
      console.log(event.field, 'focused')
    },
    onReady (el) {
      el.focus()
    }
  }
}
</script>

3DS Authorization

In your vue component

<template>
  <div>
    <div class="cell example example3" id="example-3" style="padding: 1em">
      <form>
        ...
        <card-component ref="cardComponent" />
        <button type="submit" id="authorize" v-on:click="onSubmit">Submit</button>
        ...
      </form>
    </div>
  </div>
</template>

<script>
import {CardComponent} from '@chargebee/chargebee-js-vue-wrapper';

export default {
  name: 'app',
  components: {
    'card-component': CardComponent,
  },

  mounted: function() {
    this.createPaymentIntent().then(intent => {
      this.paymentIntent = intent;
    });
  },

  data: function() {
    return {
      paymentIntent: null,
      additionalData: {
        // Additional params to improve chances of frictionless flow
      }
    }
  },

  methods: {
    createPaymentIntent() {
      // Make ajax call to server to create a paymentIntent
    },
    onSubmit (e) {
      e.preventDefault()
      this.$refs.cardComponent.authorizeWith3ds(this.paymentIntent, this.additionalData)
        .then(authorizedIntent => {
          console.log('Success', authorizedIntent.id)
        }).catch(error => {
          consoel.error('Error', error)
        })
    }
  }
}

</script>

Components and APIs

Card Component (docs)

PropsDescriptionDatatype
classCSS Class name for the container elementString
fontsAn array of font faces or linksFonts
classesSet of CSS classnames that get substituted for various eventsClasses
localeLanguage codeLocale
stylesSet of style customizationsStyles
placeholderSet of placeholders for the card fieldsPlaceholder
refVue reference(ref) for card componentVue ref
Events (docs)
PropsDescriptionArguments
@readyTriggers when component is mounted and readyField
@changeTriggers for every state changeField State
@focusTriggers when component is focusedField State
@blurTriggers when component is blurredField State

Field Components (docs)

  • CardNumber
  • CardExpiry
  • CardCVV
PropsDescriptionDatatype
classCSS Classname for container elementString
stylesStyles for inidividual fieldStyles
placeholderPlaceholder for the fieldString
Event Props (docs)
PropsDescriptionArguments
@readyTriggers when component is mounted and readyField
@changeTriggers for every state changeField State
@focusTriggers when component is focusedField State
@blurTriggers when component is blurredField State

Reference:

Chargebee Components - JS Docs

Support

Have any queries regarding the implementation? Reach out to [email protected]

版本与发布记录

@chargebee/chargebee-js-vue-wrapper 共发布 16 个版本,首次发布于 2019/04/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.3latest2025/10/091.1 年前
0.3.22023/08/093 年前
0.3.12023/01/113 年前
0.3.02022/07/084 年前
0.2.22021/03/235 年前
0.2.12020/09/166 年前

关于 @chargebee/chargebee-js-vue-wrapper 的常见问题

@chargebee/chargebee-js-vue-wrapper 是什么?

Vue wrapper for Chargebee.js Components

如何安装 @chargebee/chargebee-js-vue-wrapper?

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

@chargebee/chargebee-js-vue-wrapper 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/chargebee__chargebee-js-vue-wrapper 是否存在。

@chargebee/chargebee-js-vue-wrapper 支持 ESM 还是 CommonJS?

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

@chargebee/chargebee-js-vue-wrapper 可以商用吗?

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

@chargebee/chargebee-js-vue-wrapper 的下载量有多少?

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

@chargebee/chargebee-js-vue-wrapper 还在维护吗?

最新版本 0.3.3 发布于 2025/10/09(1.1 年前);至今共发布 16 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/04/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。