stripe_model_callbacks 0.1.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -1
  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 +37 -4
  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/event_mocker_service.rb +1 -1
  19. data/app/services/stripe_model_callbacks/invoice/updated_service.rb +1 -1
  20. data/app/services/stripe_model_callbacks/invoice_item/updated_service.rb +1 -1
  21. data/app/services/stripe_model_callbacks/notifier_service.rb +1 -1
  22. data/app/services/stripe_model_callbacks/order/updated_service.rb +1 -1
  23. data/app/services/stripe_model_callbacks/payout/updated_service.rb +1 -1
  24. data/app/services/stripe_model_callbacks/plan/sync_all.rb +9 -0
  25. data/app/services/stripe_model_callbacks/plan/updated_service.rb +1 -1
  26. data/app/services/stripe_model_callbacks/price/updated_service.rb +14 -0
  27. data/app/services/stripe_model_callbacks/product/updated_service.rb +1 -1
  28. data/app/services/stripe_model_callbacks/recipient/updated_service.rb +1 -1
  29. data/app/services/stripe_model_callbacks/refund/updated_service.rb +1 -1
  30. data/app/services/stripe_model_callbacks/review/updated_service.rb +1 -1
  31. data/app/services/stripe_model_callbacks/sku/updated_service.rb +1 -1
  32. data/app/services/stripe_model_callbacks/source/updated_service.rb +1 -1
  33. data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +2 -2
  34. data/app/services/stripe_model_callbacks/subscription_schedule/updated_service.rb +46 -0
  35. data/app/services/stripe_model_callbacks/sync_everything.rb +8 -0
  36. data/app/services/stripe_model_callbacks/sync_from_stripe.rb +29 -0
  37. data/app/services/stripe_model_callbacks/tax_rate/updated_service.rb +27 -0
  38. data/app/services/stripe_model_callbacks/transfer/updated_service.rb +1 -1
  39. data/config/routes.rb +1 -1
  40. data/db/migrate/20180206151132_change_activities_trackable_id_to_string.rb +1 -1
  41. data/db/migrate/20180208091647_change_stripe_subscription_items_quantity_to_integer.rb +1 -1
  42. data/db/migrate/20200317160513_add_auto_advance_and_billing_reason_to_stripe_invoices.rb +6 -0
  43. data/db/migrate/20200317160602_add_status_and_status_transitions_to_stripe_invoices.rb +10 -0
  44. data/db/migrate/20200317180115_add_product_type_to_products.rb +5 -0
  45. data/db/migrate/20200317181224_rename_stripe_invoices_application_fee_to_application_fee_amount.rb +6 -0
  46. data/db/migrate/20200320105158_make_stripe_invoices_forgive_optional.rb +5 -0
  47. data/db/migrate/20200320114859_make_stripe_invoice_closed_optional.rb +5 -0
  48. data/db/migrate/20200323143634_add_amount_paid_and_remaining_and_invoice_url_and_pdf.rb +11 -0
  49. data/db/migrate/20200331074940_add_unit_label_to_stripe_products.rb +5 -0
  50. data/db/migrate/20200331075241_add_metered_info_to_stripe_plans.rb +9 -0
  51. data/db/migrate/20200513131105_create_stripe_subscription_schedules.rb +31 -0
  52. data/db/migrate/20200513131120_create_stripe_subscription_schedule_phases.rb +21 -0
  53. data/db/migrate/20200513131640_create_stripe_subscription_schedule_phase_plans.rb +13 -0
  54. data/db/migrate/20200514132247_add_stripe_id_uniq_to_stripe_invoices.rb +8 -0
  55. data/db/migrate/20200520152604_change_stripe_subscription_schedule_phase_id_to_bigint.rb +27 -0
  56. data/db/migrate/20200529144649_add_latest_invoice_id_to_stripe_subscription.rb +5 -0
  57. data/db/migrate/20201223173035_rename_stripe_subscriptions_start_to_start_date.rb +5 -0
  58. data/db/migrate/20201223202117_create_stripe_tax_rates.rb +15 -0
  59. data/db/migrate/20201224120534_create_stripe_subscription_default_tax_rates.rb +9 -0
  60. data/db/migrate/20201224122058_create_stripe_prices.rb +26 -0
  61. data/db/migrate/20201224123838_add_stripe_price_to_stripe_subscription_items.rb +6 -0
  62. data/db/migrate/20211121155313_change_invoice_billing_to_nullable.rb +5 -0
  63. data/db/migrate/20211121155732_rename_invoices_billing_to_deprecated_billing.rb +5 -0
  64. data/lib/stripe_model_callbacks/configuration.rb +1 -1
  65. data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +16 -0
  66. data/lib/stripe_model_callbacks/factories/stripe_invoices.rb +1 -1
  67. data/lib/stripe_model_callbacks/factories/stripe_plans.rb +3 -1
  68. data/lib/stripe_model_callbacks/factories/stripe_prices.rb +3 -0
  69. data/lib/stripe_model_callbacks/factories/stripe_products.rb +13 -0
  70. data/lib/stripe_model_callbacks/factories/stripe_subscription_default_tax_rates.rb +6 -0
  71. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule.rb.rb +5 -0
  72. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phase_plan.rb +5 -0
  73. data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phases.rb +5 -0
  74. data/lib/stripe_model_callbacks/factories/stripe_subscriptions.rb +1 -1
  75. data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +5 -0
  76. data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.created.json +29 -0
  77. data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.deleted.json +29 -0
  78. data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.updated.json +31 -0
  79. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.closed.json +65 -0
  80. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.created.json +65 -0
  81. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.funds_reinstated.json +65 -0
  82. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.funds_withdrawn.json +65 -0
  83. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.updated.json +96 -0
  84. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refund.updated.json +28 -0
  85. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refunded.json +98 -0
  86. data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.created.json +29 -0
  87. data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.deleted.json +29 -0
  88. data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.updated.json +31 -0
  89. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.bank_account.deleted.json +29 -0
  90. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.created.json +36 -0
  91. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.deleted.json +47 -0
  92. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.created.json +36 -0
  93. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.deleted.json +36 -0
  94. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.updated.json +55 -0
  95. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.created.card.json +80 -0
  96. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.created.json +53 -0
  97. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.deleted.json +53 -0
  98. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.expiring.json +53 -0
  99. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.updated.json +56 -0
  100. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.2020-12-24.json +112 -0
  101. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.json +84 -0
  102. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.deleted.json +83 -0
  103. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.trial_will_end.json +88 -0
  104. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.updated.json +100 -0
  105. data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.updated.json +50 -0
  106. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.created.json +135 -0
  107. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_failed.json +100 -0
  108. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_succeeded.json +207 -0
  109. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.sent.json +100 -0
  110. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +100 -0
  111. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.updated.json +105 -0
  112. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.voided.json +152 -0
  113. data/lib/stripe_model_callbacks/fixtures/stripe_events/invoiceitem/invoiceitem.created.json +34 -0
  114. data/lib/stripe_model_callbacks/fixtures/stripe_events/order/order.created.json +72 -0
  115. data/lib/stripe_model_callbacks/fixtures/stripe_events/order/order.updated.json +74 -0
  116. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.canceled.json +35 -0
  117. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.created.json +35 -0
  118. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.failed.json +35 -0
  119. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.paid.json +35 -0
  120. data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.updated.json +37 -0
  121. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.created.json +32 -0
  122. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.deleted.json +27 -0
  123. data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.updated.json +30 -0
  124. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.created.json +37 -0
  125. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.deleted.json +37 -0
  126. data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.updated.json +40 -0
  127. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.created.json +49 -0
  128. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.deleted.json +48 -0
  129. data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.updated.json +50 -0
  130. data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.created.json +37 -0
  131. data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.deleted.json +37 -0
  132. data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.updated.json +39 -0
  133. data/lib/stripe_model_callbacks/fixtures/stripe_events/review/review.closed.json +21 -0
  134. data/lib/stripe_model_callbacks/fixtures/stripe_events/review/review.opened.json +21 -0
  135. data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.created.json +36 -0
  136. data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.deleted.json +36 -0
  137. data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.updated.json +38 -0
  138. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.canceled.json +53 -0
  139. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.chargeable.json +53 -0
  140. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.failed.json +53 -0
  141. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.mandate_notification.json +53 -0
  142. data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.transaction_created.json +21 -0
  143. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.canceled.json +81 -0
  144. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.created.json +77 -0
  145. data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.updated.json +87 -0
  146. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.created.json +26 -0
  147. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.updated.json +29 -0
  148. data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.created.json +41 -0
  149. data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.reversed.json +40 -0
  150. data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.updated.json +44 -0
  151. data/lib/stripe_model_callbacks/models/stripe_bank_account.rb +1 -0
  152. data/lib/stripe_model_callbacks/models/stripe_card.rb +2 -1
  153. data/lib/stripe_model_callbacks/models/stripe_charge.rb +3 -0
  154. data/lib/stripe_model_callbacks/models/stripe_coupon.rb +1 -0
  155. data/lib/stripe_model_callbacks/models/stripe_customer.rb +4 -2
  156. data/lib/stripe_model_callbacks/models/stripe_discount.rb +10 -3
  157. data/lib/stripe_model_callbacks/models/stripe_dispute.rb +1 -0
  158. data/lib/stripe_model_callbacks/models/stripe_invoice.rb +62 -7
  159. data/lib/stripe_model_callbacks/models/stripe_invoice_item.rb +2 -0
  160. data/lib/stripe_model_callbacks/models/stripe_order.rb +1 -0
  161. data/lib/stripe_model_callbacks/models/stripe_order_item.rb +1 -0
  162. data/lib/stripe_model_callbacks/models/stripe_payout.rb +2 -1
  163. data/lib/stripe_model_callbacks/models/stripe_plan.rb +4 -1
  164. data/lib/stripe_model_callbacks/models/stripe_price.rb +27 -0
  165. data/lib/stripe_model_callbacks/models/stripe_product.rb +17 -7
  166. data/lib/stripe_model_callbacks/models/stripe_recipient.rb +1 -0
  167. data/lib/stripe_model_callbacks/models/stripe_refund.rb +1 -0
  168. data/lib/stripe_model_callbacks/models/stripe_review.rb +1 -0
  169. data/lib/stripe_model_callbacks/models/stripe_sku.rb +13 -6
  170. data/lib/stripe_model_callbacks/models/stripe_source.rb +4 -2
  171. data/lib/stripe_model_callbacks/models/stripe_subscription.rb +56 -6
  172. data/lib/stripe_model_callbacks/models/stripe_subscription_default_tax_rate.rb +4 -0
  173. data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +19 -1
  174. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +94 -0
  175. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase.rb +67 -0
  176. data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase_plan.rb +37 -0
  177. data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +22 -0
  178. data/lib/stripe_model_callbacks/models/stripe_transfer.rb +1 -0
  179. data/lib/stripe_model_callbacks/version.rb +1 -1
  180. data/lib/stripe_model_callbacks.rb +1 -0
  181. metadata +176 -24
  182. data/app/assets/config/stripe_model_callbacks_manifest.js +0 -2
  183. data/app/assets/javascripts/stripe_model_callbacks/application.js +0 -13
  184. data/app/assets/stylesheets/stripe_model_callbacks/application.css +0 -15
  185. data/app/controllers/stripe_model_callbacks/application_controller.rb +0 -3
  186. data/app/jobs/stripe_model_callbacks/application_job.rb +0 -2
  187. data/app/mailers/stripe_model_callbacks/application_mailer.rb +0 -4
  188. data/app/views/layouts/stripe_model_callbacks/application.html.erb +0 -14
