Currently the handle_event callbacks that get defined in a StripeHandler only accept a Stripe.Event. This unfortunately means that we can't leverage the conn during the event handling.
More specifically, I am hoping to trigger email invitations after a checkout has been completed. These invitations will contain a link that directs to an onboarding flow. These links are generated using the Phoenix.VerifiedRoutes.url function which requires a conn.
defmodule MyApp.StripeHandler do
@behaviour Stripe.WebhookHandler
@impl true
def handle_event(%Stripe.Event{type: "checkout.session.completed"} = event) do
# do stuff
end
end
As it stands I will have to extend the Stripe.WebhookPlug locally in order for this flow to work, which is fine in the short term, but not ideal in the long term.
Solution Brainstorm
Adding the conn as an expected argument for the handle_event callbacks allow us to leverage the conn during event handling.
defmodule MyApp.StripeHandler do
@behaviour Stripe.WebhookHandler
@impl true
def handle_event(%Stripe.Event{type: "invoice.paid"} = event, conn) do
# do stuff with conn
invite_url = url(conn, ~p"/some/onboaring/path")
end
end
The downside here is that the conn could potentially be misused (i.e. to prematurely send a response) within the event handler. I'm not sure of the best way to guard against that.
Problem Statement
Currently the
handle_event
callbacks that get defined in aStripeHandler
only accept aStripe.Event
. This unfortunately means that we can't leverage the conn during the event handling.More specifically, I am hoping to trigger email invitations after a checkout has been completed. These invitations will contain a link that directs to an onboarding flow. These links are generated using the
Phoenix.VerifiedRoutes.url
function which requires aconn
.As it stands I will have to extend the
Stripe.WebhookPlug
locally in order for this flow to work, which is fine in the short term, but not ideal in the long term.Solution Brainstorm
Adding the conn as an expected argument for the
handle_event
callbacks allow us to leverage the conn during event handling.The downside here is that the conn could potentially be misused (i.e. to prematurely send a response) within the event handler. I'm not sure of the best way to guard against that.