Test Webhook at localhost in braintree

后端 未结 7 2233
故里飘歌
故里飘歌 2021-02-06 01:03

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

7条回答
  •  终归单人心
    2021-02-06 01:26

    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.

    /// 
    /// 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
    /// 
    /// Data from HTTP request body
    /// Webhook notification object
    public WebhookNotification Post([FromBody]Dictionary 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 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!

提交回复
热议问题