@chargebee/chargebee-js-angular-wrapper

中文文档
5.0.3发布于 2025/10/27MITTypeScriptES Module近 30 天下载 7264

充电器的角包装器。 js 组件

中文使用文档
文档目录10 节
  1. 实例
  2. 现场直播
  3. 安装
  4. 使用量
  5. 基本用途
  6. 一个更为复杂的例子是:
  7. 3DS 授权
  8. 指令和APIs
  9. 参考:
  10. 支助

充电蜂 JS 角包装器

充电器组件的角包装器

实例

详细例子: 点击这里

现场直播

查看实况演示 这里

安装

从 npm 安装 :

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

使用量

充电蜂组件需要您以 site 财务报告和审定财务报表 publishableKey

想知道在哪里获得您的 API 密钥吗 ? 参考这里

在你身边 index.html数字 :

<html>
  <head>
    ...
    <script src="https://js.chargebee.com/v2/chargebee.js"></script>
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

基本用途

在您的角构件中

构成部分.html

<div class="cell example example3" id="example-3" style="padding: 1em">
  <form>
    <div cbCardField id="card-field" (ready)="onReady($event)"></div>
    <button (click)="onTokenize($event)">Submit</button>
  </form>
</div>

组件.ts

import { Component } from '@angular/core';

declare var Chargebee;
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  standalone: true,
   imports: [
    RouterOutlet,
    CardFieldDirective,
    CvvFieldDirective,
    NumberFieldDirective,
    ExpiryFieldDirective,
  ],
})
export class AppComponent {
  cardComponent = null;

  constructor(...) {
    ...
    Chargebee.init({
      site: 'your-site'
      publishableKey: 'your-publishable-key'
    })
  }

  onReady = (cardComponent) => {
    this.cardComponent = cardComponent;
  }

  onTokenize = (event) => {
    event.preventDefault();

    this.cardComponent.tokenize().then(data => {
      console.log('chargebee token', data.token)
    });
  }
}

一个更为复杂的例子是:

构成部分.html

<div class="cell example example3" id="example-3" style="padding: 1em">
  <form>
    <div cbCardField id="card-field" [fonts]="fonts" [styles]="styles" locale="en" [showTestCards]="true" [classes]="classes" (ready)="onReady($event)">
      <div id="card-number" cbNumberField class="field empty" placeholder="4111 1111 1111 1111" (ready)="setFocus($event)" (change)="onChange($event)"></div>
      <div id="card-expiry" cbExpiryField class="field empty" placeholder="MM / YY" (change)="onChange($event)"></div>
      <div id="card-cvv" cbCvvField class="field empty" placeholder="CVV" (change)="onChange($event)"></div>
    </div>
    <div id="errors">{{errorMessage}}</div>
    <button id="submit-button" (click)="onSubmit($event)">Pay 25$</button>
  </form>
</div>

组件.ts

import { Component, ChangeDetectorRef, HostListener } from "@angular/core";
declare var Chargebee;

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
  standalone: true,
   imports: [
    RouterOutlet,
    CardFieldDirective,
    CvvFieldDirective,
    NumberFieldDirective,
    ExpiryFieldDirective,
  ],
})
export class AppComponent {
  errorMessage = "";
  changeDetectorRef: ChangeDetectorRef;
  cardComponent = null;

  constructor(changeDetectorRef: ChangeDetectorRef) {
    this.changeDetectorRef = changeDetectorRef;
  }

  errors = {};
  classes = {
    focus: "focus",
    complete: "complete-custom-class",
    invalid: "invalid",
    empty: "empty",
  };
  fonts = ["https://fonts.googleapis.com/css?family=Open+Sans"];
  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",
      },
    },
  };

  onReady = (cardComponent) => {
    this.cardComponent = cardComponent;
  };

  setFocus(field) {
    field.focus();
  }

  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;
    this.changeDetectorRef.detectChanges();
  };

  onSubmit = (event) => {
    event.preventDefault();
    this.cardComponent.tokenize().then((data) => {
      console.log("chargebee token", data.token);
    });
  };
}

3DS 授权

在您的角构件中

构成部分.html

<div class="cell example example3" id="example-3" style="padding: 1em">
  <form>
    <div cbCardField id="card-field" (ready)="onReady($event)"></div>
    <button (click)="authorize($event)">Submit</button>
  </form>
</div>

组件.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
   standalone: true,
   imports: [
    RouterOutlet,
    CardFieldDirective,
    CvvFieldDirective,
    NumberFieldDirective,
    ExpiryFieldDirective,
  ],
})
export class AppComponent {
  cardComponent = null;
  intent = null;
  additionalData = {
    // Additional data to improve the chances of frictionless flow
  }

  onReady = (cardComponent) => {
    this.cardComponent = cardComponent;
  }

  createPaymentIntent() {
    // make ajax call to your server to create a paymentIntent
    ...
    this.intent = paymentIntent
  }

  authorize = (event) => {
    event.preventDefault();

    this.cardComponent.authorizeWith3ds(this.intent, this.additionalData).then(authorizedIntent => {
      console.log('3DS Authorization success', authorizedIntent.id)
    });
  }
}

指令和APIs

cbCard 外地指令(文档(中文(简体) )

属性说明数据类型
fonts字体面或链接的阵列字体
classes用于替换各种 CSS 类名的集 事件类
locale语言代码语言
showTestCards添加在测试站点显示测试卡的能力布尔
styles样式定制集样式
placeholder卡片字段的一组占位符占位符
活动文档(中文(简体) )
道具说明参数
(ready)组件挂起并准备好时触发器外地
(change)每个州变化的触发器战地状态
(focus)当组件被聚焦时触发战地状态
(blur)组件模糊时触发战地状态

个别外地指示文档(中文(简体) )

  • cb 外地人数
  • cb 爆炸场
  • cbCvv 战地
道具说明数据类型
styles二元字段样式样式
placeholder字段的占位符字符串
活动支持( E)文档(中文(简体) )
道具说明参数
(ready)组件挂起并准备好时触发器外地
(change)每个州变化的触发器战地状态
(focus)当组件被聚焦时触发战地状态
(blur)组件模糊时触发战地状态

参考:

充气管组件-联署文件

支助

是否有人询问执行情况? 联系 支持@ forcebee.com

版本与发布记录

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

版本发布日期距今
5.0.3latest2025/10/271 年前
5.0.3-beta.22025/10/271 年前
5.0.3-beta.12025/10/271 年前
5.0.22025/10/241 年前
5.0.12025/10/141.1 年前
5.0.02025/01/061.8 年前

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

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

充电器的角包装器。 js 组件

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

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

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

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

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

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

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

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

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

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

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

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