pay 6.3.1 → 6.3.3

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: 6bd608f9c9d71623d2c9caab7377cc9bd370fb0c88edf5771b63e4ee13c1d4ee
4
- data.tar.gz: '082e316367a83d6152de5fbe31e98dd57a42c2ea32004d1f1cc364afbad6a628'
3
+ metadata.gz: 3dd5d8face3b7594984198d04cef9783a8b2ef213961a6eb44211fd9144d3f06
4
+ data.tar.gz: fdf8774b97c605f1a1ade9ce50bbc4ce43c86a94d0aa361afe30b6438face5b9
5
5
  SHA512:
6
- metadata.gz: 1b430133c1e930e1cd730e51ae6f87658f62901021e1a02215d6a05550a600e82c5d24399e7a148730334a56cc01cd9cdc49693d3f97f9b8655ba80fa34db224
7
- data.tar.gz: 6a6250a620a86a714aa6cf72b0b5433dbe4fc27c7e603452623d1d1d799335c9570af37a9452c1ef381263eab50aef7cffbc7059897f35d942590478484f7863
6
+ metadata.gz: a4b3921d316db733b60c841a4ebb9e16fe64ddd9e0581d832fd376feb5badf6e94e0aff348c0f3c11abb61e1dbda21f79fbe3a6f957dc9bcf958c4a9e86467dc
7
+ data.tar.gz: 80ca7cd637ca444b74a76af17bc682f96cf446ebe4cac043dc677d8e5b24d81a0e0721afee3455c7d2af942a6374ad8599f056f7f055fce72606f00e8765ca88
@@ -2,9 +2,18 @@ module Pay
2
2
  class PaymentsController < ApplicationController
3
3
  layout "pay/application"
4
4
 
5
+ before_action :set_redirect_to
6
+
5
7
  def show
6
- @redirect_to = params[:back].presence || root_path
7
8
  @payment = Payment.from_id(params[:id])
8
9
  end
10
+
11
+ private
12
+
13
+ # Ensure the back parameter is a valid path
14
+ # This safely handles XSS or external redirects
15
+ def set_redirect_to
16
+ @redirect_to = URI.parse(params[:back].to_s).path || root_path
17
+ end
9
18
  end
10
19
  end
@@ -13,8 +13,6 @@ module Pay
13
13
  validates :processor, presence: true
14
14
  validates :processor_id, allow_blank: true, uniqueness: {scope: :processor, case_sensitive: true}
15
15
 
16
- attribute :plan, :string
17
- attribute :quantity, :integer
18
16
  attribute :payment_method_token, :string
19
17
 
20
18
  # Account(s) for marketplace payments
@@ -83,12 +83,13 @@ module Pay
83
83
  trial_ends_at?
84
84
  end
85
85
 
86
+ # Does not include the last second of the trial
86
87
  def on_trial?
87
- trial_ends_at? && trial_ends_at.after?(Time.current)
88
+ trial_ends_at? && trial_ends_at > Time.current
88
89
  end
89
90
 
90
91
  def trial_ended?
91
- trial_ends_at? && trial_ends_at.before?(Time.current)
92
+ trial_ends_at? && trial_ends_at <= Time.current
92
93
  end
93
94
 
94
95
  def canceled?
@@ -100,11 +101,11 @@ module Pay
100
101
  end
101
102
 
102
103
  def ended?
103
- ends_at? && Time.current.after?(ends_at)
104
+ ends_at? && ends_at <= Time.current
104
105
  end
105
106
 
106
107
  def on_grace_period?
107
- (ends_at? && Time.current < ends_at) ||
108
+ (ends_at? && ends_at > Time.current) ||
108
109
  ((status == "paused" || pause_behavior == "void") && will_pause?)
109
110
  end
110
111
 
@@ -162,7 +163,7 @@ module Pay
162
163
 
163
164
  def swap_and_invoice(plan)
164
165
  swap(plan)
165
- owner.invoice!(subscription_id: processor_id)
166
+ customer.invoice!(subscription: processor_id)
166
167
  end
167
168
 
168
169
  def processor_subscription(**options)
@@ -54,7 +54,7 @@
54
54
  </div>
55
55
  <% end %>
56
56
 
57
- <%= link_to t("pay.back"), @redirect_to, class: "inline-block w-full px-4 py-3 bg-gray-100 hover:bg-gray-200 text-center text-gray-600 rounded-lg" %>
57
+ <%= sanitize link_to(t("pay.back"), @redirect_to, class: "inline-block w-full px-4 py-3 bg-gray-100 hover:bg-gray-200 text-center text-gray-600 rounded-lg") %>
58
58
  </div>
