使用 Authorize.Net 的 Webhook 通知 [英] Webhook Notification With Authorize.Net

查看:25
本文介绍了使用 Authorize.Net 的 Webhook 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Authorize.Net 中为 webhook 部分创建了一个端点(

解决方案

Webhook 通知将几乎与常规"通知完全一样.交易,但订阅 ID 也将包括在内.所以它应该类似于:

<代码>{notificationId":c453f527-8b7c-407d-8ec7-b022188af4a7",事件类型":net.authorize.payment.authcapture.created",事件日期":2021-05-08T17:51:20.5783303Z",webhookId":3b2fd08b-a7c4-4f29-95b5-8330958d6031",有效载荷":{响应代码":1,authCode":OT3UUE",avsResponse":Y",authAmount":1.00,实体名称":交易",id":60167299547",订阅 ID":1234567890"}}

I created an endpoint (Endpoint) for the webhook part in Authorize.Net and when I create subscription for a user from web app, I get the following in the request body (Am using Beeceptor for the endpoint):

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

I followed the link to create the endpoint - Webhook

I believe, am close enough for webhook notifications. But can anyone suggest when the monthly subscription is charged using Authorize.Net, how the response body is passed to endpoint with the webhook like is it jSon data or something similar (Obviously jSon, I believe) or what fields will it return in response (SubscriptionId, Date)? In the documentation, they trigger different event to notify with Webhook. My final goal is to retrieve that a subscriber has been charged for a month and this should be saved in database for future use. Though I just started trying with it, will like to have some feedback on it in advance - Thanks.

N.B: Below image is the output when an event is triggered using Webhook.

For regular transaction, I get the following using webhook notification:

{
    "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# sample Code: Web request from C# web app

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 body and response:

解决方案

The webhook notification will be almost exactly like a "regular" transaction but a subscription ID will also be included. So it should resemble:

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

这篇关于使用 Authorize.Net 的 Webhook 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