Sha256: 44981110938ab9045feee0db9063a016a4849511d5e5e1a8591e4b37bc75ced1

Contents?: true

Size: 980 Bytes

Versions: 5

Compression:

Stored size: 980 Bytes

Contents

# == Schema Information
#
# Table name: wbase_stripe_webhooks
#
#  id               :integer          not null, primary key
#  external_id      :string
#  object           :string
#  api_version      :string
#  created          :datetime
#  data             :json
#  livemode         :boolean
#  pending_webhooks :integer
#  external_type    :string
#  external_request :string
#  created_at       :datetime         not null
#  updated_at       :datetime         not null
#

module Wbase
  class StripeWebhook < ActiveRecord::Base
    def process!
      if external_type == 'customer.subscription.updated'
        subscription = Subscription.find_by(stripe_id: customer_stripe_id)
        subscription.update(paid_thru: Time.at(paid_thru))
      end
    end

    def customer_stripe_id
      get("customer")
    end

    def paid_thru
      data.fetch("object", {}).fetch("current_period_end")
    end

    def get(key)
      data.fetch("object", {}).fetch(key)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wbase-0.2.7 app/models/wbase/stripe_webhook.rb
wbase-0.2.6 app/models/wbase/stripe_webhook.rb
wbase-0.2.5 app/models/wbase/stripe_webhook.rb
wbase-0.2.4 app/models/wbase/stripe_webhook.rb
wbase-0.2.3 app/models/wbase/stripe_webhook.rb