Search code examples
c#asp.net-core.net-corestripe-paymentsrazor-pages

How to give custom name to post handler in Razor Pages?


I'm implementing Stripe payments on my website.

They say to create the following method on my page.

[HttpPost("create-checkout-session")]
public ActionResult CreateCheckoutSession()
{
    // ...
}

However, this is MVC syntax and I'm using Razor Pages.

public IActionResult OnPost()
{
    // ...
}

I know how to use named handlers, but I don't know how to give my method the name create-checkout-session.


Solution

  • The name create-checkout-session is just a recommendation, not a requirement. The main thing you need to do is have your frontend code call a route on your server that will create a Checkout Session and then perform the next required steps, which vary depending on how exactly you're integrating Stripe.