Skip to content

Instantly share code, notes, and snippets.

@avinasha
Created August 24, 2012 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avinasha/3448738 to your computer and use it in GitHub Desktop.
Save avinasha/3448738 to your computer and use it in GitHub Desktop.
Integrating Stripe
def active?
not (expired? or exceeds_ticket_volume?)
end
def expired?
expiry < Time.now
end
module SupportBee
class StripeWebhooks
attr_reader :params, :company
# 'params' is the POST params which Stripe sends to your application
def initialize(params)
@params = get_event_from_stripe(params['id'])
@company = get_company
end
def consume
case @params['type']
when "invoice.payment_succeeded"
send_invoice
extend_expiry
notify_campfire
when "customer.deleted"
downgrade_to_trial
end
end
private
def get_company
customer_id = @params['data']['object']['customer'] if @params['type'] == "invoice.payment_succeeded"
customer_id = @params['data']['object']['id'] if @params['type'] == "customer.deleted"
Company.find_by_stripe_customer_id(customer_id)
end
def get_event_from_stripe(event_id)
Stripe::Event.retrieve(event_id)
end
...
...
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment