stripe_model_callbacks 0.1.2 → 0.1.3

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.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -0
  3. data/app/models/stripe_model_callbacks/application_record.rb +17 -0
  4. data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +1 -1
  5. data/app/services/stripe_model_callbacks/attributes_assigner_service.rb +1 -1
  6. data/app/services/stripe_model_callbacks/base_service.rb +33 -1
  7. data/app/services/stripe_model_callbacks/charge/dispute_updated_service.rb +1 -1
  8. data/app/services/stripe_model_callbacks/charge/updated_service.rb +1 -1
  9. data/app/services/stripe_model_callbacks/configure_service.rb +52 -24
  10. data/app/services/stripe_model_callbacks/coupon/sync_all.rb +9 -0
  11. data/app/services/stripe_model_callbacks/coupon/updated_service.rb +1 -1
  12. data/app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb +1 -1
  13. data/app/services/stripe_model_callbacks/customer/deleted_service.rb +1 -1
  14. data/app/services/stripe_model_callbacks/customer/discount_updated_service.rb +1 -1
  15. data/app/services/stripe_model_callbacks/customer/source_updated_service.rb +1 -1
  16. data/app/services/stripe_model_callbacks/customer/subscription/updated_service.rb +1 -1
  17. data/app/services/stripe_model_callbacks/customer/updated_service.rb +1 -1
  18. data/app/services/stripe_model_callbacks/invoice/updated_service.rb +1 -1
  19. data/app/services/stripe_model_callbacks/invoice_item/updated_service.rb +1 -1
  20. data/app/services/stripe_model_callbacks/notifier_service.rb +1 -1
  21. data/app/services/stripe_model_callbacks/order/updated_service.rb +1 -1
  22. data/app/services/stripe_model_callbacks/payout/updated_service.rb +1 -1
  23. data/app/services/stripe_model_callbacks/plan/sync_all.rb +9 -0
  24. data/app/services/stripe_model_callbacks/plan/updated_service.rb +1 -1
  25. data/app/services/stripe_model_callbacks/price/updated_service.rb +14 -0
  26. data/app/services/stripe_model_callbacks/product/updated_service.rb +1 -1
  27. data/app/services/stripe_model_callbacks/recipient/updated_service.rb +1 -1
  28. data/app/services/stripe_model_callbacks/refund/updated_service.rb +1 -1
  29. data/app/services/stripe_model_callbacks/review/updated_service.rb +1 -1
  30. data/app/services/stripe_model_callbacks/sku/updated_service.rb +1 -1
  31. data/app/services/stripe_model_callbacks/source/updated_service.rb +1 -1
  32. data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +2 -2
  33. data/app/services/stripe_model_callbacks/subscription_schedule/updated_service.rb +46 -0
  34. data/app/services/stripe_model_callbacks/sync_everything.rb +8 -0
  35. data/app/services/stripe_model_callbacks/sync_from_stripe.rb +29 -0
  36. data/app/services/stripe_model_callbacks/tax_rate/updated_service.rb +27 -0
  37. data/app/services/stripe_model_callbacks/transfer/updated_service.rb +1 -1
  38. data/db/migrate/20200317160513_add_auto_advance_and_billing_reason_to_stripe_invoices.rb +6 -0
  39. data/db/migrate/20200317160602_add_status_and_status_transitions_to_stripe_invoices.rb +10 -0
  40. data/db/migrate/20200317180115_add_product_type_to_products.rb +5 -0
  41. data/db/migrate/20200317181224_rename_stripe_invoices_application_fee_to_application_fee_amount.rb +6 -0
  42. data/db/migrate/20200320105158_make_stripe_invoices_forgive_optional.rb +5 -0
  43. data/db/migrate/20200320114859_make_stripe_invoice_closed_optional.rb +5 -0
  44. data/db/migrate/20200323143634_add_amount_paid_and_remaining_and_invoice_url_and_pdf.rb +11 -0
  45. data/db/migrate/20200331074940_add_unit_label_to_stripe_products.rb +5 -0
  46. data/db/migrate/20200331075241_add_metered_info_to_stripe_plans.rb +9 -0
  47. data/db/migrate/20200513131105_create_stripe_subscription_schedules.rb +31 -0
  48. data/db/migrate/20200513131120_create_stripe_subscription_schedule_phases.rb +21 -0
  49. data/db/migrate/20200513131640_create_stripe_subscription_schedule_phase_plans.rb +13 -0
  50. data/db/migrate/20200514132247_add_stripe_id_uniq_to_stripe_invoices.rb +8 -0
  51. data/db/migrate/20200520152604_change_stripe_subscription_schedule_phase_id_to_bigint.rb +27 -0
  52. data/db/migrate/20200529144649_add_latest_invoice_id_to_stripe_subscription.rb +5 -0
  53. data/db/migrate/20201223173035_rename_stripe_subscriptions_start_to_start_date.rb +5 -0
  54. data/db/migrate/20201223202117_create_stripe_tax_rates.rb +15 -0
  55. data/db/migrate/20201224120534_create_stripe_subscription_default_tax_rates.rb +9 -0
  56. data/db/migrate/20201224122058_create_stripe_prices.rb +26 -0
  57. data/db/migrate/20201224123838_add_stripe_price_to_stripe_subscription_items.rb +6 -0
  58. data/lib/stripe_model_callbacks/configuration.rb +1 -1
  59. data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +16 -0
  60. data/lib/stripe_model_callbacks/factories/stripe_plans.rb +3 -1
  61. data/lib/stripe_model_callbacks/factories/stripe_prices.rb +3 -0
  62. data/lib/stripe_model_callbacks/factories/stripe_products.rb +13 -0
  63. data/lib/stripe_model_callbacks/factories/stripe_subscription_default_tax_rates.rb +6 -0
  64. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule.rb.rb +5 -0
  65. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phase_plan.rb +5 -0
  66. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phases.rb +5 -0
  67. data/lib/stripe_model_callbacks/factories/stripe_subscriptions.rb +1 -1
  68. data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +5 -0
  69. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.2020-12-24.json +112 -0
  70. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.json +1 -0
  71. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.deleted.json +2 -2
  72. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.updated.json +1 -1
  73. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.updated.json +1 -1
  74. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.created.json +13 -3
  75. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_failed.json +14 -4
  76. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_succeeded.json +23 -4
  77. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.sent.json +13 -3
  78. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +13 -3
  79. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.updated.json +13 -3
  80. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.voided.json +152 -0
  81. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.created.json +7 -2
  82. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.created.json +37 -0
  83. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.deleted.json +37 -0
  84. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.updated.json +40 -0
  85. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.created.json +1 -0
  86. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.canceled.json +81 -0
  87. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.created.json +77 -0
  88. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.updated.json +87 -0
  89. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.created.json +26 -0
  90. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.updated.json +29 -0
  91. data/lib/stripe_model_callbacks/models/stripe_bank_account.rb +1 -0
  92. data/lib/stripe_model_callbacks/models/stripe_card.rb +2 -1
  93. data/lib/stripe_model_callbacks/models/stripe_charge.rb +3 -0
  94. data/lib/stripe_model_callbacks/models/stripe_coupon.rb +1 -0
  95. data/lib/stripe_model_callbacks/models/stripe_customer.rb +4 -2
  96. data/lib/stripe_model_callbacks/models/stripe_discount.rb +10 -3
  97. data/lib/stripe_model_callbacks/models/stripe_dispute.rb +1 -0
  98. data/lib/stripe_model_callbacks/models/stripe_invoice.rb +62 -7
  99. data/lib/stripe_model_callbacks/models/stripe_invoice_item.rb +2 -0
  100. data/lib/stripe_model_callbacks/models/stripe_order.rb +1 -0
  101. data/lib/stripe_model_callbacks/models/stripe_order_item.rb +1 -0
  102. data/lib/stripe_model_callbacks/models/stripe_payout.rb +2 -1
  103. data/lib/stripe_model_callbacks/models/stripe_plan.rb +4 -1
  104. data/lib/stripe_model_callbacks/models/stripe_price.rb +27 -0
  105. data/lib/stripe_model_callbacks/models/stripe_product.rb +17 -7
  106. data/lib/stripe_model_callbacks/models/stripe_recipient.rb +1 -0
  107. data/lib/stripe_model_callbacks/models/stripe_refund.rb +1 -0
  108. data/lib/stripe_model_callbacks/models/stripe_review.rb +1 -0
  109. data/lib/stripe_model_callbacks/models/stripe_sku.rb +13 -6
  110. data/lib/stripe_model_callbacks/models/stripe_source.rb +4 -2
  111. data/lib/stripe_model_callbacks/models/stripe_subscription.rb +56 -6
  112. data/lib/stripe_model_callbacks/models/stripe_subscription_default_tax_rate.rb +4 -0
  113. data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +19 -1
  114. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +94 -0
  115. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase.rb +67 -0
  116. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase_plan.rb +37 -0
  117. data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +22 -0
  118. data/lib/stripe_model_callbacks/models/stripe_transfer.rb +1 -0
  119. data/lib/stripe_model_callbacks/version.rb +1 -1
  120. data/lib/stripe_model_callbacks.rb +1 -0
  121. metadata +90 -13
