繁体   English   中英

使用 Authorize.Net 的 Webhook 通知

[英]Webhook Notification With Authorize.Net

我在 Authorize.Net 中为 webhook 部分创建了一个端点( Endpoint ),当我从 web 应用程序为用户创建订阅时,我在请求正文中得到以下内容(我使用 Beeceptor 作为端点):

{
    "notificationId": "79780e46-c62d-4620-b4fb-e8c29366b2ec",
    "eventType": "net.authorize.customer.subscription.created",
    "eventDate": "2021-05-08T17:23:57.7129026Z",
    "webhookId": "3b2fd08b-a7c4-4f29-95b5-8330958d6031",
    "payload": {
        "name": "AT",
        "amount": 3.00,
        "status": "active",
        "profile": {
            "customerProfileId": 1518406781,
            "customerPaymentProfileId": 1517676588
        },
        "entityName": "subscription",
        "id": "7397362"
    }
}

我按照链接创建端点 - Webhook

我相信,对于 webhook 通知来说已经足够接近了。 但是任何人都可以建议何时使用 Authorize.Net 收取每月订阅费用,响应正文如何通过 webhook 传递到端点,例如它是 jSon 数据还是类似的东西(显然是 jSon,我相信)或者它将返回哪些字段作为响应(订阅 ID、日期)? 在文档中,它们触发不同的事件以使用 Webhook 进行通知。 我的最终目标是检索已向订阅者收取一个月的费用,并将其保存在数据库中以备将来使用。 虽然我刚开始尝试它,但希望提前获得一些反馈 - 谢谢。

注意:下图是使用 Webhook 触发事件时的 output。

对于常规交易,我使用 webhook 通知得到以下信息:

{
    "notificationId": "c453f527-8b7c-407d-8ec7-b022188af4a7",
    "eventType": "net.authorize.payment.authcapture.created",
    "eventDate": "2021-05-08T17:51:20.5783303Z",
    "webhookId": "3b2fd08b-a7c4-4f29-95b5-8330958d6031",
    "payload": {
        "responseCode": 1,
        "authCode": "OT3UUE",
        "avsResponse": "Y",
        "authAmount": 1.00,
        "entityName": "transaction",
        "id": "60167299547"
    }
}

C# 示例代码:Web 请求来自 C# Z2567A5EC9705EB7AC2C984033E0618

public string GetNotificationWithWebhook()
{
  string response = "";
 
  var url = "beeceptor endpoint here";

  var httpRequest = (HttpWebRequest)WebRequest.Create(url);
  var httpResponse = (HttpWebResponse)httpRequest.GetResponse();

  using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
  {
    response = streamReader.ReadToEnd();
  }

  return response;
}

请求正文和响应

请求详细信息

webhook 通知将几乎与“常规”事务完全一样,但也会包含订阅 ID。 所以它应该类似于:

{
    "notificationId": "c453f527-8b7c-407d-8ec7-b022188af4a7",
    "eventType": "net.authorize.payment.authcapture.created",
    "eventDate": "2021-05-08T17:51:20.5783303Z",
    "webhookId": "3b2fd08b-a7c4-4f29-95b5-8330958d6031",
    "payload": {
        "responseCode": 1,
        "authCode": "OT3UUE",
        "avsResponse": "Y",
        "authAmount": 1.00,
        "entityName": "transaction",
        "id": "60167299547",
        "subscriptionId": "1234567890"
    }
}

暂无
暂无

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

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