条带错误:尝试注册订阅

时间:2016-01-12 21:30:47

标签: javascript angularjs node.js 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
        });

在我的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);
    }

  });
}

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

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 }

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

1 个答案:

答案 0 :(得分:78)

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

简单地通过{{1}}解决了我的问题。