@cybersource/flex-sdk-web

中文文档
0.3.1发布于 2020/04/09SEE LICENSE IN LICENSE.mdCommonJS零依赖近 30 天下载 3549

Easily create payment tokens using Flex API

原始使用文档
文档目录10 节
  1. Table of contents
  2. Installation
  3. How to use
  4. Include in your app
  5. Include via a script tag
  6. Docs
  7. Example Integration
  8. Steps:
  9. Browser support
  10. Copyright and license

flex-sdk-web

npm version

Storing your customer’s card data dramatically increases your repeat-custom conversion rate, but it can also introduce additional risks along with a PCI DSS overhead - these are mitigated by tokenizing the card data. CyberSource replaces your customer’s card data with a token that can be used only by you.

Secure Acceptance Flexible Token API provides a secure method for tokenizing card data and reducing your PCI DSS burden. Card data is encrypted on the customer’s device and sent directly to CyberSource, bypassing your systems altogether.

This SDK simplifies the client-side integration and enables:

  • Full control of the user experience
  • Wide range of browser support
  • SAQ A-EP eligibility

Table of contents

Installation

Install the package with:

yarn add @cybersource/flex-sdk-web
# or
npm install @cybersource/flex-sdk-web --save

The SDK is exposed as a UMD providing compatibility with most module loader specs or direct use in the browser via a script tag.

How to use

Include in your app

import flex from '@cybersource/flex-sdk-web';

const options = {};

flex.createToken(options, response => {
  // use response
});

OR

Include via a script tag

<html>
  <body>
    <script src="./YOUR_ASSETS_PATH/flex-sdk-web.js"></script>
    <script>
      var options = {};

      FLEX.createToken(options, function(response) {
        // use response
      });
    </script>
  </body>
</html>

Docs

Full documentation is located in the /docs folder at the root of the installation directory.

Example Integration

The SDK is non-prescriptive on your payment flow design, making few assumptions about your development stack. It is easily integrated into any front-end setup. Described below is a minimal example for a web app using full page refreshes and form POSTs.

Steps:

  • For each transaction a new Flex public key should be fetched prior to rendering the checkout page.
  • Flex public key is rendered to a JS variable in JWK format.
  • On the button click event all payment data is gathered and a token creation call is made using the SDK.
  • When the token is created, the value is set on a hidden field and the form is submitted.
  • You can use token with follow-on CyberSource services to complete payment (e.g. in the subscription ID field used in the Simple Order API).
<!-- checkout template -->
<html>
  <body>
    <form id="paymentForm" action="/your/server/endpoint" method="post">
      <input type="text" id="cardNumber" />
      <input type="text" name="securityCode" />
      <input type="text" name="cardExpirationMonth" />
      <input type="text" name="cardExpirationYear" />
      <select name="cardType">
        <option value="001">VISA</option>
        <option value="002">MasterCard</option>
        <option value="003">AmericanExpress</option>
      </select>
      <input type="hidden" name="token" />
      <button type="button" id="payBtn">Pay Now</button>
    </form>
    <script>
      var jwk = {
        /* flex public key in jwk format */
      };
    </script>
    <script src="integration.js"></script>
  </body>
</html>
// integration.js
import flex from '@cybersource/flex-sdk-web';

document.querySelector('#payBtn').addEventListener('click', () => {
  const options = {
    kid: jwk.kid,
    keystore: jwk,
    encryptionType: 'RsaOaep', // ensure this matches the encryptionType you specified when creating your key
    cardInfo: {
      cardNumber: document.querySelector('#cardNumber').value,
      cardType: document.querySelector('select[name="cardType"]').value,
      cardExpirationMonth: document.querySelector('input[name="cardExpirationMonth"]').value,
      cardExpirationYear: document.querySelector('input[name="cardExpirationYear"]').value
    }
  };

  flex.createToken(options, response => {
    if (response.error) {
      alert('There has been an error!');
      console.log(response);
      return;
    }

    document.querySelector("input[name='token']").value = response.token;
    document.querySelector('#paymentForm').submit();
  });
});

Note that the SDK can easily be integrated into a single page application, using AJAX for the key fetch and token submission.

Browser support

  • Chrome 37+
  • Internet Explorer 11
  • Safari 7.1+ *
  • iOS Safari 8+ *
  • Firefox 34+
  • Edge 12+

Note that Safari 10 and below does not support an encryptionType of RsaOaep256

Code and documentation copyright 2017 CyberSource. Released under the CyberSource SDK License Agreement as detailed in ./LICENSE.md.

版本与发布记录

@cybersource/flex-sdk-web 共发布 9 个版本,首次发布于 2017/06/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.1latest2020/04/096 年前
0.3.02020/04/076 年前
0.2.12017/10/249 年前
0.2.02017/10/249 年前
0.1.32017/10/179 年前
0.1.22017/06/309 年前

关于 @cybersource/flex-sdk-web 的常见问题

@cybersource/flex-sdk-web 是什么?

Easily create payment tokens using Flex API

如何安装 @cybersource/flex-sdk-web?

在项目目录运行 npm install @cybersource/flex-sdk-web,或使用 pnpm add / yarn add / bun add。

@cybersource/flex-sdk-web 支持 TypeScript 吗?

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

@cybersource/flex-sdk-web 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cybersource/flex-sdk-web 可以商用吗?

@cybersource/flex-sdk-web 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@cybersource/flex-sdk-web 的下载量有多少?

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

@cybersource/flex-sdk-web 还在维护吗?

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