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, StripeProduct, StripeRecipient, StripeRefund, StripeReview, StripeSku, StripeSource, StripeSubscription, StripeSubscriptionItem, StripeTransfer
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#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
.create_from_stripe!(object) ⇒ Object
9
10
11
12
13
14
15
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 9
def self.create_from_stripe!(object)
model = new
model.stripe_object = object
model.assign_from_stripe(object)
model.save!
model
end
|
.create_on_stripe!(attributes) ⇒ Object
17
18
19
20
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 17
def self.create_on_stripe!(attributes)
object = stripe_class.create(attributes)
create_from_stripe!(object)
end
|
Instance Method Details
#destroy_on_stripe ⇒ Object
50
51
52
53
54
55
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 50
def destroy_on_stripe
to_stripe.delete
update!(deleted_at: Time.zone.now) if respond_to?(:deleted_at)
reload_from_stripe!
true
end
|
#destroy_on_stripe! ⇒ Object
57
58
59
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 57
def destroy_on_stripe!
raise ActiveRecord::RecordInvalid, self unless destroy_on_stripe
end
|
#reload!(*args, &blk) ⇒ Object
31
32
33
34
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 31
def reload!(*args, &blk)
@to_stripe = nil
super
end
|
#reload_from_stripe! ⇒ Object
26
27
28
29
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 26
def reload_from_stripe!
assign_from_stripe(to_stripe)
save!
end
|
#to_stripe ⇒ Object
22
23
24
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 22
def to_stripe
@to_stripe ||= self.class.stripe_class.retrieve(stripe_id)
end
|
#update_on_stripe(attributes) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 36
def update_on_stripe(attributes)
attributes.each do |key, value|
to_stripe.__send__("#{key}=", value)
end
to_stripe.save
reload_from_stripe!
true
end
|
#update_on_stripe!(attributes) ⇒ Object
46
47
48
|
# File 'app/models/stripe_model_callbacks/application_record.rb', line 46
def update_on_stripe!(attributes)
raise ActiveRecord::RecordInvalid, self unless update_on_stripe(attributes)
end
|