I’m working through this tutorial trying to get payments working with Stripe.
I’ve implemented a Stripe webhook handler:
defmodule Postbox.StripeHandler do
@behaviour Plug
alias Plug.Conn
def init(config), do: config
def call(%{request_path: "/webhook/payments"} = conn, _params) do
signing_secret = Application.get_env(:stripity_stripe, :webhook_key)
[stripe_signature] = Plug.Conn.get_req_header(conn, "stripe-signature")
with {:ok, body, _} = Plug.Conn.read_body(conn),
{:ok, stripe_event} =
Stripe.Webhook.construct_event(body, stripe_signature, signing_secret) do
Plug.Conn.assign(conn, :stripe_event, stripe_event)
else
err ->
conn
|> Conn.send_resp(:bad_request, err)
|> Conn.halt()
end
end
end
I’ve copied my webhook secret (:webhook_key
directly from the signing secret) but I’m still, continuously getting this error from Stripe: ** (MatchError) no match of right hand side value: {:error, "No signatures found matching the expected signature for payload"}
.
This is a test account and I’m using Ngrok for the Webhook address.
Initial question aside I’m wondering if I’m just using Stripe.Checkout.Session
do I need to even bother with Webhooks? Willl Stripe returning a successful URL be sufficient?