Я намагаюся обробити смужку смуги в кутовій за допомогою Кутові платежі модуль. Я можу отримати маркер від 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 для відповіді № 1Напевно виправте те, що на стороні сервера ваш запит "req"
але ви намагаєтесь отримати маркер з
request.body.stripeToken
,
має бути
req.body.stripeToken