我正在尝试使用Angular Payments模块处理Angular中的Stripe电荷。我可以从Stripe获取令牌,但当我尝试将令牌提交到我的Express服务器时,在客户端收到以下错误:
ReferenceError:未定义标记
有关如何解决此问题的任何想法?
以下是相关代码:
控制器:
myApp.controller('PaymentFormCtrl',
function($scope){
$scope.handleStripe = function(status, response){
console.log('response', status, response);
if(response.error) {
console.log('error');// there was an error. Fix it.
} else {
console.log('no error');
token = response.id;
return $http.post('http://localhost:8080/api/payments', payment);
}
};
});
表单的HTML:
<form stripe-form="handleStripe" name="myForm">
<div class="span3">
<label for="">Card number</label>
<input type="text" class="input-block-level" ng-model="number" payments-validate="card" payments-format="card" payments-type-model="type" ng-class="myForm.number.$card.type"/>
</div>
<div class="span1">
<label for="">Expiry</label>
<input type="text" class="input-block-level" ng-model="expiry" payments-validate="expiry" payments-format="expiry" />
</div>
<div class="span3">
<label for="">Name on card </label>
<input type="text" class="input-block-level">
</div>
<div class="span1">
<label for="">CVC</label>
<input type="text" class="input-block-level" ng-model="cvc" payments-validate="cvc" payments-format="cvc" payments-type-model="type"/>
</div>
<div class="span4">
<button type="submit" class="btn btn-primary btn-large">Submit</button>
</div>
</form>
服务器Javascript:
apiRouter.route('/payments')
.post(function(req, res) {
var stripeToken = request.body.stripeToken;
var charge = stripe.charges.create({
amount: 1000,
currency: "usd",
source: stripeToken,
description: "payinguser@example.com"
}, function (err, charge) {
if (err && err.type === 'StripeCardError') {
}
});
});
答案 0 :(得分:0)
要确定的一件事是,在服务器端,您的请求是“req'
但您正在尝试从
request.body.stripeToken
,
应该是
req.body.stripeToken