pay 3.0.19 → 3.0.23

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pay might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '093c067bb867fddfbdb00486613ad7be4b9e1d3d0d5ff1e22ec3d892b6bb76b3'
4
- data.tar.gz: d4b53a841c0e7cae39f6c73786dbfbe20bc61c81dbbfe3885cbe2a0b0f830936
3
+ metadata.gz: 5755d6421fc4b0366728f278b32de2f9f1bf6186cafe4c62cf9c5a188204d0d6
4
+ data.tar.gz: 5a4cf13ffbdf85017401dd9aca4ddc3d7fd48fea249868ff10c04bfa383e39d1
5
5
  SHA512:
6
- metadata.gz: cee4d5e1b4ed8954e7004b121165c5e4b4dc69f5a39a01b4f9b90197ef4a8dc04cca5660488b7b2da2975a78d9cf0e5356cd30e84923af56e2460277c6c79979
7
- data.tar.gz: 261fdecca8eb33582d279ce18f76fe4c80e3efe5fb95c479549c8c4232e53b6096a69decd3915ac12fe7792035e14e88122ef35a459090b5f4e8a710588a2b80
6
+ metadata.gz: 966be7e8c643bb6bfa65f21d111d76e35d461a500630434f6b37907c9001f823ae3aa7193f763a7b0af76ef35806de91bd8acfaff1eef219972c8284a96835d3
7
+ data.tar.gz: b0dd861df1aa7cb64ab45b267de205251e4a8885a113219a0eb5c3d4fe087332fae129ca7fa1b619d7b75aef6a53698f1665d977c52a472a3d31bce90ff255d5
@@ -5,7 +5,7 @@ module Pay
5
5
  def perform(pay_customer_id)
6
6
  Pay::Customer.find(pay_customer_id).update_customer!
7
7
  rescue ActiveRecord::RecordNotFound
8
- Rails.logger.info "Couldn't find a #{class_name} with ID = #{id}"
8
+ Rails.logger.info "Couldn't find a Pay::Customer with ID = #{id}"
9
9
  end
10
10
  end
11
11
  end
@@ -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/stimulus'
69
+ import { Application, Controller } from 'https://cdn.skypack.dev/@hotwired/stimulus'
70
70
  const application = Application.start()
71
71
 
72
72
  application.register('payment-intent', class extends Controller {
@@ -10,7 +10,7 @@ Amount: <%= params[:charge].amount_with_currency %><br/>
10
10
  Charged to: <%= params[:charge].charged_to %><br/>
11
11
  Transaction ID: <%= params[:charge].id %><br/>
12
12
  Date: <%= params[:charge].created_at %><br/>
13
- <% if params[:charge].customer.owner.extra_billing_info? %>
13
+ <% if params[:charge].customer.owner.try(:extra_billing_info?) %>
14
14
  <%= params[:charge].customer.owner.extra_billing_info %><br/>
15
15
  <% end %>
16
16
  <br/>
@@ -11,7 +11,7 @@ Amount: <%= params[:charge].amount_refunded_with_currency %><br/>
11
11
  Refunded to: <%= params[:charge].charged_to %><br/>
12
12
  Transaction ID: <%= params[:charge].id %><br/>
13
13
  Date: <%= params[:charge].created_at %><br/>
14
- <% if params[:charge].customer.owner.extra_billing_info? %>
14
+ <% if params[:charge].customer.owner.try(:extra_billing_info?) %>
15
15
  <%= params[:charge].customer.owner.extra_billing_info %><br/>
16
16
  <% end %>
17
17
  <br/>
@@ -30,7 +30,8 @@ module Pay
30
30
 
31
31
  customer
32
32
  else
33
- result = gateway.customer.create(email: email, first_name: try(:first_name), last_name: try(:last_name), payment_method_nonce: payment_method_token)
33
+ first_name, last_name = customer_name.split(" ", 2)
34
+ result = gateway.customer.create(email: email, first_name: first_name, last_name: last_name, payment_method_nonce: payment_method_token)
34
35
  raise Pay::Braintree::Error, result unless result.success?
35
36
  pay_customer.update!(processor_id: result.customer.id)
36
37
 
@@ -47,6 +48,13 @@ module Pay
47
48
  raise Pay::Braintree::Error, e
48
49
  end
49
50
 
51
+ # Syncs name and email to Braintree::Customer
52
+ def update_customer!
53
+ return unless processor_id?
54
+ first_name, last_name = customer_name.split(" ", 2)
55
+ gateway.customer.update(processor_id, first_name: first_name, last_name: last_name, email: email)
56
+ end
57
+
50
58
  def charge(amount, options = {})
51
59
  args = {
52
60
  amount: amount.to_i / 100.0,
@@ -19,6 +19,10 @@ module Pay
19
19
  pay_customer
20
20
  end
21
21
 
22
+ def update_customer!
23
+ # pass
24
+ end
25
+
22
26
  def charge(amount, options = {})
23
27
  # Make to generate a processor_id
24
28
  customer
@@ -18,6 +18,10 @@ module Pay
18
18
  # pass
19
19
  end
20
20
 
21
+ def update_customer!
22
+ # pass
23
+ end
24
+
21
25
  def charge(amount, options = {})
22
26
  subscription = pay_customer.subscription
23
27
  return unless subscription.processor_id
data/lib/pay/receipts.rb CHANGED
@@ -21,7 +21,7 @@ module Pay
21
21
  [I18n.t("pay.receipt.amount"), Pay::Currency.format(amount, currency: currency)],
22
22
  [I18n.t("pay.receipt.charged_to"), charged_to]
23
23
  ]
24
- line_items << [I18n.t("pay.receipt.additional_info"), customer.owner.extra_billing_info] if customer.owner.extra_billing_info?
24
+ line_items << [I18n.t("pay.receipt.additional_info"), customer.owner.extra_billing_info] if customer.owner.try(:extra_billing_info?)
25
25
  line_items << [I18n.t("pay.receipt.refunded"), Pay::Currency.format(amount_refunded, currency: currency)] if refunded?
26
26
 
27
27
  defaults = {
@@ -49,7 +49,7 @@ module Pay
49
49
 
50
50
  def invoice_pdf(**options)
51
51
  bill_to = [customer.owner.name]
52
- bill_to += [customer.owner.extra_billing_info] if customer.owner.extra_billing_info?
52
+ bill_to += [customer.owner.extra_billing_info] if customer.owner.try(:extra_billing_info?)
53
53
  bill_to += [nil, customer.owner.email]
54
54
 
55
55
  total = Pay::Currency.format(amount, currency: currency)
@@ -44,6 +44,12 @@ module Pay
44
44
  raise Pay::Stripe::Error, e
45
45
  end
46
46
 
47
+ # Syncs name and email to Stripe::Customer
48
+ def update_customer!
49
+ return unless processor_id?
50
+ ::Stripe::Customer.update(processor_id, {name: customer_name, email: email}, stripe_options)
51
+ end
52
+
47
53
  def charge(amount, options = {})
48
54
  add_payment_method(payment_method_token, default: true) if payment_method_token?
49
55
 
@@ -181,8 +187,8 @@ module Pay
181
187
  payment_method_types: ["card"],
182
188
  mode: "payment",
183
189
  # These placeholder URLs will be replaced in a following step.
184
- success_url: options.delete(:success_url) || root_url(session_id: "{CHECKOUT_SESSION_ID}"),
185
- cancel_url: options.delete(:cancel_url) || root_url(session_id: "{CHECKOUT_SESSION_ID}")
190
+ success_url: merge_session_id_param(options.delete(:success_url) || root_url),
191
+ cancel_url: merge_session_id_param(options.delete(:cancel_url) || root_url)
186
192
  }
187
193
 
188
194
  # Line items are optional
@@ -234,6 +240,13 @@ module Pay
234
240
  def stripe_options
235
241
  {stripe_account: stripe_account}.compact
236
242
  end
243
+
244
+ # Includes the `session_id` param for Stripe Checkout with existing params (and makes sure the curly braces aren't escaped)
245
+ def merge_session_id_param(url)
246
+ uri = URI.parse(url)
247
+ uri.query = URI.encode_www_form(URI.decode_www_form(uri.query.to_s).to_h.merge("session_id" => "{CHECKOUT_SESSION_ID}").to_a)
248
+ uri.to_s.gsub("%7BCHECKOUT_SESSION_ID%7D", "{CHECKOUT_SESSION_ID}")
249
+ end
237
250
  end
238
251
  end
239
252
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "3.0.19"
2
+ VERSION = "3.0.23"
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: 3.0.19
4
+ version: 3.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Charnes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-15 00:00:00.000000000 Z
12
+ date: 2021-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -123,14 +123,7 @@ files:
123
123
  - config/locales/en.yml
124
124
  - config/routes.rb
125
125
  - db/migrate/1_create_pay_tables.rb
126
- - lib/generators/active_record/billable_generator.rb
127
- - lib/generators/active_record/merchant_generator.rb
128
- - lib/generators/active_record/templates/billable_migration.rb
129
- - lib/generators/active_record/templates/merchant_migration.rb
130
- - lib/generators/pay/billable_generator.rb
131
126
  - lib/generators/pay/email_views_generator.rb
132
- - lib/generators/pay/merchant_generator.rb
133
- - lib/generators/pay/orm_helpers.rb
134
127
  - lib/generators/pay/views_generator.rb
135
128
  - lib/pay.rb
136
129
  - lib/pay/adapter.rb
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/active_record"
4
- require "generators/pay/orm_helpers"
5
-
6
- module ActiveRecord
7
- module Generators
8
- class BillableGenerator < ActiveRecord::Generators::Base
9
- include Pay::Generators::OrmHelpers
10
- source_root File.expand_path("../templates", __FILE__)
11
-
12
- def copy_pay_billable_migration
13
- if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
14
- migration_template "billable_migration.rb", "#{migration_path}/add_pay_billable_to_#{table_name}.rb", migration_version: migration_version
15
- else
16
- say "#{model_path} does not exist.", :red
17
- say "⚠️ Make sure the #{name} model exists before running this generator."
18
- end
19
- end
20
-
21
- # If the file already contains the contents, the user will receive this warning:
22
- #
23
- # File unchanged! The supplied flag value not found!
24
- #
25
- # This can be ignored as it just means the contents already exist and the file is unchanged.
26
- # Thor will be updated to improve this message: https://github.com/rails/thor/issues/706
27
- def inject_pay_billable_content
28
- return unless model_exists?
29
-
30
- content = model_contents
31
- class_path = (namespaced? ? class_name.to_s.split("::") : [class_name])
32
- indent_depth = class_path.size - 1
33
- content = content.split("\n").map { |line| " " * indent_depth + line }.join("\n") << "\n"
34
- inject_into_class(model_path, class_path.last, content)
35
- end
36
-
37
- private
38
-
39
- def model_contents
40
- " include Pay::Billable"
41
- end
42
- end
43
- end
44
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/active_record"
4
- require "generators/pay/orm_helpers"
5
-
6
- module ActiveRecord
7
- module Generators
8
- class MerchantGenerator < ActiveRecord::Generators::Base
9
- include Pay::Generators::OrmHelpers
10
- source_root File.expand_path("../templates", __FILE__)
11
-
12
- def copy_pay_merchant_migration
13
- if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
14
- migration_template "merchant_migration.rb", "#{migration_path}/add_pay_merchant_to_#{table_name}.rb", migration_version: migration_version
15
- else
16
- say "#{model_path} does not exist.", :red
17
- say "⚠️ Make sure the #{name} model exists before running this generator."
18
- end
19
- end
20
-
21
- # If the file already contains the contents, the user will receive this warning:
22
- #
23
- # File unchanged! The supplied flag value not found!
24
- #
25
- # This can be ignored as it just means the contents already exist and the file is unchanged.
26
- # Thor will be updated to improve this message: https://github.com/rails/thor/issues/706
27
- def inject_pay_merchant_content
28
- return unless model_exists?
29
-
30
- content = model_contents
31
- class_path = (namespaced? ? class_name.to_s.split("::") : [class_name])
32
- indent_depth = class_path.size - 1
33
- content = content.split("\n").map { |line| " " * indent_depth + line }.join("\n") << "\n"
34
- inject_into_class(model_path, class_path.last, content)
35
- end
36
-
37
- private
38
-
39
- def model_contents
40
- " include Pay::Merchant"
41
- end
42
- end
43
- end
44
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddPayBillableTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
4
- def change
5
- change_table :<%= table_name %>, bulk: true do |t|
6
- t.string :processor
7
- t.string :processor_id
8
- t.public_send(Pay::Adapter.json_column_type, :pay_data)
9
- t.datetime :trial_ends_at
10
- t.string :card_type
11
- t.string :card_last4
12
- t.string :card_exp_month
13
- t.string :card_exp_year
14
- t.text :extra_billing_info
15
- end
16
- end
17
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddPayMerchantTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
4
- def change
5
- add_column table_name, :merchant_processor, :string
6
-
7
- # We may already have the pay_data column if a Pay::Billable object is also a Pay::Merchant
8
- unless ActiveRecord::Base.connection.column_exists?(table_name, :pay_data)
9
- add_column :<%= table_name %>, :pay_data, Pay::Adapter.json_column_type
10
- end
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/named_base"
4
-
5
- module Pay
6
- module Generators
7
- class BillableGenerator < Rails::Generators::NamedBase
8
- include Rails::Generators::ResourceHelpers
9
-
10
- source_root File.expand_path("../templates", __FILE__)
11
-
12
- desc "Generates a migration to add Pay::Billable fields to a model."
13
-
14
- hook_for :orm
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators/named_base"
4
-
5
- module Pay
6
- module Generators
7
- class MerchantGenerator < Rails::Generators::NamedBase
8
- include Rails::Generators::ResourceHelpers
9
-
10
- source_root File.expand_path("../templates", __FILE__)
11
-
12
- desc "Generates a migration to add Pay::Merchant fields to a model."
13
-
14
- hook_for :orm
15
- end
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pay
4
- module Generators
5
- module OrmHelpers
6
- private
7
-
8
- def model_exists?
9
- File.exist?(File.join(destination_root, model_path))
10
- end
11
-
12
- def migration_exists?(table_name)
13
- Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
14
- end
15
-
16
- def migration_path
17
- if Rails.version >= "5.0.3"
18
- db_migrate_path
19
- else
20
- @migration_path ||= File.join("db", "migrate")
21
- end
22
- end
23
-
24
- def model_path
25
- @model_path ||= File.join("app", "models", "#{file_path}.rb")
26
- end
27
-
28
- def migration_version
29
- if rails5_and_up?
30
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
31
- end
32
- end
33
-
34
- def rails5_and_up?
35
- Rails::VERSION::MAJOR >= 5
36
- end
37
- end
38
- end
39
- end