Skip to content

Commit

Permalink
Merge pull request #89 from roberteles/update-docs
Browse files Browse the repository at this point in the history
Update docs to use the latest references to Stripe
  • Loading branch information
rmm5t committed Aug 22, 2017
2 parents 09a0263 + 179f8c2 commit 7e5ed1e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -101,19 +101,19 @@ This is only truly secure if your webhook endpoint is accessed over SSL, which S

## Configuration

If you have built an application that has multiple Stripe accounts--say, each of your customers has their own--you may want to define your own way of retrieving events from Stripe (e.g. perhaps you want to use the [user_id parameter](https://stripe.com/docs/connect/authentication#webhooks) from the top level to detect the customer for the event, then grab their specific API key). You can do this:
If you have built an application that has multiple Stripe accounts--say, each of your customers has their own--you may want to define your own way of retrieving events from Stripe (e.g. perhaps you want to use the [account parameter](https://stripe.com/docs/connect/webhooks) from the top level to detect the customer for the event, then grab their specific API key). You can do this:

```ruby
StripeEvent.event_retriever = lambda do |params|
api_key = Account.find_by!(stripe_user_id: params[:user_id]).api_key
api_key = Account.find_by!(stripe_user_id: params[:account]).api_key
Stripe::Event.retrieve(params[:id], api_key)
end
```

```ruby
class EventRetriever
def call(params)
api_key = retrieve_api_key(params[:user_id])
api_key = retrieve_api_key(params[:account])
Stripe::Event.retrieve(params[:id], api_key)
end

Expand All @@ -127,6 +127,8 @@ end
StripeEvent.event_retriever = EventRetriever.new
```

*Note: Older versions of Stripe used `user_id` to reference the Connect account.*

If you'd like to ignore particular webhook events (perhaps to ignore test webhooks in production, or to ignore webhooks for a non-paying customer), you can do so by returning `nil` in you custom `event_retriever`. For example:

```ruby
Expand Down

0 comments on commit 7e5ed1e

Please sign in to comment.