pay 6.6.1 → 6.7.1

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: 6ab0375b33bf0e7b915b73943996117c80c1c27698a0194dc061804edf18e200
4
- data.tar.gz: 50c1aea0c823cc6c1ed317fc1b9742c53b8ed9dfe0f8d8d7d580dbeb4b5b9008
3
+ metadata.gz: f6c599414b39eb92d44ee17f7ccb9de063c15eed29b0ea42d404f600df9966a8
4
+ data.tar.gz: 9d74f8b7307dfb0f5236c07356227dfb3f51dfa90e2e20a98beefa9a70d362a6
5
5
  SHA512:
6
- metadata.gz: c6e964209c442885544401a62dfe5669a26a9f04ffacbf3531a1ec6d3eb7bb97dfa2dc9298397abfa9aabe7547e54851369bbd96505ce08ec0a90f5d28358671
7
- data.tar.gz: e6749f6044b4075cd107d9cfb0b7739e9d60a7a55d9dac952520b1ddc71609e10825946395ab5271a19dcda07cb9e0703827864e6cf2dbbfe8eba0921bb1e26d
6
+ metadata.gz: b9b66934a36fedbd9bba2bbf01d3d4c97f32bf561d391919a980b3c95aa6ab59abcb0bf972c3f283707e8f578c329025525396f50a85e39a74572b7623467484
7
+ data.tar.gz: 7720adbb3990da1bb586a0be8f53d071ebce4bca693f37213b56a0987b8ecc865495abb56ad6ada95472e8af272bb07c407d14becdc346b16d9160358d76be78
@@ -13,7 +13,7 @@ module Pay
13
13
  # Ensure the back parameter is a valid path
14
14
  # This safely handles XSS or external redirects
15
15
  def set_redirect_to
16
- @redirect_to = URI.parse(params[:back].to_s).path || root_path
16
+ @redirect_to = URI.parse(params[:back].to_s).path.presence || root_path
17
17
  end
18
18
  end
19
19
  end
@@ -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, then secrets
13
- # 3. Check unscoped credentials, then secrets
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
@@ -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 = pay_customer.customer.invoice_settings.default_payment_method)
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
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.6.1"
2
+ VERSION = "6.7.1"
3
3
  end
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.6.1
4
+ version: 6.7.1
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-06-02 00:00:00.000000000 Z
13
+ date: 2023-07-28 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.13
171
+ rubygems_version: 3.4.17
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Payments engine for Ruby on Rails