简体   繁体   English

如何在 Razorpay 交易结束后重定向回我的网站。 注意:如果“redirect=true”作为选项传递

[英]How to Redirect back to my website after transaction ends on Razorpay . Note: if "redirect=true" is passed as an option

Firstly I am using React and NodeJs for this integration.首先,我使用 React 和 NodeJs 进行此集成。

I know it's possible to redirect back to the website by using location.href in the handler function.我知道可以通过在处理程序 function 中使用location.href重定向回网站。

But what if we are using redirect=true as an options.但是如果我们使用redirect=true作为选项呢?

It's also mentioned that we can pass the callback_url to the options object. This will make razorpay to redirect to this URL after a successful transaction but this is going to be a POST request.它还提到我们可以将callback_url 传递给选项 object。这将使 razorpay 在交易成功后重定向到这个 URL,但这将是一个POST请求。 So, we cannot give the URL of our website in here.所以,我们不能在这里给出我们网站的URL。

example:例子:

const options = {
  key: "razorpay_key",
  currency: data.currency,
  amount: data.amount.toString(),
  order_id: data.id,
  handler: function (response) {
    alert(response.razorpay_payment_id);
    alert(response.razorpay_order_id);
    alert(response.razorpay_signature);
  },
  prefill: {
    name,
    email: "abcd@xyz.com",
    contact: "9999999999",
    method: "netbanking",
  },
  redirect: true, // this redirects to the bank page from my website without opening a new window
  callback_url: "not sure what to do with it",
};

Is there any way I can get back to the cart/website page with these parameters in params (razorpay_payment_id, razorpay_order_id, razorpay_signature) after completion of the transaction.在交易完成后,有什么方法可以让我在参数(razorpay_payment_id、razorpay_order_id、razorpay_signature)中使用这些参数返回购物车/网站页面。

here you can check all the parameters for checkout options: https://razorpay.com/docs/payments/server-integration/nodejs/payment-gateway/build-integration/#checkout-options在这里您可以检查结帐选项的所有参数: https://razorpay.com/docs/payments/server-integration/nodejs/payment-gateway/build-integration/#checkout-options

Razorpay web checkout docs link: https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/ Razorpay web 结帐文档链接: https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/

Eventually, I found a way to do the same.最终,我找到了一种方法来做同样的事情。 As I am using SSR, I created a POST route on my server and simply redirected from there to my webpage.当我使用 SSR 时,我在我的服务器上创建了一个 POST 路由,然后简单地从那里重定向到我的网页。

like,喜欢,

app.post('/verification', asyncHandler((req, res) => {res.redirect(301, `webpage_url?query_param=${req.body.razorpay_payment_id}`}))

so, checkout options object looks like below因此,结帐选项 object 如下所示

const options = {
    ... // existing options
    redirect: true,
    callback_url: "server_address/verification",
};

Hope it helps someone out facing the same issue:)希望它能帮助面临同样问题的人:)

You should have another db which stores all the value for your order.您应该有另一个数据库来存储您订单的所有价值。

So, Your callback_url will be -所以,你的 callback_url 将是 -

Api to the database + unique order_id to provide you with details of order. Api到数据库+唯一order_id为您提供订单详情。

var options = {
  ... // existing options
  callback_url: 'https://localhost:3000/cart'+order_id,
  redirect: true
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM