pay 6.7.1 → 6.8.0

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: f6c599414b39eb92d44ee17f7ccb9de063c15eed29b0ea42d404f600df9966a8
4
- data.tar.gz: 9d74f8b7307dfb0f5236c07356227dfb3f51dfa90e2e20a98beefa9a70d362a6
3
+ metadata.gz: de3a99204ee0e081f59774da0369b8e820a8d1fb33d810871dbc62ec009012c1
4
+ data.tar.gz: 19bbcd3c80230b270b2fc60338d410d6ceb37e2dc9466d1674f8552ecbdf46e9
5
5
  SHA512:
6
- metadata.gz: b9b66934a36fedbd9bba2bbf01d3d4c97f32bf561d391919a980b3c95aa6ab59abcb0bf972c3f283707e8f578c329025525396f50a85e39a74572b7623467484
7
- data.tar.gz: 7720adbb3990da1bb586a0be8f53d071ebce4bca693f37213b56a0987b8ecc865495abb56ad6ada95472e8af272bb07c407d14becdc346b16d9160358d76be78
6
+ metadata.gz: 0f504f26b84e856d1fd241e61537f1203539b76f58f9af69a768316e97e710ff24b5a79ac2179a1c335d5691283dc9e097476e696b1551ec212046f8dd97f026
7
+ data.tar.gz: 87e4ae3cc89868ed3faa76e3a73b0aaba568c87d33e7c1c003619c4fc69887edcce7fab67f3c40cb57924423a4f9c0b2328cebf1491164ae975c79f586fa7cb9
@@ -1,7 +1,9 @@
1
1
  class CreatePayTables < ActiveRecord::Migration[6.0]
2
2
  def change
3
- create_table :pay_customers do |t|
4
- t.belongs_to :owner, polymorphic: true, index: false
3
+ primary_key_type, foreign_key_type = primary_and_foreign_key_types
4
+
5
+ create_table :pay_customers, id: primary_key_type do |t|
6
+ t.belongs_to :owner, polymorphic: true, index: false, type: foreign_key_type
5
7
  t.string :processor, null: false
6
8
  t.string :processor_id
7
9
  t.boolean :default
@@ -12,8 +14,8 @@ class CreatePayTables < ActiveRecord::Migration[6.0]
12
14
  add_index :pay_customers, [:owner_type, :owner_id, :deleted_at, :default], name: :pay_customer_owner_index
13
15
  add_index :pay_customers, [:processor, :processor_id], unique: true
14
16
 
15
- create_table :pay_merchants do |t|
16
- t.belongs_to :owner, polymorphic: true, index: false
17
+ create_table :pay_merchants, id: primary_key_type do |t|
18
+ t.belongs_to :owner, polymorphic: true, index: false, type: foreign_key_type
17
19
  t.string :processor, null: false
18
20
  t.string :processor_id
19
21
  t.boolean :default
@@ -22,8 +24,8 @@ class CreatePayTables < ActiveRecord::Migration[6.0]
22
24
  end
23
25
  add_index :pay_merchants, [:owner_type, :owner_id, :processor]
24
26
 
25
- create_table :pay_payment_methods do |t|
26
- t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false
27
+ create_table :pay_payment_methods, id: primary_key_type do |t|
28
+ t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type
27
29
  t.string :processor_id, null: false
28
30
  t.boolean :default
29
31
  t.string :type
@@ -32,8 +34,8 @@ class CreatePayTables < ActiveRecord::Migration[6.0]
32
34
  end
33
35
  add_index :pay_payment_methods, [:customer_id, :processor_id], unique: true
34
36
 
35
- create_table :pay_subscriptions do |t|
36
- t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false
37
+ create_table :pay_subscriptions, id: primary_key_type do |t|
38
+ t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type
37
39
  t.string :name, null: false
38
40
  t.string :processor_id, null: false
39
41
  t.string :processor_plan, null: false
@@ -56,9 +58,9 @@ class CreatePayTables < ActiveRecord::Migration[6.0]
56
58
  add_index :pay_subscriptions, [:metered]
57
59
  add_index :pay_subscriptions, [:pause_starts_at]
58
60
 
59
- create_table :pay_charges do |t|
60
- t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false
61
- t.belongs_to :subscription, foreign_key: {to_table: :pay_subscriptions}, null: true
61
+ create_table :pay_charges, id: primary_key_type do |t|
62
+ t.belongs_to :customer, foreign_key: {to_table: :pay_customers}, null: false, index: false, type: foreign_key_type
63
+ t.belongs_to :subscription, foreign_key: {to_table: :pay_subscriptions}, null: true, type: foreign_key_type
62
64
  t.string :processor_id, null: false
63
65
  t.integer :amount, null: false
64
66
  t.string :currency
@@ -70,11 +72,21 @@ class CreatePayTables < ActiveRecord::Migration[6.0]
70
72
  end
71
73
  add_index :pay_charges, [:customer_id, :processor_id], unique: true
72
74
 
73
- create_table :pay_webhooks do |t|
75
+ create_table :pay_webhooks, id: primary_key_type do |t|
74
76
  t.string :processor
75
77
  t.string :event_type
76
78
  t.public_send Pay::Adapter.json_column_type, :event
77
79
  t.timestamps
78
80
  end
79
81
  end
82
+
83
+ private
84
+
85
+ def primary_and_foreign_key_types
86
+ config = Rails.configuration.generators
87
+ setting = config.options[config.orm][:primary_key_type]
88
+ primary_key_type = setting || :primary_key
89
+ foreign_key_type = setting || :bigint
90
+ [primary_key_type, foreign_key_type]
91
+ end
80
92
  end
@@ -5,11 +5,11 @@ module Pay
5
5
  module Webhooks
6
6
  class SubscriptionChargedUnsuccessfully
7
7
  def call(event)
8
- subscription = event.subscription
9
- return if subscription.nil?
8
+ # subscription = event.subscription
9
+ # return if subscription.nil?
10
10
 
11
- pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
- return unless pay_subscription.present?
11
+ # pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
+ # return unless pay_subscription.present?
13
13
 
14
14
  # pay_customer = pay_subscription.customer
15
15
  # pay_charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
@@ -77,20 +77,17 @@ module Pay
77
77
  )
78
78
  end
79
79
 
80
+ # Charges an amount to the customer's default payment method
80
81
  def charge(amount, options = {})
81
82
  add_payment_method(payment_method_token, default: true) if payment_method_token?
82
83
 
83
84
  payment_method = pay_customer.default_payment_method
84
85
  args = {
85
- amount: amount,
86
86
  confirm: true,
87
- currency: "usd",
88
- customer: processor_id,
89
- expand: ["latest_charge.refunds"],
90
87
  payment_method: payment_method&.processor_id
91
88
  }.merge(options)
92
89
 
93
- payment_intent = ::Stripe::PaymentIntent.create(args, stripe_options)
90
+ payment_intent = create_payment_intent(amount, args)
94
91
  Pay::Payment.new(payment_intent).validate
95
92
 
96
93
  charge = payment_intent.latest_charge
@@ -99,6 +96,24 @@ module Pay
99
96
  raise Pay::Stripe::Error, e
100
97
  end
101
98
 
99
+ # Creates and returns a Stripe::PaymentIntent
100
+ def create_payment_intent(amount, options = {})
101
+ args = {
102
+ amount: amount,
103
+ currency: "usd",
104
+ customer: processor_id,
105
+ expand: ["latest_charge.refunds"],
106
+ return_url: root_url
107
+ }.merge(options)
108
+
109
+ ::Stripe::PaymentIntent.create(args, stripe_options)
110
+ end
111
+
112
+ # Used for creating Stripe Terminal charges
113
+ def terminal_charge(amount, options = {})
114
+ create_payment_intent(amount, options.merge(payment_method_types: ["card_present"], capture_method: "manual"))
115
+ end
116
+
102
117
  def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
103
118
  quantity = options.delete(:quantity)
104
119
  opts = {
@@ -209,12 +224,15 @@ module Pay
209
224
  customer unless processor_id?
210
225
  args = {
211
226
  customer: processor_id,
212
- mode: "payment",
213
- # These placeholder URLs will be replaced in a following step.
214
- success_url: merge_session_id_param(options.delete(:success_url) || root_url),
215
- cancel_url: merge_session_id_param(options.delete(:cancel_url) || root_url)
227
+ mode: "payment"
216
228
  }
217
229
 
230
+ # Embedded checkouts cannot use URLs
231
+ if options[:ui_mode] != "embedded"
232
+ args[:success_url] = merge_session_id_param(options.delete(:success_url) || root_url)
233
+ args[:cancel_url] = merge_session_id_param(options.delete(:cancel_url) || root_url)
234
+ end
235
+
218
236
  # Line items are optional
219
237
  if (line_items = options.delete(:line_items))
220
238
  quantity = options.delete(:quantity) || 1
data/lib/pay/stripe.rb CHANGED
@@ -30,6 +30,8 @@ module Pay
30
30
 
31
31
  extend Env
32
32
 
33
+ REQUIRED_VERSION = "~> 9"
34
+
33
35
  # A list of database model names that include Pay
34
36
  # Used for safely looking up models with client_reference_id
35
37
  mattr_accessor :model_names, default: Set.new
@@ -37,12 +39,12 @@ module Pay
37
39
  def self.enabled?
38
40
  return false unless Pay.enabled_processors.include?(:stripe) && defined?(::Stripe)
39
41
 
40
- Pay::Engine.version_matches?(required: "~> 8", current: ::Stripe::VERSION) || (raise "[Pay] stripe gem must be version ~> 8")
42
+ Pay::Engine.version_matches?(required: REQUIRED_VERSION, current: ::Stripe::VERSION) || (raise "[Pay] stripe gem must be version #{REQUIRED_VERSION}")
41
43
  end
42
44
 
43
45
  def self.setup
44
46
  ::Stripe.api_key = private_key
45
- ::Stripe.api_version = "2022-11-15"
47
+ ::Stripe.api_version ||= "2023-08-16"
46
48
 
47
49
  # Used by Stripe to identify Pay for support
48
50
  ::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
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.7.1"
2
+ VERSION = "6.8.0"
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.7.1
4
+ version: 6.8.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-07-28 00:00:00.000000000 Z
13
+ date: 2023-08-22 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.17
171
+ rubygems_version: 3.4.19
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Payments engine for Ruby on Rails