I'm following this guide here for installing and using webhooks in ASP.Net MVC, but it looks like this guide is for a wep api type project. I'm using a MVC type project and there is no Register method, unlike a API project. In MVC we have a RegisterRoutes method. So how do I register my webhooks in MVC?
an API project that uses Register and config, my ASP.Net MVC site doesn't have this.
MVC uses RegisterRoutes
UPdate Here I added a web api controller and the code I posted below is whats in the web api controller. I included the nuget packages for webhooks, the registration in global.asax.cs and in the register method. But I'm still having problems reaching the code 'ExecuteAsync' no breakpoints are being hit
public class StripeWebHookHandler : WebHookHandler
{
// ngrok http -host-header="localhost:[port]" [port]
// http(s)://<yourhost>/api/webhooks/incoming/stripe/ strip receiver
public StripeWebHookHandler()
{
this.Receiver = StripeWebHookReceiver.ReceiverName;
}
public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
{
// For more information about Stripe WebHook payloads, please see
// 'https://stripe.com/docs/webhooks'
StripeEvent entry = context.GetDataOrDefault<StripeEvent>();
// We can trace to see what is going on.
Trace.WriteLine(entry.ToString());
// Switch over the event types if you want to
switch (entry.EventType)
{
default:
// Information can be returned in a plain text response
context.Response = context.Request.CreateResponse();
context.Response.Content = new StringContent(string.Format("Hello {0} event!", entry.EventType));
break;
}
return Task.FromResult(true);
}
}
You can mix web api controllers in your MVC project. When you add web api controllers, you will have a
WebApiConfig.cs
file in your App_Start where you will definie the routing for web api. That is where you can call theInitializeReceiveStripeWebHooks
method after adding the necessary nuget packages to your project.When you create a new project, Visual studio present you with different project templates. You can select the WebApi one which includes MVC and Web Api support. But if your project is created using the MVC template, it will not have the web api support by default. In that case, you can manually add it by following these steps.
Step #1
Create a new class called
WebApiConfig.cs
in the App_Start folder. Have the below content in that classStep #2
Now go to global.asax and update the
Application_Start
event to include a call to theRegister
method in our newly createdWebApiConfig
class.Now you can right click on project and add new WebApiController classes and web api's should work now.