条带错误:尝试注册订阅时"不支持令牌"

JVG*_*JVG 38 javascript node.js angularjs stripe-payments

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

我的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
        });
Run Code Online (Sandbox Code Playgroud)

在我的Node路线中,我这样做:

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);
    }

  });
}
Run Code Online (Sandbox Code Playgroud)

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

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 }
Run Code Online (Sandbox Code Playgroud)

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

JVG*_*JVG 86

在Stripe的IRC频道上找到答案:官方文档中没有提到,但Stripe期待令牌ID,而不是完整的令牌本身.

简单的传球source: stripeToken.id解决了我的问题.

  • 谢谢!不仅没有提到,它在样本中是不正确的. (6认同)
  • 4个小时过去了.为什么不在文档中?谢谢亲爱的先生. (4认同)