@@ -0,0 +1,29 @@
1
+ class StripeModelCallbacks::SyncFromStripe < StripeModelCallbacks::BaseService
2
+ attr_reader :stripe_object
3
+
4
+ def initialize(stripe_object:)
5
+ @stripe_object = stripe_object
6
+ end
7
+
8
+ def perform
9
+ model = model_class.find_by(stripe_id: stripe_object.id)
10
+
11
+ if model
12
+ model.stripe_object = stripe_object
13
+ model.assign_from_stripe(stripe_object)
14
+ model.save! if model.changed?
15
+ else
16
+ model = model_class.create_from_stripe!(stripe_object)
17
+ end
18
+
19
+ succeed!(model: model)
20
+ end
21
+
22
+ def model_class_name
23
+ @model_class_name ||= stripe_object.class.name.gsub("::", "")
24
+ end
25
+
26
+ def model_class
27
+ @model_class ||= model_class_name.safe_constantize
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ class StripeModelCallbacks::TaxRate::UpdatedService < StripeModelCallbacks::BaseEventService
2
+ def perform
3
+ tax_rate.assign_from_stripe(object)
4
+
5
+ if tax_rate.save
6
+ create_activity if event
7
+ succeed! tax_rate
8
+ else
9
+ fail! tax_rate.errors.full_messages
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def create_activity
16
+ case event.type
17
+ when "tax_rate.created"
18
+ tax_rate.create_activity :created
19
+ when "tax_rate.updated"
20
+ tax_rate.create_activity :updated
21
+ end
22
+ end
23
+
24
+ def tax_rate
25
+ @tax_rate ||= StripeTaxRate.find_or_initialize_by(stripe_id: object.id)
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  class StripeModelCallbacks::Transfer::UpdatedService < StripeModelCallbacks::BaseEventService
2
- def execute
2
+ def perform
3
3
  transfer.assign_from_stripe(object)
4
4
 
5
5
  if transfer.save
@@ -0,0 +1,6 @@
1
+ class AddAutoAdvanceAndBillingReasonToStripeInvoices < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :stripe_invoices, :auto_advance, :boolean, default: false
4
+ add_column :stripe_invoices, :billing_reason, :string
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class AddStatusAndStatusTransitionsToStripeInvoices < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :stripe_invoices, :status, :string, default: "draft", nil: false
4
+
5
+ add_column :stripe_invoices, :finalized_at, :datetime
6
+ add_column :stripe_invoices, :marked_uncollectible_at, :datetime
7
+ add_column :stripe_invoices, :paid_at, :datetime
8
+ add_column :stripe_invoices, :voided_at, :datetime
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddProductTypeToProducts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :stripe_products, :product_type, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class RenameStripeInvoicesApplicationFeeToApplicationFeeAmount < ActiveRecord::Migration[6.0]
2
+ def change
3
+ rename_column :stripe_invoices, :application_fee_cents, :application_fee_amount_cents
4
+ rename_column :stripe_invoices, :application_fee_currency, :application_fee_amount_currency
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class MakeStripeInvoicesForgiveOptional < ActiveRecord::Migration[6.0]
2
+ def change
3
+ change_column_null :stripe_invoices, :forgiven, true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class MakeStripeInvoiceClosedOptional < ActiveRecord::Migration[6.0]
2
+ def change
3
+ change_column_null :stripe_invoices, :closed, true
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ class AddAmountPaidAndRemainingAndInvoiceUrlAndPdf < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :stripe_invoices, :amount_paid_cents, :integer
4
+ add_column :stripe_invoices, :amount_paid_currency, :string
5
+ add_column :stripe_invoices, :amount_remaining_cents, :integer
6
+ add_column :stripe_invoices, :amount_remaining_currency, :string
7
+ add_column :stripe_invoices, :collection_method, :string
8
+ add_column :stripe_invoices, :hosted_invoice_url, :string
9
+ add_column :stripe_invoices, :invoice_pdf, :string
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddUnitLabelToStripeProducts < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :stripe_products, :unit_label, :string
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class AddMeteredInfoToStripePlans < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :stripe_plans, :active, :boolean
4
+ add_column :stripe_plans, :aggregate_usage, :string
5
+ add_column :stripe_plans, :amount_decimal, :string
6
+ add_column :stripe_plans, :billing_scheme, :string
7
+ add_column :stripe_plans, :usage_type, :string
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ class CreateStripeSubscriptionSchedules < ActiveRecord::Migration[6.0]
2
+ def change # rubocop:disable Metrics/AbcSize
3
+ create_table :stripe_subscription_schedules do |t|
4
+ t.string :stripe_id, index: {unique: true}, null: false
5
+ t.string :billing
6
+ t.integer :billing_thresholds_amount_gte
7
+ t.boolean :billing_thresholds_reset_billing_cycle_anchor
8
+ t.timestamp :canceled_at
9
+ t.string :collection_method
10
+ t.timestamp :completed_at
11
+ t.datetime :created
12
+ t.datetime :current_phase_start_date
13
+ t.datetime :current_phase_end_date
14
+ t.string :stripe_customer_id, index: true
15
+ t.string :default_payment_method
16
+ t.string :default_source
17
+ t.string :end_behavior
18
+ t.integer :invoice_settings_days_until_due
19
+ t.boolean :livemode
20
+ t.text :metadata
21
+ t.datetime :released_at
22
+ t.string :released_stripe_subscription_id
23
+ t.string :renewal_behavior
24
+ t.string :renewal_interval
25
+ t.string :status
26
+ t.string :stripe_subscription_id, index: true
27
+
28
+ t.timestamps
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ class CreateStripeSubscriptionSchedulePhases < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :stripe_subscription_schedule_phases do |t|
4
+ t.string :stripe_subscription_schedule_id, index: {name: "index_subscription_schedule_phases_on_subscription_schedule_id"}, null: false
5
+ t.integer :application_fee_percent
6
+ t.integer :billing_thresholds_amount_gte
7
+ t.boolean :billing_thresholds_reset_billing_cycle_anchor
8
+ t.string :collection_method
9
+ t.string :stripe_coupon_id, index: true
10
+ t.string :default_payment_method
11
+ t.datetime :end_date
12
+ t.integer :invoice_settings_days_until_due
13
+ t.boolean :prorate
14
+ t.string :proration_behavior
15
+ t.datetime :start_date
16
+ t.datetime :trial_end
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ class CreateStripeSubscriptionSchedulePhasePlans < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :stripe_subscription_schedule_phase_plans do |t|
4
+ t.string :stripe_subscription_schedule_phase_id, index: {name: "index_subscription_schedule_phase_plans_on_schedule_phase_id"}, null: false
5
+ t.integer :billing_thresholds_usage_gte
6
+ t.string :stripe_plan_id, index: {name: "index_subscription_schedule_phase_plans_on_stripe_plan_id"}
7
+ t.string :stripe_price_id, index: {name: "index_subscription_schedule_phase_plans_on_stripe_price_id"}
8
+ t.integer :quantity
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ class AddStripeIdUniqToStripeInvoices < ActiveRecord::Migration[6.0]
2
+ disable_ddl_transaction!
3
+
4
+ def change
5
+ remove_index(:stripe_invoices, :stripe_id)
6
+ add_index(:stripe_invoices, :stripe_id, unique: true)
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ class ChangeStripeSubscriptionSchedulePhaseIdToBigint < ActiveRecord::Migration[6.0]
2
+ def change
3
+ if postgres?
4
+ change_column(
5
+ :stripe_subscription_schedule_phase_plans,
6
+ :stripe_subscription_schedule_phase_id,
7
+ "bigint USING stripe_subscription_schedule_phase_id::bigint"
8
+ )
9
+ elsif mysql?
10
+ change_column(
11
+ :stripe_subscription_schedule_phase_plans,
12
+ :stripe_subscription_schedule_phase_id,
13
+ "bigint USING CAST(stripe_subscription_schedule_phase_id AS bigint"
14
+ )
15
+ else
16
+ change_column :stripe_subscription_schedule_phase_plans, :stripe_subscription_schedule_phase_id, :bigint
17
+ end
18
+ end
19
+
20
+ def mysql?
21
+ ActiveRecord::Base.connection.adapter_name.downcase.include?("mysql")
22
+ end
23
+
24
+ def postgres?
25
+ %w[PostGIS Postgres].include?(ActiveRecord::Base.connection.adapter_name)
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ class AddLatestInvoiceIdToStripeSubscription < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_reference :stripe_subscriptions, :latest_stripe_invoice, type: :string, index: true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RenameStripeSubscriptionsStartToStartDate < ActiveRecord::Migration[6.0]
2
+ def change
3
+ rename_column :stripe_subscriptions, :start, :start_date
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class CreateStripeTaxRates < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :stripe_tax_rates do |t|
4
+ t.string :stripe_id, index: true, null: false
5
+ t.string :display_name
6
+ t.text :description
7
+ t.string :jurisdiction
8
+ t.float :percentage
9
+ t.boolean :inclusive
10
+ t.boolean :active
11
+ t.timestamp :created
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class CreateStripeSubscriptionDefaultTaxRates < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :stripe_subscription_default_tax_rates do |t|
4
+ t.references :stripe_subscription, foreign_key: true, index: {name: "index_on_subscription"}, null: false
5
+ t.references :stripe_tax_rate, foreign_key: true, index: {name: "index_on_tax_rate"}, null: false
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ class CreateStripePrices < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :stripe_prices do |t|
4
+ t.string :stripe_id, index: true, null: false
5
+ t.datetime :deleted_at
6
+ t.boolean :active
7
+ t.string :billing_scheme
8
+ t.datetime :created
9
+ t.string :currency
10
+ t.string :lookup_key
11
+ t.jsonb :metadata
12
+ t.string :nickname
13
+ t.string :stripe_product_id, index: true
14
+ t.boolean :recurring_aggregate_usage
15
+ t.string :recurring_interval
16
+ t.integer :recurring_interval_count
17
+ t.string :recurring_usage_type
18
+ t.string :tiers_mode
19
+ t.integer :transform_quantity_divide_by
20
+ t.string :transform_quantity_round
21
+ t.string :price_type
22
+ t.integer :unit_amount
23
+ t.timestamps
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ class AddStripePriceToStripeSubscriptionItems < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :stripe_subscription_items, :stripe_price_id, :string
4
+ add_index :stripe_subscription_items, :stripe_price_id
5
+ end
6
+ end
@@ -1,6 +1,6 @@
1
1
  class StripeModelCallbacks::Configuration
