stripe_model_callbacks 0.1.0 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/app/models/stripe_model_callbacks/application_record.rb +17 -0
- data/app/services/stripe_model_callbacks/account/external_account/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/attributes_assigner_service.rb +1 -1
- data/app/services/stripe_model_callbacks/base_service.rb +35 -3
- data/app/services/stripe_model_callbacks/charge/dispute_updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/charge/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/configure_service.rb +52 -24
- data/app/services/stripe_model_callbacks/coupon/sync_all.rb +9 -0
- data/app/services/stripe_model_callbacks/coupon/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/customer/bank_account/deleted_service.rb +1 -1
- data/app/services/stripe_model_callbacks/customer/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 +1 -1
- data/app/services/stripe_model_callbacks/customer/subscription/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/customer/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/event_mocker_service.rb +1 -1
- data/app/services/stripe_model_callbacks/invoice/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/invoice_item/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/notifier_service.rb +1 -1
- data/app/services/stripe_model_callbacks/order/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/payout/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/plan/sync_all.rb +9 -0
- data/app/services/stripe_model_callbacks/plan/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/price/updated_service.rb +14 -0
- 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/refund/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/review/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/sku/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/source/updated_service.rb +1 -1
- data/app/services/stripe_model_callbacks/subscription/state_checker_service.rb +2 -2
- data/app/services/stripe_model_callbacks/subscription_schedule/updated_service.rb +46 -0
- data/app/services/stripe_model_callbacks/sync_everything.rb +8 -0
- data/app/services/stripe_model_callbacks/sync_from_stripe.rb +29 -0
- data/app/services/stripe_model_callbacks/tax_rate/updated_service.rb +27 -0
- data/app/services/stripe_model_callbacks/transfer/updated_service.rb +1 -1
- data/db/migrate/20200317160513_add_auto_advance_and_billing_reason_to_stripe_invoices.rb +6 -0
- data/db/migrate/20200317160602_add_status_and_status_transitions_to_stripe_invoices.rb +10 -0
- data/db/migrate/20200317180115_add_product_type_to_products.rb +5 -0
- data/db/migrate/20200317181224_rename_stripe_invoices_application_fee_to_application_fee_amount.rb +6 -0
- data/db/migrate/20200320105158_make_stripe_invoices_forgive_optional.rb +5 -0
- data/db/migrate/20200320114859_make_stripe_invoice_closed_optional.rb +5 -0
- data/db/migrate/20200323143634_add_amount_paid_and_remaining_and_invoice_url_and_pdf.rb +11 -0
- data/db/migrate/20200331074940_add_unit_label_to_stripe_products.rb +5 -0
- data/db/migrate/20200331075241_add_metered_info_to_stripe_plans.rb +9 -0
- data/db/migrate/20200513131105_create_stripe_subscription_schedules.rb +31 -0
- data/db/migrate/20200513131120_create_stripe_subscription_schedule_phases.rb +21 -0
- data/db/migrate/20200513131640_create_stripe_subscription_schedule_phase_plans.rb +13 -0
- data/db/migrate/20200514132247_add_stripe_id_uniq_to_stripe_invoices.rb +8 -0
- data/db/migrate/20200520152604_change_stripe_subscription_schedule_phase_id_to_bigint.rb +27 -0
- data/db/migrate/20200529144649_add_latest_invoice_id_to_stripe_subscription.rb +5 -0
- data/db/migrate/20201223173035_rename_stripe_subscriptions_start_to_start_date.rb +5 -0
- data/db/migrate/20201223202117_create_stripe_tax_rates.rb +15 -0
- data/db/migrate/20201224120534_create_stripe_subscription_default_tax_rates.rb +9 -0
- data/db/migrate/20201224122058_create_stripe_prices.rb +26 -0
- data/db/migrate/20201224123838_add_stripe_price_to_stripe_subscription_items.rb +6 -0
- data/db/migrate/20211121155313_change_invoice_billing_to_nullable.rb +5 -0
- data/db/migrate/20211121155732_rename_invoices_billing_to_deprecated_billing.rb +5 -0
- data/lib/stripe_model_callbacks/configuration.rb +1 -1
- data/lib/stripe_model_callbacks/factories/stripe_bank_accounts.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_cards.rb +7 -0
- data/lib/stripe_model_callbacks/factories/stripe_charges.rb +11 -0
- data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +21 -0
- data/lib/stripe_model_callbacks/factories/stripe_customers.rb +17 -0
- data/lib/stripe_model_callbacks/factories/stripe_discounts.rb +6 -0
- data/lib/stripe_model_callbacks/factories/stripe_disputes.rb +7 -0
- data/lib/stripe_model_callbacks/factories/stripe_invoice_items.rb +11 -0
- data/lib/stripe_model_callbacks/factories/stripe_invoices.rb +16 -0
- data/lib/stripe_model_callbacks/factories/stripe_order_items.rb +8 -0
- data/lib/stripe_model_callbacks/factories/stripe_orders.rb +9 -0
- data/lib/stripe_model_callbacks/factories/stripe_payouts.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_plans.rb +30 -0
- data/lib/stripe_model_callbacks/factories/stripe_prices.rb +3 -0
- data/lib/stripe_model_callbacks/factories/stripe_products.rb +18 -0
- data/lib/stripe_model_callbacks/factories/stripe_recipients.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_refunds.rb +9 -0
- data/lib/stripe_model_callbacks/factories/stripe_reviews.rb +6 -0
- data/lib/stripe_model_callbacks/factories/stripe_skus.rb +7 -0
- data/lib/stripe_model_callbacks/factories/stripe_sources.rb +8 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_default_tax_rates.rb +6 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_items.rb +19 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule.rb.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phase_plan.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_schedule_phases.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscriptions.rb +40 -0
- data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +5 -0
- data/lib/stripe_model_callbacks/factories/stripe_transfers.rb +8 -0
- data/lib/stripe_model_callbacks/factory_bot_definitions.rb +1 -1
- data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.created.json +29 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.deleted.json +29 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/account/account.external_account.updated.json +31 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.closed.json +65 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.created.json +65 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.funds_reinstated.json +65 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.funds_withdrawn.json +65 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.dispute.updated.json +96 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refund.updated.json +28 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refunded.json +98 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.created.json +29 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.deleted.json +29 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/coupon/coupon.updated.json +31 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.bank_account.deleted.json +29 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.created.json +36 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.deleted.json +47 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.created.json +36 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.deleted.json +36 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.discount.updated.json +55 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.created.card.json +80 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.created.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.deleted.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.expiring.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.source.updated.json +56 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.2020-12-24.json +112 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.created.json +84 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.deleted.json +83 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.trial_will_end.json +88 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.updated.json +100 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.updated.json +50 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.created.json +135 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_failed.json +100 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_succeeded.json +207 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.sent.json +100 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +100 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.updated.json +105 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.voided.json +152 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoiceitem/invoiceitem.created.json +34 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/order/order.created.json +72 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/order/order.updated.json +74 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.canceled.json +35 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.created.json +35 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.failed.json +35 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.paid.json +35 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/payout/payout.updated.json +37 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.created.json +32 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.deleted.json +27 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.updated.json +30 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.created.json +37 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.deleted.json +37 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/price/price.updated.json +40 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.created.json +49 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.deleted.json +48 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/product/product.updated.json +50 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.created.json +37 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.deleted.json +37 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.updated.json +39 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/review/review.closed.json +21 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/review/review.opened.json +21 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.created.json +36 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.deleted.json +36 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.updated.json +38 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.canceled.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.chargeable.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.failed.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.mandate_notification.json +53 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/source/source.transaction_created.json +21 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.canceled.json +81 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.created.json +77 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/subscription_schedule/subscription_schedule.updated.json +87 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.created.json +26 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.updated.json +29 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.created.json +41 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.reversed.json +40 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/transfer/transfer.updated.json +44 -0
- data/lib/stripe_model_callbacks/models/stripe_bank_account.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_card.rb +2 -1
- data/lib/stripe_model_callbacks/models/stripe_charge.rb +3 -0
- data/lib/stripe_model_callbacks/models/stripe_coupon.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_customer.rb +4 -2
- data/lib/stripe_model_callbacks/models/stripe_discount.rb +10 -3
- data/lib/stripe_model_callbacks/models/stripe_dispute.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_invoice.rb +62 -7
- data/lib/stripe_model_callbacks/models/stripe_invoice_item.rb +2 -0
- data/lib/stripe_model_callbacks/models/stripe_order.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_order_item.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_payout.rb +2 -1
- data/lib/stripe_model_callbacks/models/stripe_plan.rb +4 -1
- data/lib/stripe_model_callbacks/models/stripe_price.rb +27 -0
- data/lib/stripe_model_callbacks/models/stripe_product.rb +17 -7
- data/lib/stripe_model_callbacks/models/stripe_recipient.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_refund.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_review.rb +1 -0
- data/lib/stripe_model_callbacks/models/stripe_sku.rb +13 -6
- data/lib/stripe_model_callbacks/models/stripe_source.rb +4 -2
- data/lib/stripe_model_callbacks/models/stripe_subscription.rb +56 -6
- data/lib/stripe_model_callbacks/models/stripe_subscription_default_tax_rate.rb +4 -0
- data/lib/stripe_model_callbacks/models/stripe_subscription_item.rb +19 -1
- data/lib/stripe_model_callbacks/models/stripe_subscription_schedule.rb +94 -0
- data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase.rb +67 -0
- data/lib/stripe_model_callbacks/models/stripe_subscription_schedule_phase_plan.rb +37 -0
- data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +22 -0
- data/lib/stripe_model_callbacks/models/stripe_transfer.rb +1 -0
- data/lib/stripe_model_callbacks/version.rb +1 -1
- data/lib/stripe_model_callbacks.rb +1 -0
- metadata +163 -11
@@ -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,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
|
@@ -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
|
data/db/migrate/20200317181224_rename_stripe_invoices_application_fee_to_application_fee_amount.rb
ADDED
@@ -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,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,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,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,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,21 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_coupon do
|
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
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_customer do
|
3
|
+
sequence(:stripe_id) { |n| "customer-identifier-#{n}" }
|
4
|
+
account_balance { 0 }
|
5
|
+
currency { "usd" }
|
6
|
+
delinquent { false }
|
7
|
+
livemode { false }
|
8
|
+
|
9
|
+
trait :with_stripe_mock do
|
10
|
+
after :create do |stripe_customer|
|
11
|
+
mock_customer = Stripe::Customer.create(source: StripeMock.create_test_helper.generate_card_token)
|
12
|
+
stripe_customer.assign_from_stripe(mock_customer)
|
13
|
+
stripe_customer.save!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_invoice_item do
|
3
|
+
sequence(:stripe_id) { |n| "stripe-invoice-item-#{n}" }
|
4
|
+
amount { Money.new(1_000, "USD") }
|
5
|
+
stripe_invoice
|
6
|
+
currency { "usd" }
|
7
|
+
discountable { false }
|
8
|
+
proration { false }
|
9
|
+
sequence(:description) { |n| "Test #{n}" }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_invoice do
|
3
|
+
sequence(:stripe_id) { |n| "stripe-invoice-#{n}" }
|
4
|
+
amount_due_cents { 0 }
|
5
|
+
amount_due_currency { "USD" }
|
6
|
+
attempted { false }
|
7
|
+
closed { false }
|
8
|
+
collection_method { "charge_automatically" }
|
9
|
+
created { 2.days.ago }
|
10
|
+
currency { "usd" }
|
11
|
+
forgiven { false }
|
12
|
+
livemode { false }
|
13
|
+
paid { false }
|
14
|
+
stripe_customer
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_plan do
|
3
|
+
sequence(:stripe_id) { |n| "stripe_plan_#{n}" }
|
4
|
+
amount_cents { 10_000 }
|
5
|
+
amount_currency { "USD" }
|
6
|
+
currency { "usd" }
|
7
|
+
interval { "month" }
|
8
|
+
interval_count { 1 }
|
9
|
+
livemode { false }
|
10
|
+
stripe_product
|
11
|
+
|
12
|
+
trait :with_stripe_mock do
|
13
|
+
association :stripe_product, factory: [:stripe_product, :with_stripe_mock]
|
14
|
+
|
15
|
+
after :create do |stripe_plan|
|
16
|
+
mock_plan = Stripe::Plan.create(
|
17
|
+
id: stripe_plan.stripe_id,
|
18
|
+
amount: stripe_plan.amount_cents,
|
19
|
+
currency: stripe_plan.currency,
|
20
|
+
name: "No name any more - waiting for Stripe mock to be updated",
|
21
|
+
interval: stripe_plan.interval,
|
22
|
+
interval_count: stripe_plan.interval_count,
|
23
|
+
product: stripe_plan.stripe_product.stripe_id
|
24
|
+
)
|
25
|
+
stripe_plan.assign_from_stripe(mock_plan)
|
26
|
+
stripe_plan.save!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :stripe_product do
|
3
|
+
sequence(:name) { |n| "Stripe product #{n}" }
|
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
|
17
|
+
end
|
18
|
+
end
|