首页 > 解决方案 > 在 Stripe api 中使用 Google Pay 响应令牌

问题描述

我已经按照 Google Pay 文档在我的页面上设置了 Google Pay 按钮,但是我陷入了最后一步,我需要按照 Google Pay 文档的描述将令牌响应从 Google Pay 发送到 Stripe。

为了执行支付,后端处理购买并将支付令牌发送给支付服务提供商。

我已经搜索了 Stripe 文档,但似乎找不到如何使用该令牌,但他们向我展示了如何使用 Stripe Payment Request Button来集成 Google Pay。那么,Stripe 是否支持来自 Google Pay api 的令牌,或者我是否需要使用 Stripe Payment Request Button来与 Google Pay 集成?

标签: stripe-paymentsgoogle-pay

解决方案


你可以做任何一个,你不/不应该混合这两种方法

基于Stripe doc here您可以使用

  1. Stripe 的 PaymentRequestButton
  2. 或者,您可以使用 Stripe 作为网关直接与 Google Pay 集成。在此处查看如何操作;在教程的第 2 步中,搜索stripe以找到网关配置
const tokenizationSpecification = {
  type: 'PAYMENT_GATEWAY',
  parameters: {
    "gateway": "stripe"
    "stripe:version": "2018-10-31" // your stripe API version
    "stripe:publishableKey": "pk_test_xxxx" // your stripe publishable key
  }
};

对于选项 2,您基本上会得到一个像这样tok_xxxx代表 GooglePay 钱包的 Stripe 令牌paymentData.paymentMethodData.tokenizationData.token,您可以使用 Stripe 的密钥直接将令牌与 Stripe API 一起使用,例如在此之后sk_test_xxxx创建费用

const stripe = require('stripe')('sk_test_xxxxx');

const charge = await stripe.charges.create({
  amount: 2000,
  currency: 'usd',
  source: 'tok_obtained_from_google_pay_api', 
  description: 'My First Test Charge (created for API docs)',
});

FYI token/chargeAPI 不再推荐,你可以payment_methodtoken这样的创建一个

const paymentMethod = await stripe.paymentMethods.create({
  type: 'card',
  card: {
    token: 'tok_xxxxx',
  },
});

并将其与 Stripe PaymentIntent API一起使用


推荐阅读