2
2
  def self.current
3
- @current ||= StripeModelCallbacks::Configuration.new
3
+ @current ||= new
4
4
  end
5
5
 
6
6
  def initialize
@@ -1,5 +1,21 @@
1
1
  FactoryBot.define do
2
2
  factory :stripe_coupon do
3
3
  sequence(:stripe_id) { |n| "stripe-coupon-#{n}" }
4
+
5
+ trait :with_stripe_mock do
6
+ duration { "repeating" }
7
+ duration_in_months { 1 }
8
+
9
+ after :create do |stripe_coupon|
10
+ mock_coupon = Stripe::Coupon.create(
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!
18
+ end
19
+ end
4
20
  end
5
21
  end
@@ -4,12 +4,14 @@ FactoryBot.define do
4
4
  amount_cents { 10_000 }
5
5
  amount_currency { "USD" }
6
6
  currency { "usd" }
7
- interval { "months" }
7
+ interval { "month" }
8
8
  interval_count { 1 }
9
9
  livemode { false }
10
10
  stripe_product
11
11
 
12
12
  trait :with_stripe_mock do
13
+ association :stripe_product, factory: [:stripe_product, :with_stripe_mock]
14
+
13
15
  after :create do |stripe_plan|
14
16
  mock_plan = Stripe::Plan.create(
15
17
  id: stripe_plan.stripe_id,
@@ -0,0 +1,3 @@
1
+ FactoryBot.define do
2
+ factory :stripe_price
3
+ end
@@ -1,5 +1,18 @@
1
1
  FactoryBot.define do
2
2
  factory :stripe_product do
3
+ sequence(:name) { |n| "Stripe product #{n}" }
3
4
  sequence(:stripe_id) { |n| "stripe-product-#{n}" }
5
+
6
+ trait :with_stripe_mock do
7
+ after :create do |stripe_product|
8
+ mock_product = Stripe::Product.create(
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!
15
+ end
16
+ end
4
17
  end
5
18
  end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :stripe_subscription_default_tax_rate do
3
+ stripe_subscription
4
+ stripe_tax_rate
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :stripe_subscription_schedule do
3
+ sequence(:stripe_id) { |n| "stripe-subscription-schedule-#{n}" }
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :stripe_subscription_schedule_phase_plan do
3
+ stripe_subscription_schedule_phase
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :stripe_subscription_schedule_phase do
3
+ stripe_subscription_schedule
4
+ end
5
+ end
@@ -9,7 +9,7 @@ FactoryBot.define do
9
9
  stripe_customer
10
10
  livemode { false }
11
11
  stripe_plan
12
- start { 1.month.ago.beginning_of_month }
12
+ start_date { 1.month.ago.beginning_of_month }
13
13
 
14
14
  trait :active do
15
15
  status { "active" }
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :stripe_tax_rate do
3
+ sequence(:stripe_id) { |n| "stripe-tax-rate-#{n}" }
4
+ end
5
+ end
@@ -0,0 +1,112 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "customer.subscription.created",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-02-06",
10
+ "data": {
11
+ "object": {
12
+ "id": "sub_00000000000000",
13
+ "object": "subscription",
14
+ "application_fee_percent": null,
15
+ "billing": "charge_automatically",
16
+ "billing_cycle_anchor": 1517764446,
17
+ "billing_thresholds": null,
18
+ "cancel_at": null,
19
+ "cancel_at_period_end": false,
20
+ "canceled_at": 1517764476,
21
+ "collection_method": "charge_automatically",
22
+ "created": 1517764446,
23
+ "current_period_end": 1520183646,
24
+ "current_period_start": 1517764446,
25
+ "customer": "cus_00000000000000",
26
+ "days_until_due": null,
27
+ "default_payment_method": null,
28
+ "default_source": null,
29
+ "default_tax_rates": [
30
+ {
31
+ "id": "txr_1I1qD2AT5SYrvIfd69tAvJe2",
32
+ "object": "tax_rate",
33
+ "active": true,
34
+ "created": 1608802452,
35
+ "description": null,
36
+ "display_name": "VAT DK",
37
+ "inclusive": false,
38
+ "jurisdiction": null,
39
+ "livemode": false,
40
+ "metadata": {},
41
+ "percentage": 25.0
42
+ }
43
+ ],
44
+ "discount": null,
45
+ "ended_at": 1517764476,
46
+ "invoice_customer_balance_settings": {
47
+ "consume_applied_balance_on_void": true
48
+ },
49
+ "items": {
50
+ "object": "list",
51
+ "data": [
52
+ {
53
+ "id": "si_00000000000000",
54
+ "object": "subscription_item",
55
+ "billing_thresholds": null,
56
+ "created": 1517764446,
57
+ "metadata": {
58
+ },
59
+ "price": {
60
+ "id": "large_00000000000000",
61
+ "object": "price",
62
+ "active": true,
63
+ "billing_scheme": "per_unit",
64
+ "created": 1517762943,
65
+ "currency": "dkk",
66
+ "livemode": false,
67
+ "lookup_key": null,
68
+ "metadata": {
69
+ },
70
+ "nickname": null,
71
+ "product": "prod_00000000000000",
72
+ "recurring": {
73
+ "aggregate_usage": null,
74
+ "interval": "month",
75
+ "interval_count": 1,
76
+ "usage_type": "licensed"
77
+ },
78
+ "tiers_mode": null,
79
+ "transform_quantity": null,
80
+ "type": "recurring",
81
+ "unit_amount": 10000,
82
+ "unit_amount_decimal": "10000"
83
+ },
84
+ "quantity": 1,
85
+ "subscription": "sub_00000000000000",
86
+ "tax_rates": [
87
+ ]
88
+ }
89
+ ],
90
+ "has_more": false,
91
+ "url": "/v1/subscription_items?subscription=sub_CGNpFmtIMKpiIN"
92
+ },
93
+ "latest_invoice": "in_1GoYq1J3a8kmO8fmMn28KIy2",
94
+ "livemode": false,
95
+ "metadata": {
96
+ },
97
+ "next_pending_invoice_item_invoice": null,
98
+ "pause_collection": null,
99
+ "pending_invoice_item_interval": null,
100
+ "pending_setup_intent": null,
101
+ "pending_update": null,
102
+ "schedule": null,
103
+ "start": 1517764446,
104
+ "start_date": 1517764446,
105
+ "status": "canceled",
106
+ "tax_percent": null,
107
+ "transfer_data": null,
108
+ "trial_end": null,
109
+ "trial_start": null
110
+ }
111
+ }
112
+ }
@@ -54,6 +54,7 @@
54
54
  "total_count": 1,
55
55
  "url": "/v1/subscription_items?subscription=sub_CGPXJjUMVXBLSx"
56
56
  },
57
+ "latest_invoice": "in_1GoYq1J3a8kmO8fmMn28KIy2",
57
58
  "livemode": false,
58
59
  "metadata": {
59
60
  },
@@ -47,7 +47,7 @@
47
47
  "trial_period_days": null
48
48
  },
