【问题标题】:Stripe - Creating Charge条纹 - 创造电荷
【发布时间】:2019-04-03 09:12:09
【问题描述】:

致力于整合 stipe。一切似乎都在前端工作,但在服务器端代码上,令牌是空的,它没有成功地向 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.js express stripe-payments payment-gateway payment


【解决方案1】:

在来自other question 的前端代码中,您将 POST 正文作为

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

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

const token = req.body.token;

改为。

【讨论】:

    【解决方案2】:

    创建费用之前,您应该创建客户。充电后工作。

    示例代码。 (ES6)

    let customer = await payStripe.customers.create({
                email: req.body.stripeEmail,
                source: req.body.stripeToken
    });
    
    //After Created Customer...
    
    if(customer){
    
     let charge = await payStripe.charges.create({
    
                amount: req.body.amount,
    
                description: req.body.description,
    
                currency: 'usd',
    
                customer: customer.id
            });
    
    
    }
    

    希望一切顺利。

    【讨论】:

    • 我认为不创建客户也可以收费
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多