条纹付款快递js:缺少交易详情

时间:2018-02-27 12:02:44

标签: javascript node.js express stripe-payments

我正在关注设置付款的官方条带文档

https://stripe.com/docs/checkout/express,一切正常,但缺少一些东西

1)交易细节,即身份,付款状态等

document.addEventListener("readystatechange", function(event) {
    if (document.readyState === "complete") {
        console.log("complete");
    }
});

stripe.customers.create(body) .then(customer => { console.log("customer",customer); stripe.charges.create({ amount, description: "Sample Charge", currency: "usd", customer: customer.id } ) } ) .then(charge =>{ console.log("charge",charge); res.render("charge.pug") }).catch(error=>{ console.log("Error",error); }); }); 提供console.log("charge",charge);

2)我需要保护undefined api吗?

POST

2 个答案:

答案 0 :(得分:0)

您需要return

app.post("/charge", (req, res) => {
  let amount = 500;

  let body = {
    email: req.body.stripeEmail,
    source: req.body.stripeToken
 };

  stripe.customers.create(body)
    .then(customer => {
      console.log("customer",customer);  
      return stripe.charges.create({ // <-- return the Promise
        amount,
        description: "Sample Charge",
        currency: "usd",
        customer: customer.id
      })
    })
  .then(charge =>{ 
    console.log("charge",charge);
    res.render("charge.pug")
  })
  .catch(error => console.log("Error",error));
});

不,你不需要保护路线。您没有看到在线商家保护他们的路线,但是,他们通常会选择“Checkout as Guest”选项。

答案 1 :(得分:0)

  

缺少交易明细

您正在解决stripe.customers.create(body)两次承诺而不是stripe.charges.create的承诺所以要解决您的第一个问题解决承诺(.then())到stripe.charges.create,如下所示

stripe.customers.create(body)
    .then(customer => {
        console.log("customer", customer);
        stripe.charges.create({
            amount,
            description: "Sample Charge",
            currency: "usd",
            customer: customer.id
        }
        ).then(charge => {
            console.log("charge", charge); //Here you will get transaction info now
            res.render("charge.pug")
        }).catch(error => {
            console.log("Error", error);
        })
    }).catch(error => {
        console.log("Error", error);
    });
  })`
  

我需要保护POST api吗?

是。您应该保护您的每个公共API。您可以使用JWT或任何其他oAUTH来保护您的路线。