问题描述
我在 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"
}
}
我相信,对于网络钩子通知来说已经足够接近了。但是任何人都可以建议何时使用 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;
}
请求正文和响应:
解决方法
网络钩子通知将几乎与“常规”交易完全一样,但还将包含订阅 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"
}
}