- This is the html:
<body ng-controller="stripeController">
<form action="/stripe" method="POST" id="payment-form">
<span class="payment-errors"></span>
<div class="from-row">
<lebel>
<span>Price:{{getTotal}}$</span>
<input type="hidden" data-stripe="number">
</lebel>
</div>
<div class="form-row">
<label>
<span>Card Number</span>
<input type="number" size="20" data-stripe="number">
</label>
</div>
<div class="form-row">
<label>
<span>Expiration (MM/YY)</span>
<input type="text" size="2" data-stripe="exp_month">
</label>
<span>/</span>
<input type="text" size="2" data-stripe="exp_year">
</div>
<div class="form-row">
<label>
<span>CVC</span>
<input type="text" size="4" data-stripe="cvc">
</label>
</div>
<input type="submit" class="submit" value="Submit Payment">
</form>
</body>
Это код контроллера:Как можно переместить значение от угловой формы на сервер nodejs
app.controller('stripeController', function($scope, $http) { $http.get('/api/me').success(function (response) { $scope.userInfo = response; $scope.isCartEmpty = true; $scope.userCart = []; if($scope.userInfo.cart.length>0){ $scope.isCartEmpty= false; } console.log($scope.isCartEmpty); for(var i=0;i<$scope.userInfo.cart.length;i++){ $scope.userCart[i] = $scope.userInfo.cart[i].productId } var y = 0; $scope.getTotal =0; for(i=0;i<$scope.userCart.length;i++) { $http.get('/api/product/' + $scope.userCart[i]).success(function (response) { $scope.userInfo.cart[y].name = response.name; $scope.userInfo.cart[y].price = response.price; $scope.getTotal+= response.price; y++; }); } });
});
Это node.js сообщение функция:
router.post('/stripe', function(req, res){ //Need to check if the cart empty than re-direct to catalog. var stripe = require("stripe")( "sk_test_mypass" ); stripe.charges.create({ amount: ????? * 100, currency: "usd", source: req.body.stripeToken, // obtained with Stripe.js description: "Test Charge" }, function(err, charge) { if(err){ console.log("Error"); } console.log("Successfully bought product!"); }); });
-Есть 1 вопросы: В функции Node.js, где я поставил "?????" как я могу получить данные из формы html. Когда я типа req.body.getTotal я не получаю данные ...