@@ -0,0 +1,46 @@
1
+ class StripeModelCallbacks::SubscriptionSchedule::UpdatedService < StripeModelCallbacks::BaseEventService
2
+ TRACKED_ACTIVITIES = {
3
+ "subscription_schedule.canceled": :canceled
4
+ }.with_indifferent_access.freeze
5
+ private_constant :TRACKED_ACTIVITIES
6
+
7
+ def perform
8
+ subscription_schedule.assign_from_stripe(object)
9
+ set_cancellation_date if canceled?
10
+
11
+ return success_actions if subscription_schedule.save
12
+
13
+ fail!(subscription_schedule.errors.full_messages)
14
+ end
15
+
16
+ private
17
+
18
+ def canceled?
19
+ @canceled ||= event.type == "subscription_schedule.canceled"
20
+ end
21
+
22
+ def create_activity
23
+ return unless tracked_activities[event.type]
24
+
25
+ subscription_schedule.create_activity(tracked_activities[event.type])
26
+ end
27
+
28
+ def set_cancellation_date
29
+ return unless canceled?
30
+
31
+ subscription_schedule.canceled_at ||= Time.zone.now
32
+ end
33
+
34
+ def subscription_schedule
35
+ @subscription_schedule ||= StripeSubscriptionSchedule.find_or_initialize_by(stripe_id: object.id)
36
+ end
37
+
38
+ def success_actions
39
+ create_activity
40
+ succeed!
41
+ end
42
+
43
+ def tracked_activities
44
+ TRACKED_ACTIVITIES
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ class StripeModelCallbacks::SyncEverything < StripeModelCallbacks::BaseService
2
+ def perform
3
+ StripeModelCallbacks::Coupon::SyncAll.execute!
4
+ StripeModelCallbacks::Plan::SyncAll.execute!
5
+
6
+ succeed!
7
+ end
8
+ end
@@ -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
data/config/routes.rb CHANGED
@@ -1,2 +1,2 @@
1
- StripeModelCallbacks::Engine.routes.draw do
1
+ StripeModelCallbacks::Engine.routes.draw do # rubocop:disable Lint/EmptyBlock
2
2
  end