59
59
 
60
60
  <p class="text-center text-gray-500 text-sm">
@@ -66,7 +66,7 @@
66
66
  <script type="module">
67
67
  window.stripe = Stripe('<%= Pay::Stripe.public_key %>');
68
68
 
69
- import { Application, Controller } from 'https://cdn.skypack.dev/@hotwired/stimulus'
69
+ import { Application, Controller } from 'https://unpkg.com/@hotwired/stimulus'
70
70
  const application = Application.start()
71
71
 
72
72
  application.register('payment-intent', class extends Controller {
data/lib/pay/env.rb CHANGED
@@ -11,6 +11,14 @@ module Pay
11
11
  # 1. Check environment variable
12
12
  # 2. Check environment scoped credentials, then secrets
13
13
  # 3. Check unscoped credentials, then secrets
14
+ #
15
+ # For example, find_value_by_name("stripe", "private_key") will check the following in order until it finds a value:
16
+ #
17
+ # ENV["STRIPE_PRIVATE_KEY"]
18
+ # Rails.application.credentials.dig(:production, :stripe, :private_key)
19
+ # Rails.application.secrets.dig(:production, :stripe, :private_key)
20
+ # Rails.application.credentials.dig(:stripe, :private_key)
21
+ # Rails.application.secrets.dig(:stripe, :private_key)
14
22
  def find_value_by_name(scope, name)
15
23
  ENV["#{scope.upcase}_#{name.upcase}"] ||
16
24
  credentials&.dig(env, scope, name) ||
@@ -19,8 +19,9 @@ module Pay
19
19
  pay_customer
20
20
  end
21
21
 
22
- def update_customer!
23
- # pass
22
+ def update_customer!(**attributes)
23
+ # return customer to fake an update
24
+ customer
24
25
  end
25
26
 
26
27
  def charge(amount, options = {})
@@ -56,6 +57,8 @@ module Pay
56
57
  attributes[:trial_ends_at] = trial_period_days.to_i.days.from_now
57
58
  end
58
59
 
60
+ attributes.delete(:promotion_code)
61
+
59
62
  pay_customer.subscriptions.create!(attributes)
60
63
  end
61
64
 
@@ -257,7 +257,7 @@ module Pay
257
257
  proration_behavior: proration_behavior,
258
258
  trial_end: (on_trial? ? trial_ends_at.to_i : "now"),
259
259
  quantity: quantity
260
- }.merge(expand_options),
260
+ }.merge(expand_options).merge(options),
261
261
  stripe_options
262
262
  )
263
263
 
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.3.1"
2
+ VERSION = "6.3.3"
3
3
  end
data/lib/pay.rb CHANGED
@@ -3,7 +3,8 @@ require "pay/engine"
3
3
  require "pay/errors"
4
4
  require "pay/adapter"
5
5
 
6
- require "active_support/dependencies"
6
+ require "action_mailer"
7
+ require "active_support"
7
8
 
8
9
  module Pay
9
10
  autoload :Attributes, "pay/attributes"
@@ -38,7 +39,7 @@ module Pay
38
39
  mattr_accessor :support_email
39
40
 
40
41
  def self.support_email=(value)
41
- @@support_email = value.is_a?(Mail::Address) ? value : Mail::Address.new(value)
42
+ @@support_email = value.is_a?(::Mail::Address) ? value : ::Mail::Address.new(value)
42
43
  end
43
44
 
44
45
  mattr_accessor :automount_routes
@@ -95,10 +96,10 @@ module Pay
95
96
  # Should return String or Array of email recipients
96
97
  mattr_accessor :mail_to
97
98
  @@mail_to = -> {
98
- if ActionMailer::Base.respond_to?(:email_address_with_name)
99
- ActionMailer::Base.email_address_with_name(params[:pay_customer].email, params[:pay_customer].customer_name)
99
+ if ::ActionMailer::Base.respond_to?(:email_address_with_name)
100
+ ::ActionMailer::Base.email_address_with_name(params[:pay_customer].email, params[:pay_customer].customer_name)
100
101
  else
101
- Mail::Address.new.tap do |builder|
102
+ ::Mail::Address.new.tap do |builder|
102
103
  builder.address = params[:pay_customer].email
103
104
  builder.display_name = params[:pay_customer].customer_name.presence
104
105
  end.to_s
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.3.1
4
+ version: 6.3.3
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-01-13 00:00:00.000000000 Z
13
+ date: 2023-04-21 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.3
171
+ rubygems_version: 3.4.12
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Payments engine for Ruby on Rails