简体   繁体   English

条纹付款快递js:缺少交易详细信息

[英]Stripe payment express js :transaction details is missing

I am following official stripe documentation for setting up the payment 我正在遵循官方的条纹文档来设置付款

https://stripe.com/docs/checkout/express ,everything works expected but couple of things is missing https://stripe.com/docs/checkout/express ,一切正常,但缺少一些内容

1)Transaction details ie id,payment status etc 1)交易明细,例如身份证,付款状态等

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); gives undefined 给出undefined

2) Do i need to protect the POST api ?? 2)我需要保护POST api吗?

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);  
      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);
      });
  });

You need to return : 您需要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));
});

And no you don't need to protect the route. 而且,您不需要保护路线。 You don't see online merchants protect their routes, however, typically they have some sort of "Checkout as Guest" option. 您不会看到在线商家保护其路线,但是,通常来说,他们有某种“以客人结帐”选项。

transaction details is missing 交易明细丢失

You are resolving promise of stripe.customers.create(body) twice and not on stripe.charges.create So to solve your first problem resolve promise( .then() ) to stripe.charges.create as follows 您正在两次解决stripe.customers.create(body) promise,而不是在stripe.charges.create因此,要解决您的第一个问题,将promise( 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);
    });
  })`

Do i need to protect the POST api ?? 我需要保护POST API吗?

Yes. 是。 You should protect your each and every public API. 您应该保护每个公共API。 You can use JWT or any other oAUTH to protect your routes. 您可以使用JWT或任何其他oAUTH保护您的路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将客户详细信息附加到 Stripe Payment Intent - Attach customer details to Stripe Payment Intent 使用 Stripe Payment Intent 自定义支付流程传递额外的客户详细信息 - Passing extra customer details with Stripe Payment Intent custom payment flow Reactjs Stripe 付款不适用于 Node/Express - Reactjs Stripe payment not working with Node/Express 付款后显示贝宝交易明细 - Showing paypal transaction details after payment 如何在不支付条纹的情况下保存卡详细信息? - how to save card details without making payment on stripe? 如何使用默认的嵌入式付款表格捕获Stripe响应详细信息? - How to catch Stripe responses details with the default embedded payment form? 在单页结账时使用 Stripe Payment 元素改变客户详细信息 - Vary Customer Details with Stripe Payment Element on Single Page Checkout Angular 和 Stripe 订阅保存付款细节并创建订阅 - Angular and Stripe subscriptions save payment details and create the subscription 如何在Vue js中使用paypal / stripe等付款方式收费? 我需要像快递这样的服务器吗? - How do i charge with payment method like paypal/stripe in Vue js? Do i need a server like express? Stripe.js保留多个支付令牌 - Stripe.js Keep Multiple Payment Tokens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM