Sha256: 573f01f813f86b0b8a4bd8a8879eec6ec618d66e4c88c6984c1553f9b48252ca

Contents?: true

Size: 1.63 KB

Versions: 137

Compression:

Stored size: 1.63 KB

Contents

module ActsAsSubscribableBuyer
  extend ActiveSupport::Concern

  module Base
    def acts_as_subscribable_buyer(*options)
      include ::ActsAsSubscribableBuyer
    end
  end

  included do
    has_one :customer, class_name: 'Effective::Customer'

    before_save(if: -> { persisted? && email_changed? && customer.present? }) do
      Rails.logger.info "[STRIPE] update customer: #{customer.stripe_customer_id}"
      customer.stripe_customer.email = email
      customer.stripe_customer.description = to_s
      throw :abort unless (customer.stripe_customer.save rescue false)
    end
  end

  module ClassMethods
    def acts_as_subscribable_buyer?; true; end

    def after_invoice_payment_succeeded(&block)
      send :define_method, :after_invoice_payment_succeeded do |event| self.instance_exec(event, &block) end
    end

    def after_invoice_payment_failed(&block)
      send :define_method, :after_invoice_payment_failed do |event| self.instance_exec(event, &block) end
    end

    def after_customer_subscription_created(&block)
      send :define_method, :after_customer_subscription_created do |event| self.instance_exec(event, &block) end
    end

    def after_customer_subscription_updated(&block)
      send :define_method, :after_customer_subscription_updated do |event| self.instance_exec(event, &block) end
    end

    def after_customer_subscription_deleted(&block)
      send :define_method, :after_customer_subscription_deleted do |event| self.instance_exec(event, &block) end
    end

    def after_customer_updated(&block)
      send :define_method, :after_customer_updated do |event| self.instance_exec(event, &block) end
    end

  end

end

Version data entries

137 entries across 137 versions & 1 rubygems

Version Path
effective_orders-6.17.2 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.17.1 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.17.0 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.16.4 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.16.3 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.16.2 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.16.1 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.16.0 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.15.0 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.6 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.5 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.4 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.3 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.2 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.1 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.14.0 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.13.3 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.13.2 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.13.1 app/models/concerns/acts_as_subscribable_buyer.rb
effective_orders-6.13.0 app/models/concerns/acts_as_subscribable_buyer.rb