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"]
and how can I return Http response 200? like python does
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
post("/some-path", YourController, :index)
You should be able to return a http code response using send_resp/3 since any
Plug.Conn function is available on Phoenix Controllers
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
post("/stripe/webhook", PaymentController, :webhook)