pay 6.3.1 → 6.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bd608f9c9d71623d2c9caab7377cc9bd370fb0c88edf5771b63e4ee13c1d4ee
4
- data.tar.gz: '082e316367a83d6152de5fbe31e98dd57a42c2ea32004d1f1cc364afbad6a628'
3
+ metadata.gz: 5edf40fbd4c73316121bba2d278819cac41f0f4bb6000bc8d216d000fcac59ff
4
+ data.tar.gz: b93a89d4c256ac814bc133f7b2b5071220187006623eeff76000c3a829780577
5
5
  SHA512:
6
- metadata.gz: 1b430133c1e930e1cd730e51ae6f87658f62901021e1a02215d6a05550a600e82c5d24399e7a148730334a56cc01cd9cdc49693d3f97f9b8655ba80fa34db224
7
- data.tar.gz: 6a6250a620a86a714aa6cf72b0b5433dbe4fc27c7e603452623d1d1d799335c9570af37a9452c1ef381263eab50aef7cffbc7059897f35d942590478484f7863
6
+ metadata.gz: e81185537e0d87f658fbf8a27b4e44f7d9942bef953a61ac8f94de2e005bd81625e43970a355fac38c27133f65e08f31067b4d5c62de7fe25bb05b1457d26538
7
+ data.tar.gz: 673fc7acfe41d96f3ef829279f89e4c9c831f6637ea57cd927acf40206fc1f42bd75b645ceb4b2a9b27cf29a91057c577b0c144408e739baa9d9bdea1c462d9c
@@ -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
 
@@ -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
 
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.3.1"
2
+ VERSION = "6.3.2"
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.2
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-19 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