How to handle Webhook's post request from Stripe

I am trying to handle webhook from stripe.
Stripe sends Webhook data is sent as JSON in the POST request body.
so I need to define endpoint in router.ex file but I don’t need a template and view,
then Do I have to define under

  pipeline :api do
    plug :accepts, ["json"]

this section?
and how can I return Http response 200? like python does

return HttpResponse(status=200)

As Phoenix is another MVC framework, according to its convention such an endpoint should be defined in a controller not in the router file. For example:

scope "/api", YourApp do
  pipe_through :api
  post("/some-path", YourController, :index)
1 Like

You should be able to return a http code response using send_resp/3 since any Plug.Conn function is available on Phoenix Controllers
Such as:

def webhook(conn, params) do
  # parse params or ignore, dispatch to another process, you name it.
  send_resp(conn, 200, "")

Then just add to your routes.ex this example, you may choose any path to it:

scope "/api" MyAppWeb do
  pipe_through :api
  post("/stripe/webhook", PaymentController, :webhook)

1 Like