Stripe Error: 'Token is Not Supported' when trying to sign up to subscription

Stripe Error: 'Token is Not Supported' when trying to sign up to subscription

无法在任何地方找到有关此特定错误的任何信息,请耐心等待。

我的 Angular/NodeJS 应用有一个通过 Stripe 处理的付款页面(用于每月和每年的订阅)。

我已经在我的 Stripe 仪表板中创建了订阅类型(两个订阅:StarterAnnualStarterMonthly),并且我已经像这样设置了处理程序:

  var handler = StripeCheckout.configure({
          key: 'pk_test_qs8Ot1USopAZAyLN3gNXma0T',
          image: '/img/stripe-logo.png',
          locale: 'auto',
          email: $scope.user.email,
          token: function(token) {
            console.log(token)
            var tempObj = {
                stripeToken : token,
                email : $scope.user.email,
                cost : $scope.plan.price * 100
                plan : $scope.plan.name
            }
            $http.post('/api/makePayment', tempObj).then(function(data){
                console.log('stripe data', data);
            },function(err){
                console.log('stripe error', err);
            })
          }
        });

        handler.open({
          name: '<bizname>',
          description: $scope.plan.name,
          amount: $scope.plan.price * 100
        });

在我的节点路线中,我这样做:

exports.makePayment = function(req,res){

  var stripeToken = req.body.stripeToken,
            email = req.body.email,
             cost = req.body.cost,
             plan = req.body.plan;

  var tempObj = {
    source: stripeToken,
    plan: plan,
    email: email
  }

  console.log(tempObj); // Everything looks fine in this log

  stripe.customers.create(tempObj, function(err, customer) {
    if(err){
      console.log("Stripe Error");
      console.log(err);
    }else{
      console.log(customer);
      res.status(200).send(customer);
    }

  });
}

当我尝试付款时,我得到:

Stripe Error
{ [Error: token is not supported.]
  type: 'StripeInvalidRequestError',
  stack: 'Error: token is not supported.\n    at Error._Error (/node_modules/stripe/lib/Error.js:12:17)\n    at Error.Constructor (/node_modules/stripe/lib/utils.js:105:13)\n    at Error.Constructor (/node_modules/stripe/lib/utils.js:105:13)\n    at Function.StripeError.generate (/node_modules/stripe/lib/Error.js:56:14)\n    at IncomingMessage.<anonymous> (/node_modules/stripe/lib/StripeResource.js:138:39)\n    at emitNone (events.js:72:20)\n    at IncomingMessage.emit (events.js:166:7)\n    at endReadableNT (_stream_readable.js:905:12)\n    at doNTCallback2 (node.js:452:9)\n    at process._tickCallback (node.js:366:17)',
  rawType: 'invalid_request_error',
  code: undefined,
  param: 'source',
  message: 'token is not supported.',
  detail: undefined,
  raw: 
   { type: 'invalid_request_error',
     message: 'token is not supported.',
     param: 'source',
     statusCode: 400,
     requestId: 'req_7hzY3mEgeM3nNJ' },
  requestId: 'req_7hzY3mEgeM3nNJ',
  statusCode: 400 }

我几乎只是直接使用文档中的代码,我在这里做错了什么?在进行订阅时,我是否需要进行不同的设置才能创建客户?

在 Stripe 的 IRC 频道上找到了答案:official docs 中没有提到,但 Stripe 需要 令牌 ID,而不是完整的令牌本身。

简单地通过 source: stripeToken.id 就解决了我的问题。