How to test receiving of Stripe webhook with stripity_stripe (Phoenix)
stripe_handler_test.ex
defmodule YourApp.StripeHandlerTest do
use YourApp.ConnCase
@valid_payload ~S({"object": "event"})
@secret "secret" # define same string with :stripe_webhook_secret
defp generate_signature_header(payload) do
timestamp = System.system_time(:second)
code = :crypto.mac(:hmac, :sha256, @secret, "#{timestamp}.#{payload}")
signature =
code
|> Base.encode16(case: :lower)
"t=#{timestamp},v1=#{signature}"
end
test "#webhooks returns a 200", %{conn: conn} do
signature_header = generate_signature_header(@valid_payload)
conn =
conn
|> put_req_header("content-type", "application/json")
|> put_req_header("stripe-signature", signature_header)
|> post("/webhook/stripe", @valid_payload)
assert response(conn, 200)
end
end
If you watn to send invoice.paid
event. You may create JSON like this. payload =
~s({
"id": "example",
"object": "event",
"data": {
"object": {
"id": "example",
"object": "invoice",
"customer": "example",
"lines": {
"object": "list",
"data": [
{
"id": "example",
"object": "line_item",
"quantity": 1,
"subscription": "#{subscription_id}",
"subscription_item": "example",
"type": "subscription"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/example/lines"
}
}
},
"livemode": false,
"pending_webhooks": 2,
"type": "invoice.paid"
})
참조: stripity_stripe/webhook_plug_test.exs at f0e20ae57effc6425cde8ec5e889c4793e83d1d1 · code-corps/stripity_stripe
Reference
이 문제에 관하여(How to test receiving of Stripe webhook with stripity_stripe (Phoenix)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/phpmyadmin/articles/c4bf0ea0afeeda텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)