javascript - cannot POST /payment (Node.js and Stripe) -



javascript - cannot POST /payment (Node.js and Stripe) -

i've embedded stripes checkout in file called payment.ejs

<form action="" method="post"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_odw7ojfvhlrjegfy0ppwzwee" data-amount="2000" data-name="demo site" data-description="2 widgets ($20.00)" data-image="/128x128.png"> </script> </form>

i visit page , come in in credit card gets accepted. however, error

cannot post /payment

in app.js have

app.post('payment', function(req, res){ //stripe console.log('posted') var stripetoken = req.body.stripetoken; var charge = stripe.charges.create({ amount: 1000, // amount in cents, 1 time again currency: "usd", card: stripetoken, description: "payinguser@example.com" }, function(err, charge) { if (err && err.type === 'stripecarderror') { console.log("card declined"); res.send('error') } else { console.log("card accepted"); res.send('ok') } }); });

as per instructions. don't see whats wrong here. ideas?

routes should include preceding /:

app.post('/payment', function (req, res) { // ^ // ... });

expressjs' routing based in part on matching path of requested url, includes each / "root" (after hostname , port). other part method.

app.use(function (req, res, next) { console.log(req.method); // "post" console.log(req.path); // "/payment" // ^ next(); });

note: whether trailing / or lack of required match depends on whether strict routing or router's strict option enabled.

enable strict routing, default "/foo" , "/foo/" treated same router.

javascript node.js stripe-payments

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -