@google/react-native-make-payment

中文文档
0.3.1发布于 2026/07/13Apache-2.0TypeScriptESM + CJS近 30 天下载 14.2万

React Native library for making native payments

原始使用文档
文档目录4 节
  1. Installation
  2. Configuration
  3. Usage
  4. Google Pay Button

react-native-make-payment

npm version

Adds native payments using the W3C Payment Request API to your React Native app. Currently supports Google Pay on Android.

Installation

npm install @google/react-native-make-payment

You can also try out the example by running the following command from the root of this repo:

yarn && yarn example

Configuration

For production, you will need to define the GOOGLE_PAY_ENVIRONMENT property in your project's gradle.properties file (typically android/gradle.properties):

GOOGLE_PAY_ENVIRONMENT=PRODUCTION

Usage

Following is a minimal example. A complete example can be found in example/src/App.tsx.

import { PaymentRequest, type W3CGooglePayPaymentMethod, type GooglePayPaymentDataRequest } from '@google/react-native-make-payment';

const paymentDetails = {
  total: {
    amount: {
      currency: 'USD',
      value: '14.95',
    },
  },
};

const googlePayRequest: GooglePayPaymentDataRequest = {
  // Google Pay API JSON request object, see:
  // https://developers.google.com/pay/api/android/reference/request-objects
};

const paymentMethods: W3CGooglePayPaymentMethod[] = [
  {
    supportedMethods: 'google_pay',
    data: googlePayRequest,
  },
];

const paymentRequest = new PaymentRequest(paymentMethods, paymentDetails);

paymentRequest.canMakePayment().then((canMakePayment) => {
  if (canMakePayment) {
    paymentRequest.show().then((response) => {
      // Handle PSP response
    });
  } else {
    // Google Pay unavailable
  }
});

Google Pay Button

Example of adding a native Google Pay button:

<GooglePayButton
  style={styles.googlepaybutton}
  onPress={checkCanMakePayment}
  allowedPaymentMethods={googlePayRequest.allowedPaymentMethods}
  theme={GooglePayButtonConstants.Themes.Dark}
  type={GooglePayButtonConstants.Types.Buy}
  radius={4}        
/>

版本与发布记录

@google/react-native-make-payment 共发布 12 个版本,首次发布于 2023/03/09;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.3.1latest2026/07/134 个月前
0.3.02026/05/016 个月前
0.2.22025/09/101.2 年前
0.2.12025/09/101.2 年前
0.2.02025/09/101.2 年前
0.1.62025/09/081.2 年前

关于 @google/react-native-make-payment 的常见问题

@google/react-native-make-payment 是什么?

React Native library for making native payments

如何安装 @google/react-native-make-payment?

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

@google/react-native-make-payment 支持 TypeScript 吗?

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

@google/react-native-make-payment 支持 ESM 还是 CommonJS?

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

@google/react-native-make-payment 可以商用吗?

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

@google/react-native-make-payment 的下载量有多少?

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

@google/react-native-make-payment 还在维护吗?

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