49
49
  "quantity": 1,
50
- "subscription": "sub_CGPlqkdRaAAkq4"
50
+ "subscription": "sub_00000000000000"
51
51
  }
52
52
  ],
53
53
  "has_more": false,
@@ -58,7 +58,7 @@
58
58
  "metadata": {
59
59
  },
60
60
  "plan": {
61
- "id": "silver-express-898_00000000000000",
61
+ "id": "silver-express-898",
62
62
  "object": "plan",
63
63
  "amount": 999,
64
64
  "created": 1506381458,
@@ -73,7 +73,7 @@
73
73
  "trial_period_days": null
74
74
  },
75
75
  "quantity": 1,
76
- "start": 1517772172,
76
+ "start_date": 1517772172,
77
77
  "status": "active",
78
78
  "tax_percent": null,
79
79
  "trial_end": null,
@@ -14,7 +14,7 @@
14
14
  "account_balance": 0,
15
15
  "created": 1517772278,
16
16
  "currency": "usd",
17
- "default_source": null,
17
+ "default_source": "card_000000000",
18
18
  "delinquent": false,
19
19
  "description": null,
20
20
  "discount": null,
@@ -12,12 +12,16 @@
12
12
  "id": "in_00000000000000",
13
13
  "object": "invoice",
14
14
  "amount_due": 3500,
