【问题标题】:Webhook Notification With Authorize.Net使用 Authorize.Net 的 Webhook 通知
【发布时间】:2021-07-31 15:06:36
【问题描述】:

我在 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 触发事件时的输出。

对于常规交易,我使用 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# Web 应用的 Web 请求

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

请求正文和响应

【问题讨论】:

    标签: c# asp.net authorize.net recurring-billing authorize.net-webhooks


    【解决方案1】:

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

    【讨论】:

    • 所以你的意思是当订阅费用完成时我会在那个端点的响应正文中得到这个(我在 webhook 设置中提供的那个)?
    • 正确。这只是另一种具有特殊特征的付款:订阅 ID
    • 我在Authorize.Net 上学到了很多东西。非常感谢您抽出宝贵的时间@John Conde 以及官方网站中提供的带有示例代码的文档。虽然我是在官方网站上了解到的,但假设无论如何,定期付款失败(因为它应该自动使用用户卡详细信息从Authorize.Net收取),我相信,一个响应将被发送到具有上述订阅ID的网站你分享的。失败可能是任何事情,比如端点异常或卡过期。
    猜你喜欢
    • 2019-05-25
    • 2014-02-11
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 2019-12-14
    • 2020-03-22
    相关资源
    最近更新 更多