条带用户令牌问题

Stripe user token issue

本文关键字:问题 令牌 用户      更新时间:2023-09-26

我遵循本指南(https://mikesabat.wordpress.com/2013/12/15/making-users-pay-building-a-site-with-strip-and-devise/),除了将 Stripe 库更改为 v2 而不是 v1 之外,没有进行任何修改。

基本上,我的问题是stripe_card_token字段保存一个以 tok_BLAHBLAHBLAH 开头的值,而在 Stripe 控制面板中,每个客户都有一个像 cus_BLAHBLAHBLAH 这样的令牌。

我的 JavaScript 返回条纹标记并填充到隐藏字段中是:

handleStripeResponse: (status, response) ->
if status == 200
  console.log(response);
  $('#user_stripe_card_token').val(response.id)
  $('#new_user')[0].submit()
else
  $('#stripe_error').text(response.error.message)
  $('#stripe_error').show()
  $('input[type=submit]').attr('disabled', false)

这些令牌实际上是两个不同的东西 - tok_XXX值是一次性卡令牌,cus_XXX值是客户 ID。

在您的用户将他们的信用卡信息输入您的表单中,并且 Stripe 通过 javascript 返回卡令牌后,您将该令牌提交到您的服务器端代码。

一旦您的服务器端代码收到卡令牌,您将从您的服务器(而不是来自 Javascript)向 Stripe 提交 Stripe API "创建客户"调用。此 API 调用将卡令牌作为输入,并返回永久客户 ID 作为响应(以及其他内容)。

客户 ID 是您将保存在数据库中的值,当您需要从客户的信用卡中扣款时,您会将其发送给 Stripe。

有关详细信息,请参阅创建客户 API 调用。