stripe_model_callbacks 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/app/models/stripe_model_callbacks/application_record.rb +28 -14
- data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/attributes_assigner_service.rb +154 -8
- data/app/services/stripe_model_callbacks/base_service.rb +9 -6
- data/app/services/stripe_model_callbacks/charge/dispute_updated_service.rb +3 -3
- data/app/services/stripe_model_callbacks/charge/updated_service.rb +5 -5
- data/app/services/stripe_model_callbacks/configure_service.rb +58 -27
- data/app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb +1 -1
- data/app/services/stripe_model_callbacks/customer/discount_updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/customer/source_updated_service.rb +3 -3
- data/app/services/stripe_model_callbacks/customer/subscription/updated_service.rb +2 -2
- data/app/services/stripe_model_callbacks/customer/updated_service.rb +2 -2
- data/app/services/stripe_model_callbacks/event_mocker_service.rb +14 -8
- data/app/services/stripe_model_callbacks/invoice/updated_service.rb +4 -4
- data/app/services/stripe_model_callbacks/payment_intent/updated_service.rb +19 -0
- data/app/services/stripe_model_callbacks/payment_method/updated_service.rb +19 -0
- data/app/services/stripe_model_callbacks/payout/updated_service.rb +3 -3
- data/app/services/stripe_model_callbacks/plan/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/price/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/product/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/recipient/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/review/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/setup_intent/updated_service.rb +8 -0
- data/app/services/stripe_model_callbacks/sku/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/source/transaction_created_service.rb +17 -0
- data/app/services/stripe_model_callbacks/source/updated_service.rb +4 -4
- data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +1 -1
- data/app/services/stripe_model_callbacks/subscription_schedule/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/sync_everything.rb +17 -2
- data/app/services/stripe_model_callbacks/sync_from_stripe.rb +1 -1
- data/app/services/stripe_model_callbacks/tax_rate/updated_service.rb +3 -3
- data/app/services/stripe_model_callbacks/transfer/updated_service.rb +1 -1
- data/config/rails_best_practices.yml +1 -0
- data/db/migrate/20180206151132_change_activities_trackable_id_to_string.rb +1 -1
- data/db/migrate/20180208091647_change_stripe_subscription_items_quantity_to_integer.rb +1 -1
- data/db/migrate/20181219121712_add_new_primary_id_and_rename_old.rb +2 -2
- data/db/migrate/20230210081405_create_stripe_setup_intents.rb +28 -0
- data/db/migrate/20230331182902_add_amount_captured_to_stripe_charges.rb +6 -0
- data/db/migrate/20230420092307_create_stripe_payment_methods.rb +15 -0
- data/db/migrate/20230421072509_create_stripe_payment_intents.rb +44 -0
- data/db/migrate/20230422074329_add_payment_intent_to_stripe_charges.rb +6 -0
- data/db/migrate/20230422175529_add_payment_intent_to_stripe_refunds.rb +6 -0
- data/db/migrate/20230422180602_change_stripe_refunds_stripe_charge_id_to_nullable.rb +5 -0
- data/db/migrate/20230518072538_change_stripe_setup_intents_payment_method_to_string.rb +7 -0
- data/lib/stripe_model_callbacks/configuration.rb +1 -1
- data/lib/stripe_model_callbacks/event_mocker.rb +1 -1
- data/lib/stripe_model_callbacks/factories/stripe_charges.rb +10 -0
- data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +10 -9
- data/lib/stripe_model_callbacks/factories/stripe_customers.rb +6 -4
- data/lib/stripe_model_callbacks/factories/stripe_invoice_items.rb +1 -0
- data/lib/stripe_model_callbacks/factories/stripe_invoices.rb +1 -0
- data/lib/stripe_model_callbacks/factories/stripe_payment_intents.rb +17 -0
- data/lib/stripe_model_callbacks/factories/stripe_payment_methods.rb +15 -0
- data/lib/stripe_model_callbacks/factories/stripe_plans.rb +9 -12
- data/lib/stripe_model_callbacks/factories/stripe_products.rb +9 -8
- data/lib/stripe_model_callbacks/factories/stripe_recipients.rb +2 -0
- data/lib/stripe_model_callbacks/factories/stripe_reviews.rb +2 -0
- data/lib/stripe_model_callbacks/factories/stripe_setup_intents.rb +7 -0
- data/lib/stripe_model_callbacks/factories/stripe_skus.rb +1 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_items.rb +7 -7
- data/lib/stripe_model_callbacks/factories/stripe_subscriptions.rb +10 -12
- data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +10 -0
- data/lib/stripe_model_callbacks/factories/stripe_transfers.rb +2 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refunded.json +1 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +0 -1
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.amount_capturable_updated.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.canceled.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.created.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.partially_funded.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.payment_failed.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.processing.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.requires_action.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_intent/payment_intent.succeeded.json +66 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.attached.json +63 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.automatically_updated.json +63 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.card_automatically_updated.json +63 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.detached.json +63 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payment_method/payment_method.updated.json +63 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/setup_intent/setup_intent.created.json +47 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/setup_intent/setup_intent.updated.json +47 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/source/{source.transaction_created.json → source.transaction.created.json} +2 -1
- data/lib/stripe_model_callbacks/models/stripe_charge.rb +51 -4
- data/lib/stripe_model_callbacks/models/stripe_coupon.rb +12 -0
- data/lib/stripe_model_callbacks/models/stripe_customer.rb +12 -0
- data/lib/stripe_model_callbacks/models/stripe_invoice.rb +17 -1
- data/lib/stripe_model_callbacks/models/stripe_payment_intent.rb +125 -0
- data/lib/stripe_model_callbacks/models/stripe_payment_method.rb +31 -0
- data/lib/stripe_model_callbacks/models/stripe_plan.rb +13 -0
- data/lib/stripe_model_callbacks/models/stripe_product.rb +10 -0
- data/lib/stripe_model_callbacks/models/stripe_recipient.rb +1 -1
- data/lib/stripe_model_callbacks/models/stripe_refund.rb +3 -1
- data/lib/stripe_model_callbacks/models/stripe_setup_intent.rb +21 -0
- data/lib/stripe_model_callbacks/models/stripe_source.rb +2 -1
- data/lib/stripe_model_callbacks/models/stripe_subscription.rb +23 -4
- data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +28 -2
- data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +2 -2
- data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase.rb +1 -1
- data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +6 -0
- data/lib/stripe_model_callbacks/version.rb +1 -1
- data/lib/stripe_model_callbacks.rb +1 -1
- metadata +47 -14
|
@@ -2,11 +2,11 @@ class StripeModelCallbacks::Customer::SourceUpdatedService < StripeModelCallback
|
|
|
2
2
|
def perform
|
|
3
3
|
source = stripe_class.find_or_initialize_by(stripe_id: object.id)
|
|
4
4
|
source.assign_from_stripe(object)
|
|
5
|
-
source.deleted_at = Time.zone.now if event
|
|
5
|
+
source.deleted_at = Time.zone.now if event&.type == "customer.source.deleted"
|
|
6
6
|
|
|
7
7
|
if source.save
|
|
8
|
-
source.
|
|
9
|
-
source.
|
|
8
|
+
source.create_audit!(action: :deleted) if event&.type == "customer.source.deleted"
|
|
9
|
+
source.create_audit!(action: :expiring) if event&.type == "customer.source.expiring"
|
|
10
10
|
succeed!
|
|
11
11
|
else
|
|
12
12
|
fail! source.errors.full_messages
|
|
@@ -16,9 +16,9 @@ private
|
|
|
16
16
|
def create_activity
|
|
17
17
|
case event.type
|
|
18
18
|
when "customer.subscription.trial_will_end"
|
|
19
|
-
subscription.
|
|
19
|
+
subscription.create_audit!(action: :trial_will_end)
|
|
20
20
|
when "customer.subscription.deleted"
|
|
21
|
-
subscription.
|
|
21
|
+
subscription.create_audit!(action: :deleted)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -2,10 +2,10 @@ class StripeModelCallbacks::Customer::UpdatedService < StripeModelCallbacks::Bas
|
|
|
2
2
|
def perform
|
|
3
3
|
customer = StripeCustomer.find_or_initialize_by(stripe_id: object.id)
|
|
4
4
|
customer.assign_from_stripe(object)
|
|
5
|
-
customer.deleted_at ||= Time.zone.now if event
|
|
5
|
+
customer.deleted_at ||= Time.zone.now if event&.type == "customer.deleted"
|
|
6
6
|
|
|
7
7
|
if customer.save
|
|
8
|
-
succeed!
|
|
8
|
+
succeed! customer
|
|
9
9
|
else
|
|
10
10
|
fail! customer.errors.full_messages
|
|
11
11
|
end
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
class StripeModelCallbacks::EventMockerService
|
|
2
2
|
attr_reader :args, :name, :scope
|
|
3
3
|
|
|
4
|
+
def self.execute!(args:, name:, scope:)
|
|
5
|
+
new(args:, name:, scope:).perform
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
def initialize(args:, name:, scope:)
|
|
5
9
|
@args = args
|
|
6
10
|
@name = name
|
|
7
11
|
@scope = scope
|
|
12
|
+
end
|
|
8
13
|
|
|
14
|
+
def perform
|
|
9
15
|
bypass_event_signature(payload)
|
|
10
16
|
post_event
|
|
11
17
|
end
|
|
12
18
|
|
|
19
|
+
def payload
|
|
20
|
+
file_content = File.read(fixture_path)
|
|
21
|
+
data = JSON.parse(file_content, symbolize_names: true)
|
|
22
|
+
data.deep_merge!(args) if args
|
|
23
|
+
data
|
|
24
|
+
end
|
|
25
|
+
|
|
13
26
|
private
|
|
14
27
|
|
|
15
28
|
def bypass_event_signature(payload)
|
|
@@ -22,14 +35,7 @@ private
|
|
|
22
35
|
end
|
|
23
36
|
|
|
24
37
|
def fixture_path
|
|
25
|
-
@fixture_path ||= "#{
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def payload
|
|
29
|
-
file_content = File.read(fixture_path)
|
|
30
|
-
data = JSON.parse(file_content, symbolize_names: true)
|
|
31
|
-
data.deep_merge!(args) if args
|
|
32
|
-
data
|
|
38
|
+
@fixture_path ||= "#{__dir__}/../../../lib/stripe_model_callbacks/fixtures/stripe_events/#{first_part}/#{name}.json"
|
|
33
39
|
end
|
|
34
40
|
|
|
35
41
|
def post_event
|
|
@@ -14,10 +14,10 @@ class StripeModelCallbacks::Invoice::UpdatedService < StripeModelCallbacks::Base
|
|
|
14
14
|
private
|
|
15
15
|
|
|
16
16
|
def create_activity
|
|
17
|
-
invoice.
|
|
18
|
-
invoice.
|
|
19
|
-
invoice.
|
|
20
|
-
invoice.
|
|
17
|
+
invoice.create_audit!(action: :payment_failed) if event.type == "invoice.payment_failed"
|
|
18
|
+
invoice.create_audit!(action: :payment_succeeded) if event.type == "invoice.payment_succeeded"
|
|
19
|
+
invoice.create_audit!(action: :sent) if event.type == "invoice.sent"
|
|
20
|
+
invoice.create_audit!(action: :upcoming) if event.type == "invoice.upcoming"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def invoice
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class StripeModelCallbacks::PaymentIntent::UpdatedService < StripeModelCallbacks::BaseEventService
|
|
2
|
+
def perform
|
|
3
|
+
payment_intent = StripePaymentIntent.find_or_initialize_by(stripe_id: object.id)
|
|
4
|
+
payment_intent.assign_from_stripe(object)
|
|
5
|
+
|
|
6
|
+
if payment_intent.save
|
|
7
|
+
create_activity!(payment_intent) if event
|
|
8
|
+
succeed!
|
|
9
|
+
else
|
|
10
|
+
fail! payment_intent.errors.full_messages
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_activity!(payment_intent)
|
|
15
|
+
match = event.type.match(/\Apayment_intent\.(.+)$/)
|
|
16
|
+
activity_type = match[1].to_sym
|
|
17
|
+
payment_intent.create_audit!(action: activity_type)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class StripeModelCallbacks::PaymentMethod::UpdatedService < StripeModelCallbacks::BaseEventService
|
|
2
|
+
def perform
|
|
3
|
+
payment_method = StripePaymentMethod.find_or_initialize_by(stripe_id: object.id)
|
|
4
|
+
payment_method.assign_from_stripe(object)
|
|
5
|
+
|
|
6
|
+
if payment_method.save
|
|
7
|
+
create_activity!(payment_method) if event
|
|
8
|
+
succeed!
|
|
9
|
+
else
|
|
10
|
+
fail! payment_method.errors.full_messages
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_activity!(payment_method)
|
|
15
|
+
match = event.type.match(/\Apayment_method\.(.+)$/)
|
|
16
|
+
activity_type = match[1].to_sym
|
|
17
|
+
payment_method.create_audit!(action: activity_type)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -15,11 +15,11 @@ private
|
|
|
15
15
|
def create_activity
|
|
16
16
|
case event.type
|
|
17
17
|
when "payout.canceled"
|
|
18
|
-
payout.
|
|
18
|
+
payout.create_audit!(action: :canceled)
|
|
19
19
|
when "payout.failed"
|
|
20
|
-
payout.
|
|
20
|
+
payout.create_audit!(action: :failed)
|
|
21
21
|
when "payout.paid"
|
|
22
|
-
payout.
|
|
22
|
+
payout.create_audit!(action: :paid)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -5,7 +5,7 @@ class StripeModelCallbacks::Plan::UpdatedService < StripeModelCallbacks::BaseEve
|
|
|
5
5
|
plan.deleted_at ||= Time.zone.now if event.type == "plan.deleted"
|
|
6
6
|
|
|
7
7
|
if plan.save
|
|
8
|
-
plan.
|
|
8
|
+
plan.create_audit!(action: :deleted) if event.type == "plan.deleted"
|
|
9
9
|
succeed!
|
|
10
10
|
else
|
|
11
11
|
fail! plan.errors.full_messages
|
|
@@ -5,7 +5,7 @@ class StripeModelCallbacks::Price::UpdatedService < StripeModelCallbacks::BaseEv
|
|
|
5
5
|
price.deleted_at ||= Time.zone.now if event.type == "price.deleted"
|
|
6
6
|
|
|
7
7
|
if price.save
|
|
8
|
-
price.
|
|
8
|
+
price.create_audit!(action: :deleted) if event.type == "price.deleted"
|
|
9
9
|
succeed!
|
|
10
10
|
else
|
|
11
11
|
fail! price.errors.full_messages
|
|
@@ -5,7 +5,7 @@ class StripeModelCallbacks::Product::UpdatedService < StripeModelCallbacks::Base
|
|
|
5
5
|
product.deleted_at ||= Time.zone.now if event.type == "product.deleted"
|
|
6
6
|
|
|
7
7
|
if product.save
|
|
8
|
-
product.
|
|
8
|
+
product.create_audit!(action: :deleted) if event.type == "product.deleted"
|
|
9
9
|
succeed!
|
|
10
10
|
else
|
|
11
11
|
fail! product.errors.full_messages
|
|
@@ -5,7 +5,7 @@ class StripeModelCallbacks::Recipient::UpdatedService < StripeModelCallbacks::Ba
|
|
|
5
5
|
recipient.deleted_at ||= Time.zone.now if event.type == "recipient.deleted"
|
|
6
6
|
|
|
7
7
|
if recipient.save
|
|
8
|
-
recipient.
|
|
8
|
+
recipient.create_audit!(action: :deleted) if event.type == "recipient.deleted"
|
|
9
9
|
succeed!
|
|
10
10
|
else
|
|
11
11
|
fail! recipient.errors.full_messages
|
|
@@ -4,7 +4,7 @@ class StripeModelCallbacks::Review::UpdatedService < StripeModelCallbacks::BaseE
|
|
|
4
4
|
review.assign_from_stripe(object)
|
|
5
5
|
|
|
6
6
|
if review.save
|
|
7
|
-
review.
|
|
7
|
+
review.create_audit!(action: :closed) if event.type == "review.closed"
|
|
8
8
|
succeed!
|
|
9
9
|
else
|
|
10
10
|
fail! review.errors.full_messages
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
class StripeModelCallbacks::SetupIntent::UpdatedService < StripeModelCallbacks::BaseEventService
|
|
2
|
+
def perform
|
|
3
|
+
refund = StripeSetupIntent.find_or_initialize_by(stripe_id: object.id)
|
|
4
|
+
refund.assign_from_stripe(object)
|
|
5
|
+
save_models_or_fail(refund)
|
|
6
|
+
succeed!
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -5,7 +5,7 @@ class StripeModelCallbacks::Sku::UpdatedService < StripeModelCallbacks::BaseEven
|
|
|
5
5
|
sku.deleted_at ||= Time.zone.now if event.type == "sku.deleted"
|
|
6
6
|
|
|
7
7
|
if sku.save
|
|
8
|
-
sku.
|
|
8
|
+
sku.create_audit!(action: :deleted) if event.type == "sku.deleted"
|
|
9
9
|
succeed!
|
|
10
10
|
else
|
|
11
11
|
fail! sku.errors.full_messages
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class StripeModelCallbacks::Source::TransactionCreatedService < StripeModelCallbacks::BaseEventService
|
|
2
|
+
def perform
|
|
3
|
+
return succeed! unless source
|
|
4
|
+
|
|
5
|
+
source.create_audit!(action: :transaction_created)
|
|
6
|
+
succeed!
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def source
|
|
12
|
+
@source ||= begin
|
|
13
|
+
source_id = object.respond_to?(:source) ? object.source : nil
|
|
14
|
+
source_id ? StripeSource.find_by(stripe_id: source_id) : nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -15,13 +15,13 @@ private
|
|
|
15
15
|
def create_activity
|
|
16
16
|
case event.type
|
|
17
17
|
when "source.canceled"
|
|
18
|
-
source.
|
|
18
|
+
source.create_audit!(action: :canceled)
|
|
19
19
|
when "source.chargeable"
|
|
20
|
-
source.
|
|
20
|
+
source.create_audit!(action: :chargeable)
|
|
21
21
|
when "source.failed"
|
|
22
|
-
source.
|
|
22
|
+
source.create_audit!(action: :failed)
|
|
23
23
|
when "source.mandate_notification"
|
|
24
|
-
source.
|
|
24
|
+
source.create_audit!(action: :mandate_notification)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -9,7 +9,7 @@ class StripeModelCallbacks::Subscription::StateCheckerService < StripeModelCallb
|
|
|
9
9
|
def perform
|
|
10
10
|
if state.is_a?(Array)
|
|
11
11
|
state.each do |state_i|
|
|
12
|
-
response = Subscription::StateCheckerService.execute!(allowed
|
|
12
|
+
response = Subscription::StateCheckerService.execute!(allowed:, state: state_i)
|
|
13
13
|
return response unless response.success?
|
|
14
14
|
end
|
|
15
15
|
elsif allowed.exclude?(state)
|
|
@@ -22,7 +22,7 @@ private
|
|
|
22
22
|
def create_activity
|
|
23
23
|
return unless tracked_activities[event.type]
|
|
24
24
|
|
|
25
|
-
subscription_schedule.
|
|
25
|
+
subscription_schedule.create_audit!(action: tracked_activities[event.type])
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def set_cancellation_date
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
class StripeModelCallbacks::SyncEverything < StripeModelCallbacks::BaseService
|
|
2
|
+
def self.stripe_classes
|
|
3
|
+
[Stripe::Customer, Stripe::Coupon, Stripe::Invoice, Stripe::Plan, Stripe::PaymentIntent, Stripe::Subscription]
|
|
4
|
+
end
|
|
5
|
+
|
|
2
6
|
def perform
|
|
3
|
-
StripeModelCallbacks::
|
|
4
|
-
|
|
7
|
+
StripeModelCallbacks::SyncEverything.stripe_classes.each do |stripe_class|
|
|
8
|
+
stripe_class.list.each do |stripe_object|
|
|
9
|
+
StripeModelCallbacks::SyncFromStripe.execute!(stripe_object:)
|
|
10
|
+
|
|
11
|
+
sync_stripe_objects(Stripe::PaymentMethod.list(customer: stripe_object.id)) if stripe_class == Stripe::Customer
|
|
12
|
+
end
|
|
13
|
+
end
|
|
5
14
|
|
|
6
15
|
succeed!
|
|
7
16
|
end
|
|
17
|
+
|
|
18
|
+
def sync_stripe_objects(stripe_objects)
|
|
19
|
+
stripe_objects.each do |stripe_object|
|
|
20
|
+
StripeModelCallbacks::SyncFromStripe.execute!(stripe_object:)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
8
23
|
end
|
|
@@ -15,13 +15,13 @@ private
|
|
|
15
15
|
def create_activity
|
|
16
16
|
case event.type
|
|
17
17
|
when "tax_rate.created"
|
|
18
|
-
tax_rate.
|
|
18
|
+
tax_rate.create_audit!(action: :created)
|
|
19
19
|
when "tax_rate.updated"
|
|
20
|
-
tax_rate.
|
|
20
|
+
tax_rate.create_audit!(action: :updated)
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def tax_rate
|
|
25
|
-
@tax_rate ||= StripeTaxRate.find_or_initialize_by(stripe_id: object.id)
|
|
25
|
+
@tax_rate ||= StripeTaxRate.find_or_initialize_by(stripe_id: object.is_a?(String) ? object : object.id)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -3,7 +3,7 @@ class StripeModelCallbacks::Transfer::UpdatedService < StripeModelCallbacks::Bas
|
|
|
3
3
|
transfer.assign_from_stripe(object)
|
|
4
4
|
|
|
5
5
|
if transfer.save
|
|
6
|
-
transfer.
|
|
6
|
+
transfer.create_audit!(action: :reversed) if event.type == "transfer.reversed"
|
|
7
7
|
succeed!
|
|
8
8
|
else
|
|
9
9
|
fail! transfer.errors.full_messages
|
|
@@ -28,6 +28,7 @@ RemoveUnusedMethodsInHelpersCheck: { except_methods: [] }
|
|
|
28
28
|
RemoveUnusedMethodsInModelsCheck: {
|
|
29
29
|
except_methods: [
|
|
30
30
|
"StripeModelCallbacks::ApplicationRecord#create_on_stripe!",
|
|
31
|
+
"StripeModelCallbacks::ApplicationRecord#inherited",
|
|
31
32
|
"StripeModelCallbacks::ApplicationRecord#reload!",
|
|
32
33
|
"StripeModelCallbacks::ApplicationRecord#update_on_stripe!",
|
|
33
34
|
"StripeModelCallbacks::ApplicationRecord#destroy_on_stripe!"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class ChangeActivitiesTrackableIdToString < ActiveRecord::Migration[5.1]
|
|
2
2
|
def change
|
|
3
|
-
change_column :activities, :trackable_id, :string
|
|
3
|
+
change_column :activities, :trackable_id, :string # rubocop:disable Rails/ReversibleMigration
|
|
4
4
|
end
|
|
5
5
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class ChangeStripeSubscriptionItemsQuantityToInteger < ActiveRecord::Migration[5.1]
|
|
2
2
|
def change
|
|
3
|
-
change_column :stripe_subscription_items, :quantity, :integer
|
|
3
|
+
change_column :stripe_subscription_items, :quantity, :integer # rubocop:disable Rails/ReversibleMigration
|
|
4
4
|
end
|
|
5
5
|
end
|
|
@@ -17,7 +17,7 @@ class AddNewPrimaryIdAndRenameOld < ActiveRecord::Migration[5.2]
|
|
|
17
17
|
change_column_null table_name, :stripe_id, false
|
|
18
18
|
remove_column table_name, :id
|
|
19
19
|
|
|
20
|
-
add_column table_name, :id, :primary_key
|
|
20
|
+
add_column table_name, :id, :primary_key # rubocop:disable Rails/DangerousColumnNames
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -28,7 +28,7 @@ class AddNewPrimaryIdAndRenameOld < ActiveRecord::Migration[5.2]
|
|
|
28
28
|
next unless column_exists?(table_name, :stripe_id)
|
|
29
29
|
|
|
30
30
|
remove_column table_name, :id
|
|
31
|
-
add_column table_name, :id, :string, primary_key: true
|
|
31
|
+
add_column table_name, :id, :string, primary_key: true # rubocop:disable Rails/DangerousColumnNames
|
|
32
32
|
execute "UPDATE #{table_name} SET id = stripe_id"
|
|
33
33
|
change_column_null table_name, :id, false
|
|
34
34
|
remove_column table_name, :stripe_id
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class CreateStripeSetupIntents < ActiveRecord::Migration[7.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :stripe_setup_intents do |t|
|
|
4
|
+
t.string :stripe_id, index: {unique: true}, null: false
|
|
5
|
+
t.string :application
|
|
6
|
+
t.string :cancellation_reason
|
|
7
|
+
t.string :client_secret
|
|
8
|
+
t.datetime :created
|
|
9
|
+
t.string :customer, index: true
|
|
10
|
+
t.string :description
|
|
11
|
+
t.json :flow_directions
|
|
12
|
+
t.string :last_setup_error
|
|
13
|
+
t.string :latest_attempt
|
|
14
|
+
t.boolean :livemode
|
|
15
|
+
t.json :mandate
|
|
16
|
+
t.json :metadata
|
|
17
|
+
t.string :next_action
|
|
18
|
+
t.string :on_behalf_of
|
|
19
|
+
t.json :payment_method
|
|
20
|
+
t.json :payment_method_options
|
|
21
|
+
t.json :payment_method_types
|
|
22
|
+
t.string :single_use_mandate
|
|
23
|
+
t.string :status
|
|
24
|
+
t.string :usage
|
|
25
|
+
t.timestamps
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class CreateStripePaymentMethods < ActiveRecord::Migration[7.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :stripe_payment_methods do |t|
|
|
4
|
+
t.string :stripe_id, index: {unique: true}, null: false
|
|
5
|
+
t.json :billing_details
|
|
6
|
+
t.json :card
|
|
7
|
+
t.json :metadata
|
|
8
|
+
t.string :customer
|
|
9
|
+
t.string :stripe_type
|
|
10
|
+
t.boolean :livemode
|
|
11
|
+
t.integer :created
|
|
12
|
+
t.timestamps
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
class CreateStripePaymentIntents < ActiveRecord::Migration[7.0]
|
|
2
|
+
def change # rubocop:disable Metrics/AbcSize
|
|
3
|
+
create_table :stripe_payment_intents do |t|
|
|
4
|
+
t.string :stripe_id, index: {unique: true}, null: false
|
|
5
|
+
t.integer :amount
|
|
6
|
+
t.integer :amount_capturable
|
|
7
|
+
t.json :amount_details
|
|
8
|
+
t.integer :amount_received
|
|
9
|
+
t.string :application
|
|
10
|
+
t.integer :application_fee_amount
|
|
11
|
+
t.json :automatic_payment_methods
|
|
12
|
+
t.integer :canceled_at
|
|
13
|
+
t.string :cancellation_reason
|
|
14
|
+
t.string :capture_method
|
|
15
|
+
t.string :client_secret
|
|
16
|
+
t.string :confirmation_method
|
|
17
|
+
t.integer :created
|
|
18
|
+
t.string :currency
|
|
19
|
+
t.string :customer, index: true
|
|
20
|
+
t.text :description
|
|
21
|
+
t.string :invoice
|
|
22
|
+
t.json :last_payment_error
|
|
23
|
+
t.string :latest_charge, index: true
|
|
24
|
+
t.boolean :livemode
|
|
25
|
+
t.json :metadata
|
|
26
|
+
t.json :next_action
|
|
27
|
+
t.string :on_behalf_of, index: true
|
|
28
|
+
t.string :payment_method, index: true
|
|
29
|
+
t.json :payment_method_options
|
|
30
|
+
t.json :payment_method_types
|
|
31
|
+
t.json :processing
|
|
32
|
+
t.string :receipt_email
|
|
33
|
+
t.string :review, index: true
|
|
34
|
+
t.string :setup_future_usage
|
|
35
|
+
t.json :shipping
|
|
36
|
+
t.string :statement_descriptor
|
|
37
|
+
t.string :statement_descriptor_suffix
|
|
38
|
+
t.string :status
|
|
39
|
+
t.json :transfer_data
|
|
40
|
+
t.string :transfer_group
|
|
41
|
+
t.timestamps
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class ChangeStripeSetupIntentsPaymentMethodToString < ActiveRecord::Migration[7.0]
|
|
2
|
+
def change
|
|
3
|
+
rename_column :stripe_setup_intents, :payment_method, :payment_method_old
|
|
4
|
+
add_column :stripe_setup_intents, :payment_method, :string
|
|
5
|
+
add_index :stripe_setup_intents, :payment_method
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -7,5 +7,15 @@ FactoryBot.define do
|
|
|
7
7
|
livemode { false }
|
|
8
8
|
paid { false }
|
|
9
9
|
refunded { false }
|
|
10
|
+
|
|
11
|
+
trait :with_conditional_stripe_mock do
|
|
12
|
+
after :create do |stripe_charge|
|
|
13
|
+
stripe_charge.create_stripe_mock! if StripeMock.instance
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
trait :with_stripe_mock do
|
|
18
|
+
after :create, &:create_stripe_mock!
|
|
19
|
+
end
|
|
10
20
|
end
|
|
11
21
|
end
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
FactoryBot.define do
|
|
2
2
|
factory :stripe_coupon do
|
|
3
3
|
sequence(:stripe_id) { |n| "stripe-coupon-#{n}" }
|
|
4
|
+
livemode { false }
|
|
4
5
|
|
|
5
|
-
trait :
|
|
6
|
+
trait :with_conditional_stripe_mock do
|
|
6
7
|
duration { "repeating" }
|
|
7
8
|
duration_in_months { 1 }
|
|
8
9
|
|
|
9
10
|
after :create do |stripe_coupon|
|
|
10
|
-
|
|
11
|
-
duration: stripe_coupon.duration,
|
|
12
|
-
duration_in_months: stripe_coupon.duration_in_months,
|
|
13
|
-
id: stripe_coupon.stripe_id,
|
|
14
|
-
percent_off: stripe_coupon.percent_off
|
|
15
|
-
)
|
|
16
|
-
stripe_coupon.assign_from_stripe(mock_coupon)
|
|
17
|
-
stripe_coupon.save!
|
|
11
|
+
stripe_coupon.create_stripe_mock! if StripeMock.instance
|
|
18
12
|
end
|
|
19
13
|
end
|
|
14
|
+
|
|
15
|
+
trait :with_stripe_mock do
|
|
16
|
+
duration { "repeating" }
|
|
17
|
+
duration_in_months { 1 }
|
|
18
|
+
|
|
19
|
+
after :create, &:create_stripe_mock!
|
|
20
|
+
end
|
|
20
21
|
end
|
|
21
22
|
end
|
|
@@ -6,12 +6,14 @@ FactoryBot.define do
|
|
|
6
6
|
delinquent { false }
|
|
7
7
|
livemode { false }
|
|
8
8
|
|
|
9
|
-
trait :
|
|
9
|
+
trait :with_conditional_stripe_mock do
|
|
10
10
|
after :create do |stripe_customer|
|
|
11
|
-
|
|
12
|
-
stripe_customer.assign_from_stripe(mock_customer)
|
|
13
|
-
stripe_customer.save!
|
|
11
|
+
stripe_customer.create_stripe_mock! if StripeMock.instance
|
|
14
12
|
end
|
|
15
13
|
end
|
|
14
|
+
|
|
15
|
+
trait :with_stripe_mock do
|
|
16
|
+
after :create, &:create_stripe_mock!
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
end
|