首页 > 解决方案 > 条纹 - 创造电荷

问题描述

致力于整合菌柄。一切似乎都在前端工作,但在服务器端代码上,令牌是空的,它没有成功地向 Stripe 收费。似乎无法弄清楚我要去哪里错了。

   app.post('/apple-pay', function(req, res, next) {

    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here: https://dashboard.stripe.com/account/apikeys
    var stripe = require("stripe")("sk_test_XXX");

    // Token is created using Checkout or Elements!
    // Get the payment token ID submitted by the form:
    const token = req.body.stripeToken;
    console.log(token)
     const charge = stripe.charges.create({
      amount: 999,
      currency: 'usd',
      description: 'Example charge',
       source: token,

    }, function(err, charge) {
         if(err){
                req.flash("error", err.message);
                res.redirect("back");
            } else {

            }
    });
    });

标签: node.jsexpressstripe-paymentspayment-gatewaypayment

解决方案


另一个问题的前端代码中,您将 POST 正文传递为

JSON.stringify({token: ev.token.id})

这意味着 Stripe 令牌实际上在tokenPOST 参数中,而不是stripeToken. 所以你需要做

const token = req.body.token;

反而。


推荐阅读