Receive Webhook

Asked

Viewed 40 times

0

I have a system in VB.NET where I need to receive webhook from the financial system that generates charges and receives payments. Every API integration is already working with this service, I just need to receive the webhook every change of transaction status to do the procedures in my database and so not have to consult every x transaction in x time.

Their documentation says that: "Transactional Webhook This webhook triggers and sends a POST notification to each change in the status of a transaction. It applies to all forms of payment and comprises the entire life cycle of a transaction."

I never developed receiving webhooks and while researching about, I had some questions.

In integrating with the Payments API, when creating a new charge for example, send a POST to the API. When consulting a charge, I send a GET. All this using Webrequest.

For Webhook, it is possible to do the same, and instead of sending, receive the POST on a page with Webrequest?

This is an example code structure I use to send a POST:

' ENVIO DA REQUISIÇÃO E OBTENÇÃO DO RETORNO
Public Sub SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String, requisicao As String)

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12

    Dim request As WebRequest

    request = WebRequest.Create(uri)
    request.ContentLength = jsonDataBytes.Length
    request.ContentType = contentType
    request.Method = method
    request.Headers.Add("X-API-KEY", buscaChaveAPIProducao())
    'request.Headers.Add("X-API-KEY", buscaChaveAPITeste())

    Using requestStream = request.GetRequestStream

        requestStream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
        requestStream.Close()

        Try

            Using responseStream = request.GetResponse.GetResponseStream
                Using reader As New StreamReader(responseStream)

                    Dim objResponse As Object = reader.ReadToEnd()

                End Using
            End Using

        Catch ex As WebException
        End Try

    End Using

End Sub
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.