@@ -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
@@ -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( # rubocop:disable Rails/ReversibleMigration
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( # rubocop:disable Rails/ReversibleMigration
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 # rubocop:disable Rails/ReversibleMigration
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
@@ -0,0 +1,5 @@
1
+ class ChangeInvoiceBillingToNullable < ActiveRecord::Migration[6.1]
2
+ def change
3
+ change_column_null :stripe_invoices, :billing, true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RenameInvoicesBillingToDeprecatedBilling < ActiveRecord::Migration[6.1]
2
+ def change
3
+ rename_column :stripe_invoices, :billing, :billing_deprecated
4
+ end
5
+ 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,8 +4,8 @@ FactoryBot.define do
4
4
  amount_due_cents { 0 }
5
5
  amount_due_currency { "USD" }
6
6
  attempted { false }
7
- billing { "charge_automatically" }
8
7
  closed { false }
8
+ collection_method { "charge_automatically" }
9
9
  created { 2.days.ago }
10
10
  currency { "usd" }
11
11
  forgiven { false }
@@ -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,29 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "account.external_account.created",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-02-05",
10
+ "data": {
11
+ "object": {
12
+ "id": "ba_00000000000000",
13
+ "object": "bank_account",
14
+ "account": "acct_00000000000000",
15
+ "account_holder_name": "Jane Austen",
16
+ "account_holder_type": "individual",
17
+ "bank_name": "STRIPE TEST BANK",
18
+ "country": "US",
19
+ "currency": "dkk",
20
+ "default_for_currency": false,
21
+ "fingerprint": "8hxBTDA6RPbX37IN",
22
+ "last4": "6789",
23
+ "metadata": {
24
+ },
25
+ "routing_number": "110000000",
26
+ "status": "new"
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "account.external_account.deleted",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-02-05",
10
+ "data": {
11
+ "object": {
12
+ "id": "ba_00000000000000",
13
+ "object": "bank_account",
14
+ "account": "acct_00000000000000",
15
+ "account_holder_name": "Jane Austen",
16
+ "account_holder_type": "individual",
17
+ "bank_name": "STRIPE TEST BANK",
18
+ "country": "US",
19
+ "currency": "dkk",
20
+ "default_for_currency": false,
21
+ "fingerprint": "8hxBTDA6RPbX37IN",
22
+ "last4": "6789",
23
+ "metadata": {
24
+ },
25
+ "routing_number": "110000000",
26
+ "status": "new"
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "account.external_account.updated",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-02-05",
10
+ "data": {
11
+ "object": {
12
+ "id": "ba_00000000000000",
13
+ "object": "bank_account",
14
+ "account": "acct_00000000000000",
15
+ "account_holder_name": "Jane Austen",
16
+ "account_holder_type": "individual",
17
+ "bank_name": "STRIPE TEST BANK",
18
+ "country": "US",
19
+ "currency": "dkk",
20
+ "default_for_currency": false,
21
+ "fingerprint": "8hxBTDA6RPbX37IN",
22
+ "last4": "6789",
23
+ "metadata": {
24
+ },
25
+ "routing_number": "110000000",
26
+ "status": "new"
27
+ },
28
+ "previous_attributes": {
29
+ }
30
+ }
31
+ }