https://github.com/gearnode/stripe_eventex
Stripe webhook integration for Plug.
https://github.com/gearnode/stripe_eventex
stripe stripe-event webhook
Last synced: 10 months ago
JSON representation
Stripe webhook integration for Plug.
- Host: GitHub
- URL: https://github.com/gearnode/stripe_eventex
- Owner: gearnode
- License: mit
- Created: 2016-06-11T21:23:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-19T16:22:44.000Z (over 7 years ago)
- Last Synced: 2025-03-28T18:05:54.622Z (10 months ago)
- Topics: stripe, stripe-event, webhook
- Language: Elixir
- Homepage: https://hex.pm/packages/stripe_eventex
- Size: 29.3 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
:warning: master branch is currently on active development, [last stable version](https://github.com/gearnode/stripe_eventex/tree/1.0.0)
[](https://travis-ci.org/gearnode/stripe_eventex)
# StripeEventex
## Installation
Add `stripe_eventex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:stripe_eventex, "~> 2.0.0"}]
end
```
Then run `mix do deps.get, deps.compile`, inside your project's directory.
## Usage
```elixir
defmodule StripeEventApplication do
import Plug.Conn
use Plug.Router
plug StripeEventex, path: "/stripe_hooks", validation: &StripeEventApplication.valid!/1
plug :match
plug :dispatch
get "/super_app" do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "Hello, World")
end
def valid!(conn), do: true
end
```
In your `config.exs` file, you must subscribe to event like this
```elixir
config :stripe_eventex, subscibed_events: [{"customer.created", Stripe.CustomerCreated},
{"customer.updated", Stripe.CustomerUpdated}]
```
Your module must implement perform/1 function, the arguments is stripe event paylaod.
e.g.
```elixir
defmodule Stripe.CustomerCreated do
def perform(event) do
IO.inspect event
end
end
```
### The validation callback
The validation callback will be called to decide if the stripe event is authorized or not.
- It has to be defined in the format &Mod.fun/1.
- It receives `%Plug.Conn.__struct__`, and must return true or false