微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Authorize.Net 的 Webhook 通知

如何解决使用 Authorize.Net 的 Webhook 通知

我在 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

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

注意:下图是使用 Webhook 触发事件时的输出

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

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

C# 示例代码:来自 C# 网络应用程序的网络请求

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

请求正文和响应

Request Details

解决方法

网络钩子通知将几乎与“常规”交易完全一样,但还将包含订阅 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"
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。