stripe_model_callbacks 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42089c7d894f5caccf7893fe4cb02f580e8a4cfbb6a72ba465894c5ebfb090f4
4
- data.tar.gz: 9be3e19bc9f6028312f9449704a79f232b86053961f61770ae36a679e93b183e
3
+ metadata.gz: 344d7a3dacb569caaadc32a2959cd2f740d493b3626fc6e3dabdc2f14bcf76f7
4
+ data.tar.gz: 30c78d0e6dfb2acb7baa4b7a0eb99aea7893f516717f863a465bdbc9d6ed0f5c
5
5
  SHA512:
6
- metadata.gz: 80831241dc6bebde63eb620b78c4c10cf2701e66867da8339f77ffcad40d8306126c7e84084980679929f7f765e3ba00bc3ddc78a9ba26fda82ba4a9528ff7d0
7
- data.tar.gz: dc731f5bed637ed10b1beac0205b1199c5cf3a787d5139f30d38b0ff3d70aa86e0fe8557fe9bffeec55eef147e58b96ccffed3b27a8ab9f23043a7b9076768fe
6
+ metadata.gz: b0def52a911f242f016c3994b973edfadde72c9dfe565615e4493302b63de32eb2f5f50fe88a86cdd1377261792f9ccd140d281e6ddb9e77625daff1d82cec66
7
+ data.tar.gz: 6dccf484db456f98641a84f71ae36cda7cb8ecfa96c68426d853ec99cf9c76dcaad2584e3f659bbf10a224e3c3205865719f90f6701e1aabf00efc03c00b4b73
@@ -10,7 +10,7 @@ class ChangeStripeSubscriptionSchedulePhaseIdToBigint < ActiveRecord::Migration[
10
10
  change_column( # rubocop:disable Rails/ReversibleMigration
11
11
  :stripe_subscription_schedule_phase_plans,
12
12
  :stripe_subscription_schedule_phase_id,
13
- "bigint USING CAST(stripe_subscription_schedule_phase_id AS bigint"
13
+ "bigint USING CAST(stripe_subscription_schedule_phase_id AS bigint)"
14
14
  )
15
15
  else
16
16
  change_column :stripe_subscription_schedule_phase_plans, :stripe_subscription_schedule_phase_id, :bigint # rubocop:disable Rails/ReversibleMigration
@@ -8,7 +8,13 @@ class CreateStripePrices < ActiveRecord::Migration[6.0]
8
8
  t.datetime :created
9
9
  t.string :currency
10
10
  t.string :lookup_key
11
- t.jsonb :metadata
11
+
12
+ if mysql?
13
+ t.json :metadata
14
+ else
15
+ t.jsonb :metadata
16
+ end
17
+
12
18
  t.string :nickname
13
19
  t.string :stripe_product_id, index: true
14
20
  t.boolean :recurring_aggregate_usage
@@ -23,4 +29,8 @@ class CreateStripePrices < ActiveRecord::Migration[6.0]
23
29
  t.timestamps
24
30
  end
25
31
  end
32
+
33
+ def mysql?
34
+ ActiveRecord::Base.connection.adapter_name.downcase.include?("mysql")
35
+ end
26
36
  end
@@ -0,0 +1,5 @@
1
+ class RenameStripeCustomersAccountBalanceToBalance < ActiveRecord::Migration[7.0]
2
+ def change
3
+ rename_column :stripe_customers, :account_balance, :balance
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module StripeModelCallbacks; end
2
2
 
3
- class StripeModelCallbacks::Engine < ::Rails::Engine
3
+ class StripeModelCallbacks::Engine < Rails::Engine
4
4
  isolate_namespace StripeModelCallbacks
5
5
  end
@@ -1,7 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :stripe_customer do
3
3
  sequence(:stripe_id) { |n| "customer-identifier-#{n}" }
4
- account_balance { 0 }
4
+ balance { 0 }
5
5
  currency { "usd" }
6
6
  delinquent { false }
7
7
  livemode { false }
@@ -17,7 +17,6 @@ FactoryBot.define do
17
17
  id: stripe_plan.stripe_id,
18
18
  amount: stripe_plan.amount_cents,
19
19
  currency: stripe_plan.currency,
20
- name: "No name any more - waiting for Stripe mock to be updated",
21
20
  interval: stripe_plan.interval,
22
21
  interval_count: stripe_plan.interval_count,
23
22
  product: stripe_plan.stripe_product.stripe_id
@@ -14,10 +14,19 @@ class StripeCustomer < StripeModelCallbacks::ApplicationRecord
14
14
 
15
15
  def assign_from_stripe(object)
16
16
  check_object_is_stripe_class(object)
17
+
18
+ if object.respond_to?(:account_balance)
19
+ self.balance = object.account_balance
20
+ elsif object.respond_to?(:balance)
21
+ self.balance = object.balance
22
+ else
23
+ Rails.logger.error "Couldn't figure out where to get the customers balance from"
24
+ end
25
+
17
26
  StripeModelCallbacks::AttributesAssignerService.execute!(
18
27
  model: self, stripe_model: object,
19
28
  attributes: %w[
20
- account_balance currency created default_source delinquent description discount email
29
+ currency created default_source delinquent description discount email
21
30
  id livemode metadata
22
31
  ]
23
32
  )
@@ -4,6 +4,7 @@ class StripePlan < StripeModelCallbacks::ApplicationRecord
4
4
  has_many :stripe_invoice_items, primary_key: "stripe_id"
5
5
  has_many :stripe_subscriptions, primary_key: "stripe_id"
6
6
  has_many :stripe_subscription_items, primary_key: "stripe_id"
7
+ has_many :stripe_subscription_schedule_phase_plans, primary_key: "stripe_id"
7
8
 
8
9
  scope :not_deleted, -> { where(deleted_at: nil) }
9
10
 
@@ -1,4 +1,6 @@
1
1
  class StripePrice < StripeModelCallbacks::ApplicationRecord
2
+ has_many :stripe_subscription_item, primary_key: "stripe_id"
3
+
2
4
  def self.stripe_class
3
5
  Stripe::Price
4
6
  end
@@ -1,4 +1,6 @@
1
1
  class StripeSource < StripeModelCallbacks::ApplicationRecord
2
+ has_many :stripe_charges, primary_key: "stripe_id"
3
+
2
4
  monetize :amount_cents, allow_nil: true
3
5
  monetize :receiver_amount_charged_cents, allow_nil: true
4
6
  monetize :receiver_amount_received_cents, allow_nil: true
@@ -3,6 +3,7 @@ class StripeSubscription < StripeModelCallbacks::ApplicationRecord
3
3
  belongs_to :stripe_discount, optional: true
4
4
  belongs_to :stripe_plan, optional: true, primary_key: "stripe_id"
5
5
  has_many :stripe_invoices, primary_key: "stripe_id"
6
+ has_many :stripe_invoice_items, primary_key: "stripe_id"
6
7
  has_many :stripe_discounts, primary_key: "stripe_id"
7
8
  has_many :stripe_subscription_default_tax_rates, autosave: true, dependent: :destroy
8
9
  has_many :stripe_subscription_items, autosave: true, primary_key: "stripe_id"
@@ -1,3 +1,3 @@
1
1
  module StripeModelCallbacks
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe_model_callbacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-01 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -256,6 +256,7 @@ files:
256
256
  - db/migrate/20201224123838_add_stripe_price_to_stripe_subscription_items.rb
257
257
  - db/migrate/20211121155313_change_invoice_billing_to_nullable.rb
258
258
  - db/migrate/20211121155732_rename_invoices_billing_to_deprecated_billing.rb
259
+ - db/migrate/20221223095244_rename_stripe_customers_account_balance_to_balance.rb
259
260
  - lib/stripe_model_callbacks.rb
260
261
  - lib/stripe_model_callbacks/autoload_models.rb
261
262
  - lib/stripe_model_callbacks/configuration.rb