lib/pay/billable.rb in pay-2.0.3 vs lib/pay/billable.rb in pay-2.1.0
- old
+ new
@@ -2,12 +2,25 @@
module Pay
module Billable
extend ActiveSupport::Concern
- included do
+ # Keep track of which Billable models we have
+ class << self
+ attr_reader :includers
+ end
+
+ def self.included(base = nil, &block)
+ @includers ||= []
+ @includers << base if base
+ super
+ end
+
+ included do |base|
include Pay::Billable::SyncEmail
+ include Pay::Stripe::Billable if defined? ::Stripe
+ include Pay::Braintree::Billable if defined? ::Braintree
has_many :charges, class_name: Pay.chargeable_class, foreign_key: :owner_id, inverse_of: :owner
has_many :subscriptions, class_name: Pay.subscription_class, foreign_key: :owner_id, inverse_of: :owner
attribute :plan, :string
@@ -110,11 +123,11 @@
end
private
def check_for_processor
- raise StandardError, "No payment processor selected. Make sure to set the #{Pay.billable_class}'s `processor` attribute to either 'stripe' or 'braintree'." unless processor
+ raise StandardError, "No payment processor selected. Make sure to set the #{self.class.name}'s `processor` attribute to either 'stripe' or 'braintree'." unless processor
end
# Used for creating a Pay::Subscription in the database
def create_subscription(subscription, processor, name, plan, options = {})
options[:quantity] ||= 1
@@ -123,10 +136,10 @@
name: name || "default",
processor: processor,
processor_id: subscription.id,
processor_plan: plan,
trial_ends_at: send("#{processor}_trial_end_date", subscription),
- ends_at: nil,
+ ends_at: nil
)
subscriptions.create!(options)
end
def default_generic_trial?(name, plan)