Class: StripeModelCallbacks::ApplicationRecord
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- StripeModelCallbacks::ApplicationRecord
show all
- Includes:
- PublicActivity::Model
- Defined in:
- app/models/stripe_model_callbacks/application_record.rb
Direct Known Subclasses
StripeBankAccount, StripeCard, StripeCharge, StripeCoupon, StripeCustomer, StripeDiscount, StripeDispute, StripeInvoice, StripeInvoiceItem, StripeOrder, StripeOrderItem, StripePayout, StripePlan, StripePrice, StripeProduct, StripeRecipient, StripeRefund, StripeReview, StripeSku, StripeSource, StripeSubscription, StripeSubscriptionDefaultTaxRate, StripeSubscriptionItem, StripeSubscriptionSchedule, StripeSubscriptionSchedulePhase, StripeSubscriptionSchedulePhasePlan, StripeTaxRate, StripeTransfer
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
permalink
#stripe_object=(value) ⇒ Object
Sets the attribute stripe_object
7
8
9
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 7
def stripe_object=(value)
@stripe_object = value
end
|
Class Method Details
permalink
.check_object_is_stripe_class(object, allowed = nil) ⇒ Object
[View source]
9
10
11
12
13
14
15
16
17
18
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 9
def self.check_object_is_stripe_class(object, allowed = nil)
raise "'stripe_class' not defined on #{name}" unless respond_to?(:stripe_class)
return if object.class.name == "Stripe::StripeObject"
allowed ||= [stripe_class]
raise "Expected #{object.class.name} to be a #{allowed.map(&:name).join(", ")}" unless allowed.any? { |stripe_class| object.is_a?(stripe_class) }
end
|
permalink
.create_from_stripe!(object) ⇒ Object
[View source]
24
25
26
27
28
29
30
31
32
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 24
def self.create_from_stripe!(object)
check_object_is_stripe_class(object)
model = new
model.stripe_object = object
model.assign_from_stripe(object)
model.save!
model
end
|
permalink
.create_on_stripe!(attributes) ⇒ Object
[View source]
34
35
36
37
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 34
def self.create_on_stripe!(attributes)
object = stripe_class.create(attributes)
create_from_stripe!(object)
end
|
Instance Method Details
permalink
#check_object_is_stripe_class(object, allowed = nil) ⇒ Object
[View source]
20
21
22
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 20
def check_object_is_stripe_class(object, allowed = nil)
self.class.check_object_is_stripe_class(object, allowed)
end
|
permalink
#destroy_on_stripe ⇒ Object
[View source]
67
68
69
70
71
72
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 67
def destroy_on_stripe
to_stripe.delete
update!(deleted_at: Time.zone.now) if respond_to?(:deleted_at)
reload_from_stripe!
true
end
|
permalink
#destroy_on_stripe! ⇒ Object
[View source]
74
75
76
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 74
def destroy_on_stripe!
raise ActiveRecord::RecordInvalid, self unless destroy_on_stripe
end
|
permalink
#reload!(*args, &blk) ⇒ Object
[View source]
48
49
50
51
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 48
def reload!(*args, &blk)
@to_stripe = nil
super
end
|
permalink
#reload_from_stripe! ⇒ Object
[View source]
43
44
45
46
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 43
def reload_from_stripe!
assign_from_stripe(to_stripe)
save!
end
|
permalink
#to_stripe ⇒ Object
[View source]
39
40
41
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 39
def to_stripe
@to_stripe ||= self.class.stripe_class.retrieve(stripe_id)
end
|
permalink
#update_on_stripe(attributes) ⇒ Object
[View source]
53
54
55
56
57
58
59
60
61
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 53
def update_on_stripe(attributes)
attributes.each do |key, value|
to_stripe.__send__("#{key}=", value)
end
to_stripe.save
reload_from_stripe!
true
end
|
permalink
#update_on_stripe!(attributes) ⇒ Object
[View source]
63
64
65
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 63
def update_on_stripe!(attributes)
raise ActiveRecord::RecordInvalid, self unless update_on_stripe(attributes)
end
|