使用 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"
    }
}

我按照 link 创建端点 - Webhook

我相信,已经足够接近 webhook 通知了。但是任何人都可以建议何时使用 Authorize.Net 收取每月订阅费用,如何使用 webhook 将响应正文传递到端点,就像它是 jSon 数据或类似的东西(显然 jSon,我相信) 或它将 return 响应哪些字段(SubscriptionId、Date)?在文档中,它们触发不同的事件以通过 Webhook 进行通知。我的最终目标是检索订户已被收取一个月的费用,这应该保存在数据库中以备将来使用。虽然我才刚刚开始尝试,但还是希望能提前收到一些反馈 - 谢谢。

N.B:下图是使用Webhook触发事件时的输出。

对于常规交易,我使用 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# 示例代码:来自 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;
}

请求正文和响应:

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

我刚刚测试过。 subscriptionId 字段不是 net.authorize.payment.authcapture.created.

的 Payload 的一部分

所以解决方案是使用 id(transactionid) 调用“Get Transaction Details”API,其中 returns 订阅字段。

参考:https://community.developer.cybersource.com/t5/Integration-and-Testing/net-authorize-payment-authcapture-created-does-not-have/td-p/63234