Look at the tutorial for stripity_stripe: https://tolc.io/blog/stripe-with-elixir-and-phoenix
Maybe you don’t need to implement a plug at all because it’s already implemented in the package? Just use the behaviours in your handler @behaviour Stripe.WebhookHandler.
Initial question aside I’m wondering if I’m just using
Stripe.Checkout.Sessiondo I need to even bother with Webhooks? Willl Stripe returning a successful URL be sufficient?
Yes, you need to handle the event after the checkout like I did for setup payment methods:
defmodule MyApp.Endpoint do
plug(Stripe.WebhookPlug,
at: "/webhook/stripe",
handler: MyApp.PaymentService.API.Stripe.EventHandler,
secret: {MyApp.Config, :cfg, [[:stripity_stripe, :signing_secret]]}
)
...
defmodule MyApp.PaymentService.API.Stripe.EventHandler do
@behaviour Stripe.WebhookHandler
@impl Stripe.WebhookHandler
def handle_event(%Stripe.Event{type: "checkout.session.completed", data: %{object: %Stripe.Checkout.Session{mode: "setup"}}} = event) do
...
end
...
It’s required to handle all checkout session events. Look at the Stripe API and handle your events according to entity statuses and event types.
In my case I needed to handle the “checkout.session.completed” and then update some payment method fields in the DB to make it active in my system.
You should look at the events you need https://docs.stripe.com/api/events/types#event_types-checkout.session.async_payment_failed and handle them as you want, e.g. update a Payment schema entity status.
I would not rely on synchronous API responses only and strongly advice to handle events in a webhook.
P.S.: some useful docs and recommendations about using webhooks - Receive Stripe events in your webhook endpoint | Stripe Documentation






