15
- "application_fee": null,
15
+ "amount_paid": 3500,
16
+ "amount_remaining": 0,
17
+ "application_fee_amount": null,
16
18
  "attempt_count": 1,
17
19
  "attempted": false,
20
+ "auto_advance": false,
18
21
  "billing": "charge_automatically",
22
+ "billing_reason": "subscription_create",
19
23
  "charge": "ch_00000000000000",
20
- "closed": true,
24
+ "collection_method": "charge_automatically",
21
25
  "currency": "dkk",
22
26
  "customer": "cus_00000000000000",
23
27
  "date": 1517763745,
@@ -25,7 +29,6 @@
25
29
  "discount": null,
26
30
  "due_date": null,
27
31
  "ending_balance": 0,
28
- "forgiven": false,
29
32
  "lines": {
30
33
  "data": [
31
34
  {
@@ -79,6 +82,13 @@
79
82
  "receipt_number": null,
80
83
  "starting_balance": 0,
81
84
  "statement_descriptor": null,
85
+ "status": "draft",
86
+ "status_transitions": {
87
+ "finalized_at": null,
88
+ "marked_uncollectible_at": null,
89
+ "paid_at": null,
90
+ "voided_at": null
91
+ },
82
92
  "subscription": "sub_00000000000000",
83
93
  "subtotal": 3500,
84
94
  "tax": null,