Question

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"

Était-ce utile?

La solution

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

Autres conseils

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!

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.

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

For quick 'n dirty testing: http://requestb.in/

For more formal testing (e.g. continuous integration): https://www.runscope.com/

If you have a online server you may forward port from your computer to that server.

ssh -nNT -R 9090:localhost:3000 root@yourvds.com

And then specify webhook as http://yourvds.com:9090/webhook

all requests will be forwarded to you machine, you will be able to see logs

I know this is an old question, but according to the docs, you can use this code to test your webhook code:

Dictionary<String, String> sampleNotification = gateway.WebhookTesting.SampleNotification(
    WebhookKind.SUBSCRIPTION_WENT_PAST_DUE, "my_id"
);

WebhookNotification webhookNotification = gateway.WebhookNotification.Parse(
    sampleNotification["bt_signature"],
    sampleNotification["bt_payload"]
);

webhookNotification.Subscription.Id;
// "my_id"

You can use the Svix CLI Listener: https://github.com/svix/svix-cli#using-the-listen-command

This will allow you to easily channel requests to your public endpoint to a local port where you can run your logic against and debug it on your localhost.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top