pay 5.0.0 → 5.0.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pay might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/models/pay/customer.rb +9 -8
- data/lib/pay/stripe/subscription.rb +10 -3
- data/lib/pay/stripe.rb +1 -1
- data/lib/pay/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c607f5486ae4c1dfbf46b492e1a369e89e763e03e43bb25596882396285a416a
|
4
|
+
data.tar.gz: cbe12e5104c4cc18c9edc0a3d2ecf99f2d9d3adad431e4868747625f4934e6ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae0b3f32f96f2efcc5618df5b158397e1d6d1c6c79ee2109bb806628da2c53d998d8090fb7c9d7b2055a7ba660960b8ae4a36a6e6c4da54a943b4cd7020adae2
|
7
|
+
data.tar.gz: 356ba70d14722f9b083f366a957c26809082ce14193d7e4ec09350cf4c232de8dd215736b8c5968166d5659a8d9235df90104cc9367654b94e8905a09cfcdb77
|
data/app/models/pay/customer.rb
CHANGED
@@ -8,6 +8,7 @@ module Pay
|
|
8
8
|
|
9
9
|
scope :active, -> { where(deleted_at: nil) }
|
10
10
|
scope :deleted, -> { where.not(deleted_at: nil) }
|
11
|
+
scope :not_fake_processor, -> { where.not(processor: :fake_processor) }
|
11
12
|
|
12
13
|
validates :processor, presence: true
|
13
14
|
validates :processor_id, allow_blank: true, uniqueness: {scope: :processor, case_sensitive: true}
|
@@ -23,6 +24,14 @@ module Pay
|
|
23
24
|
delegate :email, to: :owner
|
24
25
|
delegate_missing_to :pay_processor
|
25
26
|
|
27
|
+
%w[stripe braintree paddle fake_processor].each do |processor_name|
|
28
|
+
scope processor_name, -> { where(processor: processor_name) }
|
29
|
+
|
30
|
+
define_method "#{processor_name}?" do
|
31
|
+
processor == processor_name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
26
35
|
def self.pay_processor_for(name)
|
27
36
|
"Pay::#{name.to_s.classify}::Billable".constantize
|
28
37
|
end
|
@@ -83,13 +92,5 @@ module Pay
|
|
83
92
|
# If these match, consider it a generic trial
|
84
93
|
subscription.trial_ends_at == subscription.ends_at
|
85
94
|
end
|
86
|
-
|
87
|
-
%w[stripe braintree paddle fake_processor].each do |processor_name|
|
88
|
-
scope processor_name, -> { where(processor: processor_name) }
|
89
|
-
|
90
|
-
define_method "#{processor_name}?" do
|
91
|
-
processor == processor_name
|
92
|
-
end
|
93
|
-
end
|
94
95
|
end
|
95
96
|
end
|
@@ -153,7 +153,7 @@ module Pay
|
|
153
153
|
# For a subscription with a single item, we can update the subscription directly if no SubscriptionItem ID is available
|
154
154
|
# Otherwise a SubscriptionItem ID is required so Stripe knows which entry to update
|
155
155
|
def change_quantity(quantity, **options)
|
156
|
-
subscription_item_id = options.fetch(:subscription_item_id, subscription_items
|
156
|
+
subscription_item_id = options.fetch(:subscription_item_id, subscription_items&.first&.dig("id"))
|
157
157
|
if subscription_item_id
|
158
158
|
::Stripe::SubscriptionItem.update(subscription_item_id, options.merge(quantity: quantity), stripe_options)
|
159
159
|
@stripe_subscription = nil
|
@@ -240,16 +240,23 @@ module Pay
|
|
240
240
|
# create_usage_record(quantity: 4, action: :increment)
|
241
241
|
# create_usage_record(subscription_item_id: "si_1234", quantity: 100, action: :set)
|
242
242
|
def create_usage_record(**options)
|
243
|
-
subscription_item_id = options.fetch(:subscription_item_id,
|
243
|
+
subscription_item_id = options.fetch(:subscription_item_id, metered_subscription_item&.dig("id"))
|
244
244
|
::Stripe::SubscriptionItem.create_usage_record(subscription_item_id, options, stripe_options)
|
245
245
|
end
|
246
246
|
|
247
247
|
# Returns usage record summaries for a subscription item
|
248
248
|
def usage_record_summaries(**options)
|
249
|
-
subscription_item_id = options.fetch(:subscription_item_id,
|
249
|
+
subscription_item_id = options.fetch(:subscription_item_id, metered_subscription_item&.dig("id"))
|
250
250
|
::Stripe::SubscriptionItem.list_usage_record_summaries(subscription_item_id, options, stripe_options)
|
251
251
|
end
|
252
252
|
|
253
|
+
# Returns the first metered subscription item
|
254
|
+
def metered_subscription_item
|
255
|
+
subscription_items.find do |subscription_item|
|
256
|
+
subscription_item.dig("price", "recurring", "usage_type") == "metered"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
253
260
|
# Returns an upcoming invoice for a subscription
|
254
261
|
def upcoming_invoice(**options)
|
255
262
|
::Stripe::Invoice.upcoming(options.merge(subscription: processor_id), stripe_options)
|
data/lib/pay/stripe.rb
CHANGED
@@ -36,7 +36,7 @@ module Pay
|
|
36
36
|
|
37
37
|
def self.setup
|
38
38
|
::Stripe.api_key = private_key
|
39
|
-
::Stripe.api_version = "2022-08-
|
39
|
+
::Stripe.api_version = "2022-08-01"
|
40
40
|
|
41
41
|
# Used by Stripe to identify Pay for support
|
42
42
|
::Stripe.set_app_info("PayRails", partner_id: "pp_partner_IqhY0UExnJYLxg", version: Pay::VERSION, url: "https://github.com/pay-rails/pay")
|
data/lib/pay/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Charnes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-08-
|
12
|
+
date: 2022-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|