pay 6.6.1 → 6.7.0
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/app/models/pay/customer.rb +4 -0
- data/lib/pay/env.rb +5 -6
- data/lib/pay/stripe/billable.rb +1 -1
- data/lib/pay/stripe/webhooks/customer_updated.rb +11 -1
- data/lib/pay/stripe.rb +1 -1
- data/lib/pay/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e567d11b06b8b9a612a7e7caee9d9fddc5f4198a01c5c0ddff1a317e4d0975d7
|
4
|
+
data.tar.gz: 7a8bed12ce361bbe0abee836aba840600daa0465be8fbe058a11050fbe19e5fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0cb64ba729edfc532dceb8f4d1de0fea3d31305e2316cf1bfbba2e795bac8ead3926200f66d49b4b474d4f715542ed6e78ccd8ec19d4d9a9e3c004a377fe81
|
7
|
+
data.tar.gz: 169195c2a8d6bc6dc5f13d3ca709afb820ced2549290bc8f83750814554935deed134f4e5dd8876026031d126818616ac7168789e6d0a43de50321f2c442aa97
|
data/app/models/pay/customer.rb
CHANGED
@@ -19,6 +19,10 @@ module Pay
|
|
19
19
|
store_accessor :data, :stripe_account
|
20
20
|
store_accessor :data, :braintree_account
|
21
21
|
|
22
|
+
# Stripe invoice credit balance is a Hash-like object { "usd" => 1234 }
|
23
|
+
store_accessor :data, :invoice_credit_balance
|
24
|
+
store_accessor :data, :currency
|
25
|
+
|
22
26
|
delegate :email, to: :owner
|
23
27
|
delegate_missing_to :pay_processor
|
24
28
|
|
data/lib/pay/env.rb
CHANGED
@@ -9,21 +9,20 @@ module Pay
|
|
9
9
|
# the current environment.
|
10
10
|
#
|
11
11
|
# 1. Check environment variable
|
12
|
-
# 2. Check environment scoped credentials
|
13
|
-
# 3. Check unscoped credentials
|
12
|
+
# 2. Check environment scoped credentials
|
13
|
+
# 3. Check unscoped credentials
|
14
|
+
# 4. Check scoped and unscoped secrets (removed in Rails 7.2)
|
14
15
|
#
|
15
16
|
# For example, find_value_by_name("stripe", "private_key") will check the following in order until it finds a value:
|
16
17
|
#
|
17
18
|
# ENV["STRIPE_PRIVATE_KEY"]
|
18
19
|
# Rails.application.credentials.dig(:production, :stripe, :private_key)
|
19
|
-
# Rails.application.secrets.dig(:production, :stripe, :private_key)
|
20
20
|
# Rails.application.credentials.dig(:stripe, :private_key)
|
21
|
-
# Rails.application.secrets.dig(:stripe, :private_key)
|
22
21
|
def find_value_by_name(scope, name)
|
23
22
|
ENV["#{scope.upcase}_#{name.upcase}"] ||
|
24
23
|
credentials&.dig(env, scope, name) ||
|
25
|
-
secrets&.dig(env, scope, name) ||
|
26
24
|
credentials&.dig(scope, name) ||
|
25
|
+
secrets&.dig(env, scope, name) ||
|
27
26
|
secrets&.dig(scope, name)
|
28
27
|
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
29
28
|
Rails.logger.error <<~MESSAGE
|
@@ -40,7 +39,7 @@ module Pay
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def secrets
|
43
|
-
Rails.application.secrets
|
42
|
+
Rails.application.secrets if Rails.application.respond_to?(:secrets)
|
44
43
|
end
|
45
44
|
|
46
45
|
def credentials
|
data/lib/pay/stripe/billable.rb
CHANGED
@@ -49,7 +49,7 @@ module Pay
|
|
49
49
|
# Returns a Stripe::Customer object
|
50
50
|
def customer
|
51
51
|
stripe_customer = if processor_id?
|
52
|
-
::Stripe::Customer.retrieve({id: processor_id, expand: ["tax"]}, stripe_options)
|
52
|
+
::Stripe::Customer.retrieve({id: processor_id, expand: ["tax", "invoice_credit_balance"]}, stripe_options)
|
53
53
|
else
|
54
54
|
sc = ::Stripe::Customer.create(customer_attributes.merge(expand: ["tax"]), stripe_options)
|
55
55
|
pay_customer.update!(processor_id: sc.id, stripe_account: stripe_account)
|
@@ -9,14 +9,24 @@ module Pay
|
|
9
9
|
# Couldn't find user, we can skip
|
10
10
|
return unless pay_customer.present?
|
11
11
|
|
12
|
+
stripe_customer = pay_customer.customer
|
13
|
+
|
12
14
|
# Sync default card
|
13
|
-
if (payment_method_id =
|
15
|
+
if (payment_method_id = stripe_customer.invoice_settings.default_payment_method)
|
14
16
|
Pay::Stripe::PaymentMethod.sync(payment_method_id, stripe_account: event.try(:account))
|
15
17
|
|
16
18
|
else
|
17
19
|
# No default payment method set
|
18
20
|
pay_customer.payment_methods.update_all(default: false)
|
19
21
|
end
|
22
|
+
|
23
|
+
# Sync invoice credit balance and currency
|
24
|
+
if stripe_customer.invoice_credit_balance.present?
|
25
|
+
pay_customer.update(
|
26
|
+
invoice_credit_balance: stripe_customer.invoice_credit_balance,
|
27
|
+
currency: stripe_customer.currency
|
28
|
+
)
|
29
|
+
end
|
20
30
|
end
|
21
31
|
end
|
22
32
|
end
|
data/lib/pay/stripe.rb
CHANGED
@@ -98,7 +98,7 @@ module Pay
|
|
98
98
|
# When a customers subscription trial period is 3 days from ending or ended immediately this event is fired
|
99
99
|
events.subscribe "stripe.customer.subscription.trial_will_end", Pay::Stripe::Webhooks::SubscriptionTrialWillEnd.new
|
100
100
|
|
101
|
-
# Monitor changes for customer's default card changing
|
101
|
+
# Monitor changes for customer's default card changing and invoice credit updates
|
102
102
|
events.subscribe "stripe.customer.updated", Pay::Stripe::Webhooks::CustomerUpdated.new
|
103
103
|
|
104
104
|
# If a customer was deleted in Stripe, their subscriptions should be cancelled
|
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: 6.
|
4
|
+
version: 6.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Charnes
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
rubygems_version: 3.4.
|
171
|
+
rubygems_version: 3.4.17
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: Payments engine for Ruby on Rails
|