2
我試圖建立條紋付款,但遇到了一個錯誤: 類型錯誤:無法在/Users/andreykondratyuk/websites/talllly/src/server/app.js:56讀的不確定
財產' ID ': 37
在Layer.handle [按handle_request] ...如何將stripe token從angularjs傳遞給nodejs或修復錯誤nodejs post?
形式:
<form stripe-form="stripeCallback" name="checkoutForm">
<input ng-model="number" placeholder="Card Number" payments-format="card" payments-validate="card" name="card" />
<input ng-model="expiry" placeholder="Expiration" payments-format="expiry" payments-validate="expiry" name="expiry" />
<input ng-model="cvc" placeholder="CVC" payments-format="cvc" payments-validate="cvc" name="cvc" />
<button type="submit">Submit</button>
<div ng-if="checkoutForm.card.$invalid"> Error: invalid card number! </div>
</form>
在控制器
// Stripe Response Handler
$scope.stripeCallback = function (code, result) {
console.log(result);
if (result.error) {
window.alert('it failed! error: ' + result.error.message);
} else {
// Simple POST request example (passing data) :
$http.post('/charge', result)
.success(function(data, status, headers, config) {
alert(data);
})
.error(function(data, status, headers, config) {
alert(data);
});
}
};
在後端app.js
app.post('/charge', function(req, res) {
console.log(req);
var stripeToken = req.body.token.id;
var charge = stripe.charges.create({
amount: 10000, // amount in cents, again
currency: "usd",
card: stripeToken,
description: "[email protected]"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
console.log(JSON.stringify(err, null, 2));
}
res.send("completed payment!");
});
});
我在做什麼錯?