@google-pay/save-button-react

中文文档
1.0.0发布于 2021/03/24Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 6390

React component for Google Pay button

原始使用文档
文档目录6 节
  1. Installation
  2. Example usage
  3. Documentation
  4. Properties
  5. Callbacks
  6. About this package

Save to Google Pay React button

This is the React component for the Save to Google Pay button.

Installation

npm install @google-pay/save-button-react

Example usage

<SaveToGooglePay jwt="eyJhbGci...7_eD2kT3_IuHxw" height="standard" textsize="large" />

A React example can be found in the examples folder of this repository.

Documentation

Properties

Property Type Remarks

jwt

string

Required.

Google Pay API for Passes Json Web Token (JWT) used to save the loyalty pass to Google Pay.

A JWT can be generated by following the instructions at the Save passes to Google Pay page.

height

"small" | "standard"

Optional.

Height of button to display. Possible values are: small (30px high) and standard (38px high). The height defaults to small. Refer to Google Pay API for Passes buttons to see samples of buttons with different height settings.

Default value "small".

size

"matchparent" | undefined

Optional.

Width of button to display. You can set size to matchparent to have the width match the width of the parent element. Refer to Google Pay API for Passes buttons to see samples of buttons with different size settings.

Default value undefined.

textsize

"large" | undefined

Optional.

When textsize of large is specified, displays dramatically increased text size and button size, for cases with special UI requirements.

Default value undefined.

theme

"dark" | "light"

Optional.

Theme of button to display. Possible values are: dark and light. The default theme is dark. Refer to Google Pay API for Passes buttons to see samples of buttons with different theme settings.

Default value "dark".

Callbacks

Callback Remarks

onSuccess

A callback function that is invoked when the user successfully saves the pass to their account.

onFailure

A callback that is invoked when an error occurs in the process of saving the pass. The first paramemer is a CustomEvent where the detail property describes the details of the error.

onProvideJwt

A callback function that can be used to intercept and potentially manipulate the JWT before the pass is saved to Google Pay. This function must return a string.

Visit the Google Pay API for Passes for Web API Reference for more information about integrating the different button properties.

About this package

Note that this folder does not contain a package.json file. The package.json file is generated during the build process using the package-template.json where the version number is read from the package.json file defined in the root of this repository.

版本与发布记录

@google-pay/save-button-react 共发布 2 个版本,首次发布于 2021/03/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2021/03/245 年前
0.1.12021/03/235 年前

关于 @google-pay/save-button-react 的常见问题

@google-pay/save-button-react 是什么?

React component for Google Pay button

如何安装 @google-pay/save-button-react?

在项目目录运行 npm install @google-pay/save-button-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@types/react(>=16.0.0)、@types/react-dom(>=16.0.0)、react(>=16.3.0)、react-dom(>=16.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@google-pay/save-button-react 支持 TypeScript 吗?

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

@google-pay/save-button-react 支持 ESM 还是 CommonJS?

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

@google-pay/save-button-react 需要什么版本的 Node.js?

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

@google-pay/save-button-react 可以商用吗?

@google-pay/save-button-react 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@google-pay/save-button-react 的下载量有多少?

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

@google-pay/save-button-react 还在维护吗?

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