stripe_model_callbacks 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/app/services/stripe_model_callbacks/charge/updated_service.rb +0 -7
  3. data/app/services/stripe_model_callbacks/configure_service.rb +9 -0
  4. data/db/migrate/20200520152604_change_stripe_subscription_schedule_phase_id_to_bigint.rb +1 -1
  5. data/db/migrate/20201224122058_create_stripe_prices.rb +11 -1
  6. data/db/migrate/20221223095244_rename_stripe_customers_account_balance_to_balance.rb +5 -0
  7. data/db/migrate/20230129142139_add_tax_rate_to_stripe_tax_rates.rb +5 -0
  8. data/db/migrate/20230129145312_add_country_to_stripe_tax_rates.rb +5 -0
  9. data/lib/stripe_model_callbacks/engine.rb +1 -1
  10. data/lib/stripe_model_callbacks/factories/stripe_customers.rb +1 -1
  11. data/lib/stripe_model_callbacks/factories/stripe_plans.rb +0 -1
  12. data/lib/stripe_model_callbacks/fixtures/stripe_events/charge/charge.refunded.json +0 -22
  13. data/lib/stripe_model_callbacks/fixtures/stripe_events/refund/refund.created.json +28 -0
  14. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.created.json +3 -1
  15. data/lib/stripe_model_callbacks/fixtures/stripe_events/tax_rate/tax_rate.updated.json +3 -1
  16. data/lib/stripe_model_callbacks/models/stripe_customer.rb +10 -1
  17. data/lib/stripe_model_callbacks/models/stripe_plan.rb +1 -0
  18. data/lib/stripe_model_callbacks/models/stripe_price.rb +2 -0
  19. data/lib/stripe_model_callbacks/models/stripe_source.rb +2 -0
  20. data/lib/stripe_model_callbacks/models/stripe_subscription.rb +1 -0
  21. data/lib/stripe_model_callbacks/models/stripe_tax_rate.rb +1 -1
  22. data/lib/stripe_model_callbacks/version.rb +1 -1
  23. metadata +7 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42089c7d894f5caccf7893fe4cb02f580e8a4cfbb6a72ba465894c5ebfb090f4
4
- data.tar.gz: 9be3e19bc9f6028312f9449704a79f232b86053961f61770ae36a679e93b183e
3
+ metadata.gz: ba7a4cb71e7f2d449a43ac85eeb6c61f086fdc7858ec55b88cb3a04fdae79af4
4
+ data.tar.gz: ed0262077e01beaf939e3b42f35e9b2a812b89ab22fa52b1d98c51445bb8d256
5
5
  SHA512:
6
- metadata.gz: 80831241dc6bebde63eb620b78c4c10cf2701e66867da8339f77ffcad40d8306126c7e84084980679929f7f765e3ba00bc3ddc78a9ba26fda82ba4a9528ff7d0
7
- data.tar.gz: dc731f5bed637ed10b1beac0205b1199c5cf3a787d5139f30d38b0ff3d70aa86e0fe8557fe9bffeec55eef147e58b96ccffed3b27a8ab9f23043a7b9076768fe
6
+ metadata.gz: db828818fb5d9e4110dd8e4517da60d7e384cbfdc2a945cb0639c31aff8576dc957827b18745dfd1c127cfa070e291c82b45c10e0470ed37defdbf0efece86bd
7
+ data.tar.gz: 8150383579159ce6f3936ed2b06e38e94d2dd87d5f112c508b6f3634e7a08aae38362c41c4bd89274ce1a70808c8d2894fb0d7625b273bb30e2584d0ed5f94b1
@@ -3,7 +3,6 @@ class StripeModelCallbacks::Charge::UpdatedService < StripeModelCallbacks::BaseE
3
3
  charge.assign_from_stripe(object)
4
4
 
5
5
  if charge.save
6
- create_refunds if event.type == "charge.refunded"
7
6
  create_activity
8
7
  succeed!
9
8
  else
@@ -31,10 +30,4 @@ private
31
30
  charge.create_activity :succeeded
32
31
  end
33
32
  end
34
-
35
- def create_refunds
36
- object.refunds.each do |stripe_refund|
37
- StripeModelCallbacks::Refund::UpdatedService.reported_execute!(object: stripe_refund)
38
- end
39
- end
40
33
  end
@@ -24,6 +24,7 @@ class StripeModelCallbacks::ConfigureService < StripeModelCallbacks::BaseEventSe
24
24
  plan_events
25
25
  price_events
26
26
  product_events
27
+ refund_events
27
28
  review_events
28
29
  sku_events
29
30
  source_events
@@ -155,6 +156,14 @@ private
155
156
  end
156
157
  end
157
158
 
159
+ def refund_events
160
+ %w[created updated].each do |refund_event|
161
+ subscribe "refund.#{refund_event}" do |event|
162
+ StripeModelCallbacks::Refund::UpdatedService.execute_with_advisory_lock!(event: event)
163
+ end
164
+ end
165
+ end
166
+
158
167
  def plan_events
159
168
  %w[created deleted updated].each do |plan_event|
160
169
  subscribe "plan.#{plan_event}" do |event|
@@ -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
@@ -0,0 +1,5 @@
1
+ class AddTaxRateToStripeTaxRates < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :stripe_tax_rates, :tax_type, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddCountryToStripeTaxRates < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :stripe_tax_rates, :country, :string
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
@@ -38,28 +38,6 @@
38
38
  "receipt_email": null,
39
39
  "receipt_number": null,
40
40
  "refunded": true,
41
- "refunds": {
42
- "object": "list",
43
- "data": [
44
- {
45
- "id": "re_CGQ7INZZQPOC8U",
46
- "object": "refund",
47
- "amount": 100,
48
- "balance_transaction": "txn_CGQ7Sq2yeAIYK4",
49
- "charge": "ch_1BrtHZAT5SYrvIfdqkyvLyvX",
50
- "created": 1517772969,
51
- "currency": "usd",
52
- "metadata": {
53
- },
54
- "reason": null,
55
- "receipt_number": "1527-1121",
56
- "status": "succeeded"
57
- }
58
- ],
59
- "has_more": false,
60
- "total_count": 0,
61
- "url": "/v1/charges/ch_1BrtHZAT5SYrvIfdqkyvLyvX/refunds"
62
- },
63
41
  "review": null,
64
42
  "shipping": null,
65
43
  "source": {
@@ -0,0 +1,28 @@
1
+ {
2
+ "created": 1326853478,
3
+ "livemode": false,
4
+ "id": "evt_00000000000000",
5
+ "type": "refund.created",
6
+ "object": "event",
7
+ "request": null,
8
+ "pending_webhooks": 1,
9
+ "api_version": "2018-01-23",
10
+ "data": {
11
+ "object": {
12
+ "id": "re_CGQ7INZZQPOC8U",
13
+ "object": "refund",
14
+ "amount": 100,
15
+ "balance_transaction": "txn_CGQ7Sq2yeAIYK4",
16
+ "charge": "ch_3MI7uIIICJxvfdbR0gVMAA5h",
17
+ "created": 1675958030,
18
+ "currency": "dkk",
19
+ "metadata": {},
20
+ "payment_intent": null,
21
+ "reason": null,
22
+ "receipt_number": "1527-1121",
23
+ "source_transfer_reversal": null,
24
+ "status": "succeeded",
25
+ "transfer_reversal": null
26
+ }
27
+ }
28
+ }
@@ -12,6 +12,7 @@
12
12
  "id": "txr_00000000000000",
13
13
  "object": "tax_rate",
14
14
  "active": true,
15
+ "country": "DE",
15
16
  "created": 1608755171,
16
17
  "description": "VAT Germany",
17
18
  "display_name": "VAT",
@@ -20,7 +21,8 @@
20
21
  "livemode": false,
21
22
  "metadata": {
22
23
  },
23
- "percentage": 16
24
+ "percentage": 16,
25
+ "tax_type": "vat"
24
26
  }
25
27
  }
26
28
  }
@@ -12,6 +12,7 @@
12
12
  "id": "txr_00000000000000",
13
13
  "object": "tax_rate",
14
14
  "active": true,
15
+ "country": "DE",
15
16
  "created": 1608755201,
16
17
  "description": "VAT Germany",
17
18
  "display_name": "VAT",
@@ -20,7 +21,8 @@
20
21
  "livemode": false,
21
22
  "metadata": {
22
23
  },
23
- "percentage": 16
24
+ "percentage": 16,
25
+ "tax_type": "vat"
24
26
  },
25
27
  "previous_attributes": {
26
28
  "display_name": "Old name"
@@ -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"
@@ -16,7 +16,7 @@ class StripeTaxRate < StripeModelCallbacks::ApplicationRecord
16
16
  StripeModelCallbacks::AttributesAssignerService.execute!(
17
17
  model: self,
18
18
  stripe_model: object,
19
- attributes: %w[display_name description jurisdiction percentage inclusive]
19
+ attributes: ["active", "country", "display_name", "description", "jurisdiction", "percentage", "inclusive", "tax_type"]
20
20
  )
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module StripeModelCallbacks
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.7".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.7
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-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -122,34 +122,6 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 4.6.0
125
- - !ruby/object:Gem::Dependency
126
- name: appraisal
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: pry
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
125
  description: Framework for getting Stripe webhook callbacks directly to your models
154
126
  email:
155
127
  - kaspernj@gmail.com
@@ -256,6 +228,9 @@ files:
256
228
  - db/migrate/20201224123838_add_stripe_price_to_stripe_subscription_items.rb
257
229
  - db/migrate/20211121155313_change_invoice_billing_to_nullable.rb
258
230
  - db/migrate/20211121155732_rename_invoices_billing_to_deprecated_billing.rb
231
+ - db/migrate/20221223095244_rename_stripe_customers_account_balance_to_balance.rb
232
+ - db/migrate/20230129142139_add_tax_rate_to_stripe_tax_rates.rb
233
+ - db/migrate/20230129145312_add_country_to_stripe_tax_rates.rb
259
234
  - lib/stripe_model_callbacks.rb
260
235
  - lib/stripe_model_callbacks/autoload_models.rb
261
236
  - lib/stripe_model_callbacks/configuration.rb
@@ -347,6 +322,7 @@ files:
347
322
  - lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.created.json
348
323
  - lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.deleted.json
349
324
  - lib/stripe_model_callbacks/fixtures/stripe_events/recipient/recipient.updated.json
325
+ - lib/stripe_model_callbacks/fixtures/stripe_events/refund/refund.created.json
350
326
  - lib/stripe_model_callbacks/fixtures/stripe_events/review/review.closed.json
351
327
  - lib/stripe_model_callbacks/fixtures/stripe_events/review/review.opened.json
352
328
  - lib/stripe_model_callbacks/fixtures/stripe_events/sku/sku.created.json
@@ -416,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
416
392
  - !ruby/object:Gem::Version
417
393
  version: '0'
418
394
  requirements: []
419
- rubygems_version: 3.2.32
395
+ rubygems_version: 3.3.7
420
396
  signing_key:
421
397
  specification_version: 4
422
398
  summary: Framework for getting Stripe webhook callbacks directly to your models