stripe_model_callbacks 0.1.7 → 0.1.8
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 +11 -7
- data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/base_service.rb +6 -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 +54 -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/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 +9 -9
- data/lib/stripe_model_callbacks/factories/stripe_customers.rb +6 -4
- 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 +6 -8
- data/lib/stripe_model_callbacks/factories/stripe_setup_intents.rb +7 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_items.rb +6 -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/fixtures/stripe_events/charge/charge.refunded.json +1 -0
- 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/models/stripe_charge.rb +47 -3
- data/lib/stripe_model_callbacks/models/stripe_coupon.rb +11 -0
- data/lib/stripe_model_callbacks/models/stripe_customer.rb +12 -0
- data/lib/stripe_model_callbacks/models/stripe_invoice.rb +16 -1
- data/lib/stripe_model_callbacks/models/stripe_payment_intent.rb +126 -0
- data/lib/stripe_model_callbacks/models/stripe_payment_method.rb +32 -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_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 +10 -1
- data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +1 -1
- 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 +45 -13
@@ -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
|
@@ -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
|
@@ -2,20 +2,20 @@ FactoryBot.define do
|
|
2
2
|
factory :stripe_coupon do
|
3
3
|
sequence(:stripe_id) { |n| "stripe-coupon-#{n}" }
|
4
4
|
|
5
|
-
trait :
|
5
|
+
trait :with_conditional_stripe_mock do
|
6
6
|
duration { "repeating" }
|
7
7
|
duration_in_months { 1 }
|
8
8
|
|
9
9
|
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!
|
10
|
+
stripe_coupon.create_stripe_mock! if StripeMock.instance
|
18
11
|
end
|
19
12
|
end
|
13
|
+
|
14
|
+
trait :with_stripe_mock do
|
15
|
+
duration { "repeating" }
|
16
|
+
duration_in_months { 1 }
|
17
|
+
|
18
|
+
after :create, &:create_stripe_mock!
|
19
|
+
end
|
20
20
|
end
|
21
21
|
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
|
@@ -0,0 +1,17 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_payment_intent do
|
3
|
+
amount { 125_00 }
|
4
|
+
currency { "usd" }
|
5
|
+
sequence(:stripe_id) { |n| "stripe-payment-intent-#{n}" }
|
6
|
+
|
7
|
+
trait :with_conditional_stripe_mock do
|
8
|
+
after :create do |stripe_payment_intent|
|
9
|
+
stripe_payment_intent.create_stripe_mock! if StripeMock.instance
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
trait :with_stripe_mock do
|
14
|
+
after :create, &:create_stripe_mock!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_payment_method do
|
3
|
+
sequence(:stripe_id) { |n| "stripe-payment-method-#{n}" }
|
4
|
+
|
5
|
+
trait :with_conditional_stripe_mock do
|
6
|
+
after :create do |stripe_payment_method|
|
7
|
+
stripe_payment_method.create_stripe_mock! if StripeMock.instance
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
trait :with_stripe_mock do
|
12
|
+
after :create, &:create_stripe_mock!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,21 +9,18 @@ FactoryBot.define do
|
|
9
9
|
livemode { false }
|
10
10
|
stripe_product
|
11
11
|
|
12
|
-
trait :
|
13
|
-
association :stripe_product, factory: [:stripe_product, :
|
12
|
+
trait :with_conditional_stripe_mock do
|
13
|
+
association :stripe_product, factory: [:stripe_product, :with_conditional_stripe_mock]
|
14
14
|
|
15
15
|
after :create do |stripe_plan|
|
16
|
-
|
17
|
-
id: stripe_plan.stripe_id,
|
18
|
-
amount: stripe_plan.amount_cents,
|
19
|
-
currency: stripe_plan.currency,
|
20
|
-
interval: stripe_plan.interval,
|
21
|
-
interval_count: stripe_plan.interval_count,
|
22
|
-
product: stripe_plan.stripe_product.stripe_id
|
23
|
-
)
|
24
|
-
stripe_plan.assign_from_stripe(mock_plan)
|
25
|
-
stripe_plan.save!
|
16
|
+
stripe_plan.create_stripe_mock! if StripeMock.instance
|
26
17
|
end
|
27
18
|
end
|
19
|
+
|
20
|
+
trait :with_stripe_mock do
|
21
|
+
association :stripe_product, factory: [:stripe_product, :with_stripe_mock]
|
22
|
+
|
23
|
+
after :create, &:create_stripe_mock!
|
24
|
+
end
|
28
25
|
end
|
29
26
|
end
|
@@ -3,16 +3,14 @@ FactoryBot.define do
|
|
3
3
|
sequence(:name) { |n| "Stripe product #{n}" }
|
4
4
|
sequence(:stripe_id) { |n| "stripe-product-#{n}" }
|
5
5
|
|
6
|
-
trait :
|
6
|
+
trait :with_conditional_stripe_mock do
|
7
7
|
after :create do |stripe_product|
|
8
|
-
|
9
|
-
id: stripe_product.stripe_id,
|
10
|
-
name: stripe_product.name,
|
11
|
-
type: "service"
|
12
|
-
)
|
13
|
-
stripe_product.assign_from_stripe(mock_product)
|
14
|
-
stripe_product.save!
|
8
|
+
stripe_product.create_stripe_mock! if StripeMock.instance
|
15
9
|
end
|
16
10
|
end
|
11
|
+
|
12
|
+
trait :with_stripe_mock do
|
13
|
+
after :create, &:create_stripe_mock!
|
14
|
+
end
|
17
15
|
end
|
18
16
|
end
|
@@ -5,15 +5,14 @@ FactoryBot.define do
|
|
5
5
|
stripe_plan
|
6
6
|
quantity { 1 }
|
7
7
|
|
8
|
-
trait :
|
8
|
+
trait :with_conditional_stripe_mock do
|
9
9
|
after :build do |item|
|
10
|
-
|
11
|
-
subscription: item.stripe_subscription.stripe_id,
|
12
|
-
plan: item.stripe_plan.stripe_id,
|
13
|
-
quantity: item.quantity
|
14
|
-
)
|
15
|
-
item.assign_from_stripe(mock_item)
|
10
|
+
item.create_stripe_mock! if StripeMock.instance
|
16
11
|
end
|
17
12
|
end
|
13
|
+
|
14
|
+
trait :with_stripe_mock do
|
15
|
+
after :build, &:create_stripe_mock!
|
16
|
+
end
|
18
17
|
end
|
19
18
|
end
|
@@ -19,22 +19,20 @@ FactoryBot.define do
|
|
19
19
|
cancel_at_period_end { true }
|
20
20
|
end
|
21
21
|
|
22
|
-
trait :
|
23
|
-
association :stripe_customer, factory: [:stripe_customer, :
|
24
|
-
association :stripe_plan, factory: [:stripe_plan, :
|
22
|
+
trait :with_conditional_stripe_mock do
|
23
|
+
association :stripe_customer, factory: [:stripe_customer, :with_conditional_stripe_mock]
|
24
|
+
association :stripe_plan, factory: [:stripe_plan, :with_conditional_stripe_mock]
|
25
25
|
|
26
26
|
after :create do |stripe_subscription|
|
27
|
-
|
27
|
+
stripe_subscription.create_stripe_mock! if StripeMock.instance
|
28
|
+
end
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
)
|
33
|
-
stripe_subscription.assign_from_stripe(mock_subscription)
|
34
|
-
stripe_subscription.save!
|
31
|
+
trait :with_stripe_mock do
|
32
|
+
association :stripe_customer, factory: [:stripe_customer, :with_stripe_mock]
|
33
|
+
association :stripe_plan, factory: [:stripe_plan, :with_stripe_mock]
|
35
34
|
|
36
|
-
|
37
|
-
end
|
35
|
+
after :create, &:create_stripe_mock!
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
@@ -1,5 +1,15 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :stripe_tax_rate do
|
3
3
|
sequence(:stripe_id) { |n| "stripe-tax-rate-#{n}" }
|
4
|
+
|
5
|
+
trait :with_conditional_stripe_mock do
|
6
|
+
after :create do |stripe_tax_rate|
|
7
|
+
stripe_tax_rate.create_stripe_mock! if StripeMock.instance
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
trait :with_stripe_mock do
|
12
|
+
after :create, &:create_stripe_mock!
|
13
|
+
end
|
4
14
|
end
|
5
15
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
{
|
2
|
+
"id": "evt_1MxwhGIICJxvfdbRjLpH5qNb",
|
3
|
+
"object": "event",
|
4
|
+
"api_version": "2022-11-15",
|
5
|
+
"created": 1681755758,
|
6
|
+
"data": {
|
7
|
+
"object": {
|
8
|
+
"id": "pi_1JGpBw4Lf1hyuG3tSrdK3llw",
|
9
|
+
"object": "payment_intent",
|
10
|
+
"amount": 1000,
|
11
|
+
"amount_capturable": 0,
|
12
|
+
"amount_details": {
|
13
|
+
"tip": {}
|
14
|
+
},
|
15
|
+
"amount_received": 0,
|
16
|
+
"application": null,
|
17
|
+
"application_fee_amount": null,
|
18
|
+
"automatic_payment_methods": null,
|
19
|
+
"canceled_at": null,
|
20
|
+
"cancellation_reason": null,
|
21
|
+
"capture_method": "automatic",
|
22
|
+
"client_secret": "pi_1JGpBw4Lf1hyuG3tSrdK3llw_secret_LS2rgASDfUetReE3XLXayygdt",
|
23
|
+
"confirmation_method": "automatic",
|
24
|
+
"created": 1627149796,
|
25
|
+
"currency": "usd",
|
26
|
+
"customer": "cus_NiCY7UI5u0pbJH",
|
27
|
+
"description": "Created by stripe.com/docs demo",
|
28
|
+
"invoice": null,
|
29
|
+
"last_payment_error": null,
|
30
|
+
"latest_charge": null,
|
31
|
+
"livemode": false,
|
32
|
+
"metadata": {},
|
33
|
+
"next_action": null,
|
34
|
+
"on_behalf_of": null,
|
35
|
+
"payment_method": null,
|
36
|
+
"payment_method_options": {
|
37
|
+
"card": {
|
38
|
+
"installments": null,
|
39
|
+
"mandate_options": null,
|
40
|
+
"network": null,
|
41
|
+
"request_three_d_secure": "automatic"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
"payment_method_types": [
|
45
|
+
"card"
|
46
|
+
],
|
47
|
+
"processing": null,
|
48
|
+
"receipt_email": null,
|
49
|
+
"review": null,
|
50
|
+
"setup_future_usage": null,
|
51
|
+
"shipping": null,
|
52
|
+
"statement_descriptor": null,
|
53
|
+
"statement_descriptor_suffix": null,
|
54
|
+
"status": "requires_payment_method",
|
55
|
+
"transfer_data": null,
|
56
|
+
"transfer_group": null
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"livemode": true,
|
60
|
+
"pending_webhooks": 1,
|
61
|
+
"request": {
|
62
|
+
"id": null,
|
63
|
+
"idempotency_key": "setatt_1MxwglIICJxvfdbR7jPCO6O3-src_1MxwgmIICJxvfdbRoaqKyWHH"
|
64
|
+
},
|
65
|
+
"type": "payment_intent.amount_capturable_updated"
|
66
|
+
}
|