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.
- checksums.yaml +4 -4
- data/README.md +14 -0
- 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 +33 -1
- 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/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/lib/stripe_model_callbacks/configuration.rb +1 -1
- data/lib/stripe_model_callbacks/factories/stripe_coupons.rb +16 -0
- data/lib/stripe_model_callbacks/factories/stripe_plans.rb +3 -1
- data/lib/stripe_model_callbacks/factories/stripe_prices.rb +3 -0
- data/lib/stripe_model_callbacks/factories/stripe_products.rb +13 -0
- data/lib/stripe_model_callbacks/factories/stripe_subscription_default_tax_rates.rb +6 -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 +1 -1
- data/lib/stripe_model_callbacks/factories/stripe_tax_rates.rb +5 -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 +1 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.deleted.json +2 -2
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.updated.json +1 -1
- data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.updated.json +1 -1
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.created.json +13 -3
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_failed.json +14 -4
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.payment_succeeded.json +23 -4
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.sent.json +13 -3
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.upcoming.json +13 -3
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.updated.json +13 -3
- data/lib/stripe_model_callbacks/fixtures/stripe_events/invoice/invoice.voided.json +152 -0
- data/lib/stripe_model_callbacks/fixtures/stripe_events/plan/plan.created.json +7 -2
- 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 +1 -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/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 +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
|
@@ -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
|
@@ -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 { "
|
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,
|
@@ -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,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
|
+
}
|
data/lib/stripe_model_callbacks/fixtures/stripe_events/customer/customer.subscription.deleted.json
CHANGED
@@ -47,7 +47,7 @@
|
|
47
47
|
"trial_period_days": null
|
48
48
|
},
|
49
49
|
"quantity": 1,
|
50
|
-
"subscription": "
|
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-
|
61
|
+
"id": "silver-express-898",
|
62
62
|
"object": "plan",
|
63
63
|
"amount": 999,
|
64
64
|
"created": 1506381458,
|
@@ -12,12 +12,16 @@
|
|
12
12
|
"id": "in_00000000000000",
|
13
13
|
"object": "invoice",
|
14
14
|
"amount_due": 3500,
|
15
|
-
"
|
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
|
-
"
|
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,
|