在第三方付款网站上付款后,如何重新呈现我的前端?

时间:2020-07-03 02:38:37

标签: node.js reactjs api redirect payment

在前端(反应),我有一个付款按钮,可将用户重定向到第三方付款网站。付款完成后,该网站的API会将付款数据发送到我的后端(NodeJS + express)。之后,我进行一些安全检查(以验证哈希是否相同),并将此数据存储到我的数据库中。我已经实现了,一切正常。 但是现在我希望该用户从前端自动获得我的下载链接。 所以我想我的后端应该向前端发送一个付款成功的响应,并且前端应该重新呈现付款块(而不是向用户提供下载链接的付款按钮)。但是我不知道如何将该响应发送到我的前端以及如何在前端实现。 您有任何想法如何执行此操作吗?预先谢谢你!

这是我的后端:

app.post("/paymentConfirmation", (req, res) => {
  const { notification_type, operation_id, amount, currency, datetime, sender, codepro, label, sha1_hash } = req.body;
  // security check
  // forming hesh string from req body parameters and comparing it to req body hesh
  let queryString = `${notification_type}&${operation_id}&${amount}&${currency}&${datetime}&${sender}&${codepro}&TnRBii6WbYjljn5Lw8QF1uQ1&${label}`;
  let heshString = SHA1(queryString).toString();
  if (sha1_hash === heshString) {
    db("paymentlogs")
      .insert({
        name: notification_type,
        sha1_hash: sha1_hash,
        date_time: datetime,
      })
      .then(console.log);
    res.status(200).json("working");
  } else {
    res.status(400).json("hash is different");
  }
});

这是我的战线:

render(){
    
    return(
      <div className="App">
        <Header />
        <Introduction />
        <Presets />       {/* <--- After succesfull payment I want to hide this component  */}
        <DownloadLink />  {/* <--- and to show up this one  */}
        <ButtonsList changeGallerySection={this.changeGallerySection}/>
        <Gallery section={this.state.section}/>
        <ContactInfo />
      </div>
    );
  };

0 个答案:

没有答案