0.0
No commit activity in last 3 years
No release in over 3 years
A webhookr extension to support Stripe webhooks.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Webhookr::Stripe

Build Status Dependency Status Code Climate Coverage Status

This gem is a plugin for Webhookr that enables your application to accept webhooks from Stripe.

Installation

Add this line to your application's Gemfile:

gem 'webhookr-stripe'

Or install it yourself:

$ gem install webhookr-stripe

webhookr is installed as a dependency of webhookr-stripe. If you have not setup Webhookr, do so now:

rails g webhookr:add_route

Usage

Once you have the gem installed run the generator to add the code to your initializer. An initializer will be created if you do not have one.

rails g webhookr:stripe:init *initializer_name* -s

Run the generator to create an example file to handle stripe webhooks.

rails g webhookr:stripe:example_hooks

Or create a stripe handler class for any event that you want to handle. For example to handle unsubscribes you would create a class as follows:

class StripeHooks
  def on_charge_succeeded(incoming)
    # Your custom logic goes here.
    charge = incoming.payload
    puts("charge.succeeded: (#{charge})")
  end
end

For a complete list of events, and the payload format, see below.

Edit config/initializers/initializer_name and change the commented line to point to your custom Stripe event handling class. If your class was called StripeHooks the configuration line would look like this:

  Webhookr::Stripe::Adapter.config.callback = StripeHooks

To see the list of Stripe URLs your application can use when you configure stripe webhooks, run the provided webhookr rake task:

rake webhookr:services

Example output:

stripe:
  GET	/webhookr/events/stripe/19xl64emxvn
  POST	/webhookr/events/stripe/19xl64emxvn

Stripe Events & Payload

Events

All webhook events are supported. For further information on these events, see the stripe documentation.

Stripe Event Event Handler
account.updated on_account_updated(incoming)
charge.succeeded on_charge_succeeded(incoming)
charge.failed on_charge_failed(incoming)
charge.refunded on_charge_refunded(incoming)
charge.dispute.created on_charge_dispute_created(incoming)
charge.dispute.updated on_charge_dispute_updated(incoming)
charge.dispute.closed on_charge_dispute_closed(incoming)
coupon.created on_coupon_created(incoming)
coupon.deleted on_coupon_deleted(incoming)
customer.created on_customer_created(incoming)
customer.updated on_customer_updated(incoming)
customer.deleted on_customer_deleted(incoming)
customer.discount.created on_customer_discount_created(incoming)
customer.discount.updated on_customer_discount_updated(incoming)
customer.discount.deleted on_customer_discount_deleted(incoming)
customer.subscription.created on_customer_subscription_created(incoming)
customer.subscription.updated on_customer_subscription_updated(incoming)
customer.subscription.deleted on_customer_subscription_deleted(incoming)
invoice.created on_invoice_created(incoming)
invoice.updated on_invoice_updated(incoming)
invoice.payment_succeeded on_invoice_payment_succeeded(incoming)
invoice.payment_failed on_invoice_payment_failed(incoming)
invoiceitem.created on_invoiceitem_created(incoming)
invoiceitem.updated on_invoiceitem_updated(incoming)
invoiceitem.deleted on_invoiceitem_deleted(incoming)
plan.created on_plan_created(incoming)
plan.updated on_plan_updated(incoming)
plan.deleted on_plan_deleted(incoming)
transfer.created on_transfer_created(incoming)
transfer.updated on_transfer_updated(incoming)
transfer.paid on_transfer_paid(incoming)
transfer.failed on_transfer_failed(incoming)

Payload

The payload is the full payload data from as per the stripe documentation, converted to an OpenStruct for ease of access. Examples can be found in the example hook file.

Supported Service - stripe

Works with:

webhookr-stripe works with Rails 3.1, 3.2 and 4.0, and has been tested on the following Ruby implementations:

  • 2.0.0
  • 2.1.0

Pending:

  • 1.9.3
  • jruby-19mode

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, once this gem reaches a 1.0 release, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision. For example:

spec.add_dependency 'webhookr-stripe', '~> 1.0'

While this gem is currently a 0.x release, suggestion is to require the exact version that works for your code:

spec.add_dependency 'webhookr-stripe', '0.0.1'

License

webhookr-stripe is released under the MIT license.

Author