stripe_model_callbacks 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +153 -0
- data/Rakefile +26 -0
- data/app/assets/config/stripe_model_callbacks_manifest.js +2 -0
- data/app/assets/javascripts/stripe_model_callbacks/application.js +13 -0
- data/app/assets/stylesheets/stripe_model_callbacks/application.css +15 -0
- data/app/controllers/stripe_model_callbacks/application_controller.rb +3 -0
- data/app/jobs/stripe_model_callbacks/application_job.rb +2 -0
- data/app/mailers/stripe_model_callbacks/application_mailer.rb +4 -0
- data/app/models/stripe_model_callbacks/application_record.rb +60 -0
- data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +13 -0
- data/app/services/stripe_model_callbacks/attributes_assigner_service.rb +35 -0
- data/app/services/stripe_model_callbacks/base_event_service.rb +9 -0
- data/app/services/stripe_model_callbacks/base_service.rb +26 -0
- data/app/services/stripe_model_callbacks/charge/dispute_updated_service.rb +29 -0
- data/app/services/stripe_model_callbacks/charge/updated_service.rb +40 -0
- data/app/services/stripe_model_callbacks/configure_service.rb +217 -0
- data/app/services/stripe_model_callbacks/coupon/updated_service.rb +18 -0
- data/app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb +13 -0
- data/app/services/stripe_model_callbacks/customer/deleted_service.rb +13 -0
- data/app/services/stripe_model_callbacks/customer/discount_updated_service.rb +32 -0
- data/app/services/stripe_model_callbacks/customer/source_updated_service.rb +25 -0
- data/app/services/stripe_model_callbacks/customer/subscription/updated_service.rb +28 -0
- data/app/services/stripe_model_callbacks/customer/updated_service.rb +13 -0
- data/app/services/stripe_model_callbacks/event_mocker_service.rb +38 -0
- data/app/services/stripe_model_callbacks/invoice/updated_service.rb +26 -0
- data/app/services/stripe_model_callbacks/invoice_item/updated_service.rb +13 -0
- data/app/services/stripe_model_callbacks/notifier_service.rb +6 -0
- data/app/services/stripe_model_callbacks/order/updated_service.rb +28 -0
- data/app/services/stripe_model_callbacks/payout/updated_service.rb +29 -0
- data/app/services/stripe_model_callbacks/plan/updated_service.rb +14 -0
- data/app/services/stripe_model_callbacks/product/updated_service.rb +14 -0
- data/app/services/stripe_model_callbacks/recipient/updated_service.rb +14 -0
- data/app/services/stripe_model_callbacks/refund/updated_service.rb +12 -0
- data/app/services/stripe_model_callbacks/review/updated_service.rb +13 -0
- data/app/services/stripe_model_callbacks/sku/updated_service.rb +14 -0
- data/app/services/stripe_model_callbacks/source/updated_service.rb +31 -0
- data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +21 -0
- data/app/services/stripe_model_callbacks/transfer/updated_service.rb +18 -0
- data/app/views/layouts/stripe_model_callbacks/application.html.erb +14 -0
- data/config/rails_best_practices.yml +49 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20180206115801_create_stripe_charges.rb +54 -0
- data/db/migrate/20180206115802_create_stripe_coupons.rb +22 -0
- data/db/migrate/20180206115803_create_stripe_customers.rb +21 -0
- data/db/migrate/20180206115804_create_stripe_discounts.rb +27 -0
- data/db/migrate/20180206115805_create_stripe_invoice_items.rb +26 -0
- data/db/migrate/20180206115806_create_stripe_invoices.rb +57 -0
- data/db/migrate/20180206115807_create_stripe_order_items.rb +15 -0
- data/db/migrate/20180206115808_create_stripe_orders.rb +46 -0
- data/db/migrate/20180206115809_create_stripe_payouts.rb +27 -0
- data/db/migrate/20180206115810_create_stripe_plans.rb +20 -0
- data/db/migrate/20180206115811_create_stripe_products.rb +25 -0
- data/db/migrate/20180206115812_create_stripe_recipients.rb +18 -0
- data/db/migrate/20180206115813_create_stripe_refunds.rb +21 -0
- data/db/migrate/20180206115814_create_stripe_skus.rb +22 -0
- data/db/migrate/20180206115815_create_stripe_sources.rb +70 -0
- data/db/migrate/20180206115816_create_stripe_subscriptions.rb +29 -0
- data/db/migrate/20180206115817_create_stripe_transfers.rb +25 -0
- data/db/migrate/20180206130408_create_disputes.rb +76 -0
- data/db/migrate/20180206151132_change_activities_trackable_id_to_string.rb +5 -0
- data/db/migrate/20180207121808_create_stripe_subscription_items.rb +14 -0
- data/db/migrate/20180207171559_remove_name_from_stripe_plans.rb +5 -0
- data/db/migrate/20180207172011_add_stripe_product_id_to_stripe_plans.rb +6 -0
- data/db/migrate/20180207185604_add_index_on_refund_charge.rb +5 -0
- data/db/migrate/20180208091647_change_stripe_subscription_items_quantity_to_integer.rb +5 -0
- data/db/migrate/20180208102513_add_attempt_count_to_stripe_invoices.rb +7 -0
- data/db/migrate/20180208121235_create_stripe_reviews.rb +13 -0
- data/db/migrate/20180208122654_create_stripe_bank_accounts.rb +20 -0
- data/db/migrate/20180208160046_add_nickname_to_stripe_plans.rb +5 -0
- data/db/migrate/20180211092437_rename_stripe_invoice_items_subscription_item.rb +6 -0
- data/db/migrate/20180216224335_rename_stripe_subscriptions_discount.rb +5 -0
- data/db/migrate/20180217200350_change_stripe_invoices_to_reference_discounts.rb +9 -0
- data/db/migrate/20180217204628_create_stripe_cards.rb +29 -0
- data/db/migrate/20180218092600_add_deleted_at_to_stripe_cards.rb +9 -0
- data/db/migrate/20181219121712_add_new_primary_id_and_rename_old.rb +37 -0
- data/db/migrate/20190629112050_rename_stripe_invoice_date_to_created.rb +5 -0
- data/lib/stripe_model_callbacks.rb +19 -0
- data/lib/stripe_model_callbacks/autoload_models.rb +8 -0
- data/lib/stripe_model_callbacks/configuration.rb +23 -0
- data/lib/stripe_model_callbacks/engine.rb +5 -0
- data/lib/stripe_model_callbacks/event_mocker.rb +5 -0
- data/lib/stripe_model_callbacks/factory_bot_definitions.rb +7 -0
- data/lib/stripe_model_callbacks/models/stripe_bank_account.rb +17 -0
- data/lib/stripe_model_callbacks/models/stripe_card.rb +25 -0
- data/lib/stripe_model_callbacks/models/stripe_charge.rb +47 -0
- data/lib/stripe_model_callbacks/models/stripe_coupon.rb +24 -0
- data/lib/stripe_model_callbacks/models/stripe_customer.rb +23 -0
- data/lib/stripe_model_callbacks/models/stripe_discount.rb +53 -0
- data/lib/stripe_model_callbacks/models/stripe_dispute.rb +86 -0
- data/lib/stripe_model_callbacks/models/stripe_invoice.rb +88 -0
- data/lib/stripe_model_callbacks/models/stripe_invoice_item.rb +33 -0
- data/lib/stripe_model_callbacks/models/stripe_order.rb +63 -0
- data/lib/stripe_model_callbacks/models/stripe_order_item.rb +20 -0
- data/lib/stripe_model_callbacks/models/stripe_payout.rb +26 -0
- data/lib/stripe_model_callbacks/models/stripe_plan.rb +32 -0
- data/lib/stripe_model_callbacks/models/stripe_product.rb +27 -0
- data/lib/stripe_model_callbacks/models/stripe_recipient.rb +16 -0
- data/lib/stripe_model_callbacks/models/stripe_refund.rb +28 -0
- data/lib/stripe_model_callbacks/models/stripe_review.rb +18 -0
- data/lib/stripe_model_callbacks/models/stripe_sku.rb +28 -0
- data/lib/stripe_model_callbacks/models/stripe_source.rb +79 -0
- data/lib/stripe_model_callbacks/models/stripe_subscription.rb +101 -0
- data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +36 -0
- data/lib/stripe_model_callbacks/models/stripe_transfer.rb +25 -0
- data/lib/stripe_model_callbacks/require_models.rb +7 -0
- data/lib/stripe_model_callbacks/version.rb +3 -0
- data/lib/tasks/stripe_model_callbacks_tasks.rake +4 -0
- metadata +249 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
class StripeProduct < StripeModelCallbacks::ApplicationRecord
|
2
|
+
has_many :stripe_plans, primary_key: "stripe_id"
|
3
|
+
|
4
|
+
def self.stripe_class
|
5
|
+
Stripe::Subscription
|
6
|
+
end
|
7
|
+
|
8
|
+
def assign_from_stripe(object)
|
9
|
+
assign_attributes(
|
10
|
+
active: object.active == true,
|
11
|
+
updated: Time.zone.at(object.updated),
|
12
|
+
stripe_attributes: JSON.generate(object.attributes),
|
13
|
+
package_dimensions_height: object.package_dimensions&.height,
|
14
|
+
package_dimensions_length: object.package_dimensions&.length,
|
15
|
+
package_dimensions_weight: object.package_dimensions&.weight,
|
16
|
+
package_dimensions_width: object.package_dimensions&.width,
|
17
|
+
shippable: object.shippable == true
|
18
|
+
)
|
19
|
+
|
20
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
21
|
+
model: self, stripe_model: object,
|
22
|
+
attributes: %w[
|
23
|
+
caption created description id livemode name metadata statement_descriptor
|
24
|
+
]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class StripeRecipient < StripeModelCallbacks::ApplicationRecord
|
2
|
+
def self.stripe_class
|
3
|
+
Stripe::Recipient
|
4
|
+
end
|
5
|
+
|
6
|
+
def assign_from_stripe(object)
|
7
|
+
assign_attributes(
|
8
|
+
stripe_type: object.type
|
9
|
+
)
|
10
|
+
|
11
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
12
|
+
model: self, stripe_model: object,
|
13
|
+
attributes: %w[active_account description email name migrated_to verified]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class StripeRefund < StripeModelCallbacks::ApplicationRecord
|
2
|
+
belongs_to :stripe_charge, optional: true, primary_key: "stripe_id"
|
3
|
+
|
4
|
+
monetize :amount_cents, allow_nil: true
|
5
|
+
|
6
|
+
def self.stripe_class
|
7
|
+
Stripe::Refund
|
8
|
+
end
|
9
|
+
|
10
|
+
def assign_from_stripe(object)
|
11
|
+
assign_attributes(
|
12
|
+
amount: Money.new(object.amount, object.currency),
|
13
|
+
stripe_charge_id: object.charge,
|
14
|
+
created: Time.zone.at(object.created),
|
15
|
+
livemode: object.try(:livemode) == true,
|
16
|
+
metadata: JSON.generate(object.metadata)
|
17
|
+
)
|
18
|
+
|
19
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
20
|
+
model: self,
|
21
|
+
stripe_model: object,
|
22
|
+
attributes: %w[balance_transaction currency reason receipt_number status]
|
23
|
+
)
|
24
|
+
|
25
|
+
self.failure_reason = object.failure_reason if object.respond_to?(:failure_reason)
|
26
|
+
self.failure_balance_transaction = object.failure_balance_transaction if object.respond_to?(:failure_balance_transaction)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class StripeReview < StripeModelCallbacks::ApplicationRecord
|
2
|
+
belongs_to :stripe_charge, optional: true, primary_key: "stripe_id"
|
3
|
+
|
4
|
+
def self.stripe_class
|
5
|
+
Stripe::Review
|
6
|
+
end
|
7
|
+
|
8
|
+
def assign_from_stripe(object)
|
9
|
+
assign_attributes(
|
10
|
+
stripe_charge_id: object.charge
|
11
|
+
)
|
12
|
+
|
13
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
14
|
+
model: self, stripe_model: object,
|
15
|
+
attributes: %w[id created livemode open reason]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class StripeSku < StripeModelCallbacks::ApplicationRecord
|
2
|
+
monetize :price_cents
|
3
|
+
|
4
|
+
def self.stripe_class
|
5
|
+
Stripe::Sku
|
6
|
+
end
|
7
|
+
|
8
|
+
def assign_from_stripe(object)
|
9
|
+
assign_attributes(
|
10
|
+
active: object.active == true,
|
11
|
+
created: Time.zone.at(object.created),
|
12
|
+
updated: Time.zone.at(object.updated),
|
13
|
+
stripe_attributes: JSON.generate(object.attributes),
|
14
|
+
inventory_quantity: object.inventory.quantity,
|
15
|
+
inventory_type: object.inventory.type,
|
16
|
+
inventory_value: object.inventory.value,
|
17
|
+
livemode: object.livemode,
|
18
|
+
metadata: JSON.generate(object.metadata),
|
19
|
+
price: Money.new(object.price, object.currency),
|
20
|
+
stripe_product_id: object.product
|
21
|
+
)
|
22
|
+
|
23
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
24
|
+
model: self, stripe_model: object,
|
25
|
+
attributes: %w[currency]
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class StripeSource < StripeModelCallbacks::ApplicationRecord
|
2
|
+
monetize :amount_cents, allow_nil: true
|
3
|
+
monetize :receiver_amount_charged_cents, allow_nil: true
|
4
|
+
monetize :receiver_amount_received_cents, allow_nil: true
|
5
|
+
monetize :receiver_amount_returned_cents, allow_nil: true
|
6
|
+
|
7
|
+
def self.stripe_class
|
8
|
+
Stripe::Source
|
9
|
+
end
|
10
|
+
|
11
|
+
def assign_from_stripe(object)
|
12
|
+
self.stripe_type = object.type
|
13
|
+
self.amount = Money.new(object.amount, object.currency) if object.respond_to?(:amount)
|
14
|
+
|
15
|
+
assign_owner(object)
|
16
|
+
assign_owner_verified(object)
|
17
|
+
assign_receiver(object)
|
18
|
+
assign_ach_credit_transfer(object)
|
19
|
+
|
20
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
21
|
+
model: self, stripe_model: object,
|
22
|
+
attributes: %w[
|
23
|
+
client_secret created currency flow livemode metadata statement_descriptor
|
24
|
+
status usage
|
25
|
+
]
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def assign_owner(object)
|
32
|
+
assign_attributes(
|
33
|
+
owner_address_city: object.owner.address&.city,
|
34
|
+
owner_address_country: object.owner.address&.country,
|
35
|
+
owner_address_line1: object.owner.address&.line1,
|
36
|
+
owner_address_line2: object.owner.address&.line2,
|
37
|
+
owner_address_postal_code: object.owner.address&.postal_code,
|
38
|
+
owner_address_state: object.owner.address&.state,
|
39
|
+
owner_email: object.owner.email,
|
40
|
+
owner_name: object.owner.name,
|
41
|
+
owner_phone: object.owner.phone
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def assign_owner_verified(object)
|
46
|
+
assign_attributes(
|
47
|
+
owner_verified_address_city: object.owner.verified_address&.city,
|
48
|
+
owner_verified_address_country: object.owner.verified_address&.country,
|
49
|
+
owner_verified_address_line1: object.owner.verified_address&.line1,
|
50
|
+
owner_verified_address_line2: object.owner.verified_address&.line2,
|
51
|
+
owner_verified_address_postal_code: object.owner.verified_address&.postal_code,
|
52
|
+
owner_verified_address_state: object.owner.verified_address&.state,
|
53
|
+
owner_verified_email: object.owner.verified_email,
|
54
|
+
owner_verified_name: object.owner.verified_name,
|
55
|
+
owner_verified_phone: object.owner.verified_phone
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def assign_receiver(object)
|
60
|
+
assign_attributes(
|
61
|
+
receiver_address: object.receiver.address,
|
62
|
+
receiver_amount_charged: Money.new(object.receiver.amount_charged, object.currency),
|
63
|
+
receiver_amount_received: Money.new(object.receiver.amount_received, object.currency),
|
64
|
+
receiver_amount_returned: Money.new(object.receiver.amount_returned, object.currency),
|
65
|
+
receiver_refund_attributes_method: object.receiver.refund_attributes_method,
|
66
|
+
receiver_refund_attributes_status: object.receiver.refund_attributes_status
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
def assign_ach_credit_transfer(object)
|
71
|
+
assign_attributes(
|
72
|
+
ach_credit_transfer_account_number: object.ach_credit_transfer.account_number,
|
73
|
+
ach_credit_transfer_routing_number: object.ach_credit_transfer.routing_number,
|
74
|
+
ach_credit_transfer_fingerprint: object.ach_credit_transfer.fingerprint,
|
75
|
+
ach_credit_transfer_bank_name: object.ach_credit_transfer.bank_name,
|
76
|
+
ach_credit_transfer_swift_code: object.ach_credit_transfer.swift_code
|
77
|
+
)
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class StripeSubscription < StripeModelCallbacks::ApplicationRecord
|
2
|
+
belongs_to :stripe_customer, optional: true, primary_key: "stripe_id"
|
3
|
+
belongs_to :stripe_discount, optional: true
|
4
|
+
belongs_to :stripe_plan, optional: true, primary_key: "stripe_id"
|
5
|
+
has_many :stripe_invoices, primary_key: "stripe_id"
|
6
|
+
has_many :stripe_discounts, primary_key: "stripe_id"
|
7
|
+
has_many :stripe_subscription_items, autosave: true, primary_key: "stripe_id"
|
8
|
+
|
9
|
+
STATES = %w[trialing active past_due canceled unpaid].freeze
|
10
|
+
|
11
|
+
scope :with_state, lambda { |states|
|
12
|
+
StripeModelCallbacks::Subscription::StateCheckerService.execute!(allowed: STATES, state: states)
|
13
|
+
where(status: states)
|
14
|
+
}
|
15
|
+
|
16
|
+
def self.stripe_class
|
17
|
+
Stripe::Subscription
|
18
|
+
end
|
19
|
+
|
20
|
+
def assign_from_stripe(object)
|
21
|
+
assign_attributes(
|
22
|
+
canceled_at: object.canceled_at ? Time.zone.at(object.canceled_at) : nil,
|
23
|
+
stripe_customer_id: object.customer,
|
24
|
+
ended_at: object.ended_at ? Time.zone.at(object.ended_at) : nil,
|
25
|
+
stripe_plan_id: object.plan&.id
|
26
|
+
)
|
27
|
+
|
28
|
+
assign_discount(object)
|
29
|
+
assign_items(object)
|
30
|
+
assign_periods(object)
|
31
|
+
|
32
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
33
|
+
model: self, stripe_model: object,
|
34
|
+
attributes: %w[billing cancel_at_period_end created id livemode status tax_percent]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def reactivate!
|
39
|
+
raise "Cannot reactivate unless cancel at period end has been set" unless cancel_at_period_end?
|
40
|
+
|
41
|
+
# https://stripe.com/docs/subscriptions/canceling-pausing
|
42
|
+
items = []
|
43
|
+
stripe_subscription_items.each do |item|
|
44
|
+
items << {
|
45
|
+
id: item.stripe_id,
|
46
|
+
plan: item.stripe_plan_id,
|
47
|
+
quantity: item.quantity
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
to_stripe.items = items
|
52
|
+
to_stripe.save
|
53
|
+
|
54
|
+
reload_from_stripe!
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def cancel!(args = {})
|
59
|
+
to_stripe.delete(args)
|
60
|
+
reload_from_stripe!
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def assign_discount(object)
|
67
|
+
return if object.discount.blank?
|
68
|
+
|
69
|
+
discount = stripe_discount || build_stripe_discount
|
70
|
+
discount.assign_from_stripe(object.discount)
|
71
|
+
end
|
72
|
+
|
73
|
+
def assign_items(object)
|
74
|
+
object.items.each do |item|
|
75
|
+
sub_item = find_item_by_stripe_item(item) if persisted?
|
76
|
+
sub_item ||= stripe_subscription_items.build
|
77
|
+
sub_item.assign_from_stripe(item)
|
78
|
+
sub_item.save! if persisted?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def assign_periods(object)
|
83
|
+
assign_attributes(
|
84
|
+
current_period_start: Time.zone.at(object.current_period_start),
|
85
|
+
current_period_end: Time.zone.at(object.current_period_end),
|
86
|
+
start: Time.zone.at(object.start),
|
87
|
+
trial_start: object.trial_start ? Time.zone.at(object.trial_start) : nil,
|
88
|
+
trial_end: object.trial_end ? Time.zone.at(object.trial_end) : nil
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def find_item_by_stripe_item(item)
|
93
|
+
stripe_subscription_items.find do |sub_item|
|
94
|
+
if item.plan.is_a?(String)
|
95
|
+
sub_item.stripe_plan_id == item.plan
|
96
|
+
else
|
97
|
+
sub_item.stripe_plan_id == item.plan.id
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class StripeSubscriptionItem < StripeModelCallbacks::ApplicationRecord
|
2
|
+
belongs_to :stripe_plan, optional: true, primary_key: "stripe_id"
|
3
|
+
belongs_to :stripe_subscription, optional: true, primary_key: "stripe_id"
|
4
|
+
|
5
|
+
has_many :stripe_invoice_items, primary_key: "stripe_id"
|
6
|
+
|
7
|
+
def self.stripe_class
|
8
|
+
Stripe::SubscriptionItem
|
9
|
+
end
|
10
|
+
|
11
|
+
def assign_from_stripe(object)
|
12
|
+
self.stripe_subscription_id = object.subscription if object.respond_to?(:subscription)
|
13
|
+
self.stripe_plan_id = object.plan.id if object.plan.respond_to?(:id)
|
14
|
+
|
15
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
16
|
+
model: self, stripe_model: object,
|
17
|
+
attributes: %w[id created metadata quantity]
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_quantity_on_stripe!(new_quantity)
|
22
|
+
sub_object = stripe_subscription.to_stripe
|
23
|
+
|
24
|
+
new_items = [{
|
25
|
+
id: id,
|
26
|
+
plan: stripe_plan_id,
|
27
|
+
quantity: new_quantity
|
28
|
+
}]
|
29
|
+
|
30
|
+
sub_object.items = new_items
|
31
|
+
sub_object.save
|
32
|
+
|
33
|
+
stripe_subscription.reload_from_stripe!
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class StripeTransfer < StripeModelCallbacks::ApplicationRecord
|
2
|
+
monetize :amount_cents
|
3
|
+
monetize :amount_reversed_cents
|
4
|
+
|
5
|
+
def self.stripe_class
|
6
|
+
Stripe::Transfer
|
7
|
+
end
|
8
|
+
|
9
|
+
def assign_from_stripe(object)
|
10
|
+
assign_attributes(
|
11
|
+
amount: Money.new(object.amount, object.currency),
|
12
|
+
amount_reversed: Money.new(object.amount_reversed, object.currency),
|
13
|
+
created: Time.zone.at(object.created),
|
14
|
+
metadata: JSON.generate(object.metadata)
|
15
|
+
)
|
16
|
+
|
17
|
+
StripeModelCallbacks::AttributesAssignerService.execute!(
|
18
|
+
model: self, stripe_model: object,
|
19
|
+
attributes: %w[
|
20
|
+
balance_transaction currency description destination destination_payment livemode reversed
|
21
|
+
source_transaction source_type transfer_group status
|
22
|
+
]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stripe_model_callbacks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kaspernj
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: money-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: public_activity
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: service_pattern
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: stripe
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: stripe-ruby-mock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: stripe_event
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.0.4
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.0.4
|
111
|
+
description: Framework for getting Stripe webhook callbacks directly to your models
|
112
|
+
email:
|
113
|
+
- kaspernj@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- MIT-LICENSE
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- app/assets/config/stripe_model_callbacks_manifest.js
|
122
|
+
- app/assets/javascripts/stripe_model_callbacks/application.js
|
123
|
+
- app/assets/stylesheets/stripe_model_callbacks/application.css
|
124
|
+
- app/controllers/stripe_model_callbacks/application_controller.rb
|
125
|
+
- app/jobs/stripe_model_callbacks/application_job.rb
|
126
|
+
- app/mailers/stripe_model_callbacks/application_mailer.rb
|
127
|
+
- app/models/stripe_model_callbacks/application_record.rb
|
128
|
+
- app/services/stripe_model_callbacks/account/external_account/updated_service.rb
|
129
|
+
- app/services/stripe_model_callbacks/attributes_assigner_service.rb
|
130
|
+
- app/services/stripe_model_callbacks/base_event_service.rb
|
131
|
+
- app/services/stripe_model_callbacks/base_service.rb
|
132
|
+
- app/services/stripe_model_callbacks/charge/dispute_updated_service.rb
|
133
|
+
- app/services/stripe_model_callbacks/charge/updated_service.rb
|
134
|
+
- app/services/stripe_model_callbacks/configure_service.rb
|
135
|
+
- app/services/stripe_model_callbacks/coupon/updated_service.rb
|
136
|
+
- app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb
|
137
|
+
- app/services/stripe_model_callbacks/customer/deleted_service.rb
|
138
|
+
- app/services/stripe_model_callbacks/customer/discount_updated_service.rb
|
139
|
+
- app/services/stripe_model_callbacks/customer/source_updated_service.rb
|
140
|
+
- app/services/stripe_model_callbacks/customer/subscription/updated_service.rb
|
141
|
+
- app/services/stripe_model_callbacks/customer/updated_service.rb
|
142
|
+
- app/services/stripe_model_callbacks/event_mocker_service.rb
|
143
|
+
- app/services/stripe_model_callbacks/invoice/updated_service.rb
|
144
|
+
- app/services/stripe_model_callbacks/invoice_item/updated_service.rb
|
145
|
+
- app/services/stripe_model_callbacks/notifier_service.rb
|
146
|
+
- app/services/stripe_model_callbacks/order/updated_service.rb
|
147
|
+
- app/services/stripe_model_callbacks/payout/updated_service.rb
|
148
|
+
- app/services/stripe_model_callbacks/plan/updated_service.rb
|
149
|
+
- app/services/stripe_model_callbacks/product/updated_service.rb
|
150
|
+
- app/services/stripe_model_callbacks/recipient/updated_service.rb
|
151
|
+
- app/services/stripe_model_callbacks/refund/updated_service.rb
|
152
|
+
- app/services/stripe_model_callbacks/review/updated_service.rb
|
153
|
+
- app/services/stripe_model_callbacks/sku/updated_service.rb
|
154
|
+
- app/services/stripe_model_callbacks/source/updated_service.rb
|
155
|
+
- app/services/stripe_model_callbacks/subscription/state_checker_service.rb
|
156
|
+
- app/services/stripe_model_callbacks/transfer/updated_service.rb
|
157
|
+
- app/views/layouts/stripe_model_callbacks/application.html.erb
|
158
|
+
- config/rails_best_practices.yml
|
159
|
+
- config/routes.rb
|
160
|
+
- db/migrate/20180206115801_create_stripe_charges.rb
|
161
|
+
- db/migrate/20180206115802_create_stripe_coupons.rb
|
162
|
+
- db/migrate/20180206115803_create_stripe_customers.rb
|
163
|
+
- db/migrate/20180206115804_create_stripe_discounts.rb
|
164
|
+
- db/migrate/20180206115805_create_stripe_invoice_items.rb
|
165
|
+
- db/migrate/20180206115806_create_stripe_invoices.rb
|
166
|
+
- db/migrate/20180206115807_create_stripe_order_items.rb
|
167
|
+
- db/migrate/20180206115808_create_stripe_orders.rb
|
168
|
+
- db/migrate/20180206115809_create_stripe_payouts.rb
|
169
|
+
- db/migrate/20180206115810_create_stripe_plans.rb
|
170
|
+
- db/migrate/20180206115811_create_stripe_products.rb
|
171
|
+
- db/migrate/20180206115812_create_stripe_recipients.rb
|
172
|
+
- db/migrate/20180206115813_create_stripe_refunds.rb
|
173
|
+
- db/migrate/20180206115814_create_stripe_skus.rb
|
174
|
+
- db/migrate/20180206115815_create_stripe_sources.rb
|
175
|
+
- db/migrate/20180206115816_create_stripe_subscriptions.rb
|
176
|
+
- db/migrate/20180206115817_create_stripe_transfers.rb
|
177
|
+
- db/migrate/20180206130408_create_disputes.rb
|
178
|
+
- db/migrate/20180206151132_change_activities_trackable_id_to_string.rb
|
179
|
+
- db/migrate/20180207121808_create_stripe_subscription_items.rb
|
180
|
+
- db/migrate/20180207171559_remove_name_from_stripe_plans.rb
|
181
|
+
- db/migrate/20180207172011_add_stripe_product_id_to_stripe_plans.rb
|
182
|
+
- db/migrate/20180207185604_add_index_on_refund_charge.rb
|
183
|
+
- db/migrate/20180208091647_change_stripe_subscription_items_quantity_to_integer.rb
|
184
|
+
- db/migrate/20180208102513_add_attempt_count_to_stripe_invoices.rb
|
185
|
+
- db/migrate/20180208121235_create_stripe_reviews.rb
|
186
|
+
- db/migrate/20180208122654_create_stripe_bank_accounts.rb
|
187
|
+
- db/migrate/20180208160046_add_nickname_to_stripe_plans.rb
|
188
|
+
- db/migrate/20180211092437_rename_stripe_invoice_items_subscription_item.rb
|
189
|
+
- db/migrate/20180216224335_rename_stripe_subscriptions_discount.rb
|
190
|
+
- db/migrate/20180217200350_change_stripe_invoices_to_reference_discounts.rb
|
191
|
+
- db/migrate/20180217204628_create_stripe_cards.rb
|
192
|
+
- db/migrate/20180218092600_add_deleted_at_to_stripe_cards.rb
|
193
|
+
- db/migrate/20181219121712_add_new_primary_id_and_rename_old.rb
|
194
|
+
- db/migrate/20190629112050_rename_stripe_invoice_date_to_created.rb
|
195
|
+
- lib/stripe_model_callbacks.rb
|
196
|
+
- lib/stripe_model_callbacks/autoload_models.rb
|
197
|
+
- lib/stripe_model_callbacks/configuration.rb
|
198
|
+
- lib/stripe_model_callbacks/engine.rb
|
199
|
+
- lib/stripe_model_callbacks/event_mocker.rb
|
200
|
+
- lib/stripe_model_callbacks/factory_bot_definitions.rb
|
201
|
+
- lib/stripe_model_callbacks/models/stripe_bank_account.rb
|
202
|
+
- lib/stripe_model_callbacks/models/stripe_card.rb
|
203
|
+
- lib/stripe_model_callbacks/models/stripe_charge.rb
|
204
|
+
- lib/stripe_model_callbacks/models/stripe_coupon.rb
|
205
|
+
- lib/stripe_model_callbacks/models/stripe_customer.rb
|
206
|
+
- lib/stripe_model_callbacks/models/stripe_discount.rb
|
207
|
+
- lib/stripe_model_callbacks/models/stripe_dispute.rb
|
208
|
+
- lib/stripe_model_callbacks/models/stripe_invoice.rb
|
209
|
+
- lib/stripe_model_callbacks/models/stripe_invoice_item.rb
|
210
|
+
- lib/stripe_model_callbacks/models/stripe_order.rb
|
211
|
+
- lib/stripe_model_callbacks/models/stripe_order_item.rb
|
212
|
+
- lib/stripe_model_callbacks/models/stripe_payout.rb
|
213
|
+
- lib/stripe_model_callbacks/models/stripe_plan.rb
|
214
|
+
- lib/stripe_model_callbacks/models/stripe_product.rb
|
215
|
+
- lib/stripe_model_callbacks/models/stripe_recipient.rb
|
216
|
+
- lib/stripe_model_callbacks/models/stripe_refund.rb
|
217
|
+
- lib/stripe_model_callbacks/models/stripe_review.rb
|
218
|
+
- lib/stripe_model_callbacks/models/stripe_sku.rb
|
219
|
+
- lib/stripe_model_callbacks/models/stripe_source.rb
|
220
|
+
- lib/stripe_model_callbacks/models/stripe_subscription.rb
|
221
|
+
- lib/stripe_model_callbacks/models/stripe_subscription_item.rb
|
222
|
+
- lib/stripe_model_callbacks/models/stripe_transfer.rb
|
223
|
+
- lib/stripe_model_callbacks/require_models.rb
|
224
|
+
- lib/stripe_model_callbacks/version.rb
|
225
|
+
- lib/tasks/stripe_model_callbacks_tasks.rake
|
226
|
+
homepage: https://github.com/kaspernj/stripe_model_callbacks
|
227
|
+
licenses:
|
228
|
+
- MIT
|
229
|
+
metadata: {}
|
230
|
+
post_install_message:
|
231
|
+
rdoc_options: []
|
232
|
+
require_paths:
|
233
|
+
- lib
|
234
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
235
|
+
requirements:
|
236
|
+
- - ">="
|
237
|
+
- !ruby/object:Gem::Version
|
238
|
+
version: '0'
|
239
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
requirements: []
|
245
|
+
rubygems_version: 3.0.6
|
246
|
+
signing_key:
|
247
|
+
specification_version: 4
|
248
|
+
summary: Framework for getting Stripe webhook callbacks directly to your models
|
249
|
+
test_files: []
|