Integrating Stripe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def active? | |
not (expired? or exceeds_ticket_volume?) | |
end | |
def expired? | |
expiry < Time.now | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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