You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React集成Google Pay报错求助(OR-CCSEH-21)

React集成Google Pay按钮报错排查与修复

我使用@google-pay/button-react在React项目中集成Google Pay时,支付流程出现报错,弹窗提示“无法处理您的请求,请稍后重试”。尝试移除Stripe作为支付网关后问题仍未解决,当前使用的代码如下:

import React from "react";
import GooglePayButton from "@google-pay/button-react";
const Gpay = () => {
  console.log("here");
  return (
    <GooglePayButton
      environment="TEST"
      paymentRequest={{
        apiVersion: 2,
        apiVersionMinor: 0,
        allowedPaymentMethods: [
          {
            type: "CARD",
            parameters: {
              allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"],
              allowedCardNetworks: ["MASTERCARD", "VISA"],
            },
            tokenizationSpecification: {
              type: "PAYMENT_GATEWAY",
              parameters: {
                gateway: "stripe",
                "stripe:version": "v3",
                "stripe:publishableKey":
               "<pub_key_added>",
              },
            },
          },
        ],
        merchantInfo: {
          merchantId: "12345678901234567890",
          merchantName: "Demo Merchant",
        },
        transactionInfo: {
          totalPriceStatus: "FINAL",
          totalPriceLabel: "Total",
          totalPrice: "100.00",
          currencyCode: "USD",
          countryCode: "US",
        },
      }}
      onLoadPaymentData={(paymentRequest) => {
        console.log("load payment data", paymentRequest);
      }}
    />
  );
};

export default Gpay;

排查与修复步骤:

  • 调整测试环境商户ID配置
    在TEST环境下,若未完成Google Pay商户注册,无需填写真实merchantId,可直接移除该字段,仅保留merchantName即可。部分地区测试环境对未验证的商户ID会触发请求失败。

  • 适配移除Stripe后的令牌化配置
    移除Stripe网关后,需替换tokenizationSpecification为测试可用的配置。仅用于前端流程测试的话,可使用如下示例:

    tokenizationSpecification: {
      type: 'PAYMENT_GATEWAY',
      parameters: {
        gateway: 'example',
        gatewayMerchantId: 'test_merchant_id'
      }
    }
    

    若要对接真实支付网关,需替换为对应网关的官方配置参数。

  • 验证核心参数合规性
    确认transactionInfo中的totalPrice为合法数字字符串,currencyCode与countryCode匹配(如USD对应US)。同时确保apiVersion和apiVersionMinor符合Google Pay当前规范(当前2/0版本是兼容的)。

  • 检查页面运行环境
    Google Pay要求页面必须在HTTPS环境运行(localhost开发环境除外),部署后的测试页面需确保使用HTTPS协议,否则会因权限问题触发请求失败。

内容的提问来源于stack exchange,提问作者Ishaan Parmar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 19:53:09