Closed patrickmichalina closed 7 years ago
Could you take a look at our comment in #48?
@EvanHahn maybe you can explain to me where I am going wrong. The current .NET documentation does not show any scenario beside the MVC ActionResult. When using Web API 2, what would be the appropriate strategy? As mentioned in my comment above, I found an additional "\" in the raw value of the payload. The only way I have been able to get this to work has been to use (which took me several days to figure out):
public async Task<IHttpActionResult> Marketplaces([FromBody] MyFormData hook)
{
... // removed for clarity
var webhookNotification = _braintreeGateway.WebhookNotification.Parse(
hook.bt_signature,
hook.bt_payload.Replace("\\n", "\n"));
... // removed for clarity
}
public class MyFormData
{
public string bt_signature { get; set; }
public string bt_payload { get; set; }
}
I am not sure why this is happening, and worry it may break in the future. I don't think asking braintree to support Web API use-cases is unreasonable. Also, supporting a Content-Type: application/json doesn't seem like an outlandish request either.
A couple of questions to help you debug:
.Replace
, what error do you see when parsing?Framework: .NET 4.6.2 (was happening on 4.6 as well and probably 4.5 - can't remember).
Error Message "payload contains illegal characters"
which I believe is an invalid signature exception found in the code here
That's helpful! What version of the Braintree .NET SDK are you using?
@EvanHahn I am now at 3.5.0 but this was happening back in 3.4.0 as well (when I first started using this API).
@patrickmichalina - Thanks again for the feedback.
We're unable to recreate the issue. Have you checked your web framework to ensure it isn't adding the extra character somewhere?
@demerino did you attempt to recreate this in ASP.NET Web API 2? If so, then I will have to investigate any changed I add in the API pipeline...
We didn't, but we haven't seen other reports of this issue, which makes us think that there might be something special in your case.
The bad news is that we're not very well-versed in .NET (let alone ASP.NET Web API) so I'm not sure we'll be much help. The good news is that you have a fix, albeit an inelegant one.
@EvanHahn ok thanks for looking into it!
If I find a framework level explanation for this I will update this issue.
Cheers
I have had nothing but struggles trying to integrate Braintree webhooks into my Web API. The .net documentation only focuses on MVC apps, but does not clarify subtle differences with a Web API. It took me days to figure out I need to strip out an additional character that is being added to the payload:
Would it not be better to support a json payload type with base64 encoding? x-www-form-encoded does not fit all needs and is error prone.