c# - 无法保存使用 ASP.NET C# Web 窗体接收的 Razorpay Webhook 数据

标签 c# asp.net webhooks razorpay

我正在尝试将从 Razorpay webhook 接收到的 POST 数据保存到我的 SQL 服务器。但我做不到。我无法找出问题,请帮助我。

我是 Webhook 新手。

下面是我的页面,Webhook 给出了响应:

Successpage.aspx.cs代码:

using System;
using Razorpay.Api;
using System.IO;
using System.Text;

public partial class Razorpay_Successpage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string documentContents;
        //To Capture RAW JSON posted
        using (Stream receiveStream = Request.InputStream)
        {
            using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
            {
                documentContents = readStream.ReadToEnd();
            }
        }

        Response.Write(documentContents);

        //To Capture Signature

        var RazorpaySignature = Request.Headers["X-Razorpay-Signature"];

        Response.Write(RazorpaySignature);
        //Response.Write(ReqHeader);```
    }
}

以上代码仅打印在您的结帐回调 URL 上发送的标准 razorpay 响应。

我想打印 webhook 提供的其他数据,所以请帮助我。

最佳答案

获取文档内容后,我尝试通过这种方式获取数据:

var details = (JObject)JsonConvert.DeserializeObject(documentContents);
var data = details["payload"];
var payment = data["payment"];
var entity = payment["entity"];
string OrderId = entity["order_id"].ToString();
string  paymentstatus = entity["status"].ToString();

通过这种方式,我在局部变量中获得了 order_id 和付款状态,并将其保存到数据库中。希望对您有所帮助!

关于c# - 无法保存使用 ASP.NET C# Web 窗体接收的 Razorpay Webhook 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55645536/

相关文章:

c# - 如何重构模型以解决代码警告 : "CA2214" and "CA2227"?

c# - ML.NET:功能列的架构不匹配 'Features'

javascript - 如何在下拉菜单中将复选标记显示为文本?

go - Heroku 托管应用程序上的 Webhook 未更新

c# - 为什么 grid.Rows.Count 总是 0?

c# - MySQL ExecuteNonQuery 抛出 "There is already an open DataReader associated with this Command which must be closed first"异常

c# - 在 ASP.net 数据访问应用程序中跟踪用户操作

.net - 使用 Entity Framework 作为数据访问层

reactjs - 在 React Frontend 中安全存储身份验证 token

webhooks - 无法从应用程序 POST 到 Slack Incoming Webhook