Webhook Notification With Authorize.Net

2k views Asked by At

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:

Request Details

2

There are 2 answers

4
John Conde On BEST ANSWER

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"
    }
}
0
findcaiyzh On

I just tested. The subscriptionId field is not the part of Payload of net.authorize.payment.authcapture.created.

So the solution is to use id(transactionid) to call "Get Transaction Details" API which returns the subscription fields.

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