Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test Webhook at localhost in braintree

I am working on braintree and I want to send custom email notifications to my customers as I am working with recurring billing, so every month these custom notifications should be send to all users. For this I have to use webhooks to retrieve currently ocuured event and then send email notification according to webhook's response. (I think this is only solution in this case, If anyone know another possible solution please suggest). I want to test webhooks at my localhost first, And I have tried to create a new webhook and specified the localhost path as destination to retrieve webhooks. But this shows a error "Destination is not verified"..........

My path is : "http://127.0.0.1:81/webhook/Accept"

like image 374
Singh Avatar asked Jan 20 '14 12:01

Singh


4 Answers

These are some of the tools that can be used during development of webhooks :

1) PostCatcher,

2) RequestBin,

3) ngrok,

4) PageKite and

5) LocalTunnel

http://telerivet.com/help/api/webhook/testing

https://www.twilio.com/blog/2013/10/test-your-webhooks-locally-with-ngrok.html

like image 152
Pradeep Vairamani Avatar answered Sep 28 '22 07:09

Pradeep Vairamani


Well Another way to test it is by creating a WebAPI and POSTing Data to your POST method via Postman. To do this, just create a WebAPI in Visual Studio. In the API controller, create a POST method.

/// <summary>
/// Web API POST method for Braintree Webhook request
/// The data is passed through HTTP POST request. 
/// A sample data set is present in POSTMAN HTTP Body
/// /api/webhook
/// </summary>
/// <param name="BTRequest">Data from HTTP request body</param>
/// <returns>Webhook notification object</returns>
public WebhookNotification Post([FromBody]Dictionary<String, String> BTRequest)
{

    WebhookNotification webhook = gateway.WebhookNotification.Parse(BTRequest["bt_signature"], BTRequest["bt_payload"]);
    return webhook;
}

In Postman, Post the following data in the Body as raw JSON.

    {
        "bt_signature":"Generated Data",
        "bt_payload":"Very long generated data"
}

The data for the above Json dictionary has been generated through the below code:

     Dictionary<String, String> sampleNotification = gateway.WebhookTesting.SampleNotification(WebhookKind.DISPUTE_OPENED, "my_Test_id");
// Your Webhook kind and your test ID

Just pick the data from sample notification and place it above in the JSON. Run your WebAPI, place debuggers. Add the localhost URL in Postman, select POST, and click on Send. Your POST method should be hit.

Also, don't forget to add your gateway details:

private BraintreeGateway gateway = new BraintreeGateway
        {
            Environment = Braintree.Environment.SANDBOX,
            MerchantId = "Your Merchant Key",
            PublicKey = "Your Public Key",
            PrivateKey = "Your Private Key"
        };

I hope this helps!

like image 40
Purushottam.Prasad Avatar answered Sep 28 '22 08:09

Purushottam.Prasad


I work at Braintree. If you need more help, please get in touch with our support team.

In order to test webhooks, your app needs to be able to be reached by the Braintree Gateway. A localhost address isn't. Try using your external IP address and make sure the port on the correct computer can be reached from the internet.

Take a look at the Braintree webhook guide for more info on setting up webhooks.

like image 30
agf Avatar answered Sep 28 '22 07:09

agf


You can use PutsReq to simulate the response you want and do your end-to-end test in development.

like image 22
Pablo Cantero Avatar answered Sep 28 '22 07:09

Pablo Cantero