pay 3.0.24 → 4.0.2

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.

Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/controllers/pay/webhooks/braintree_controller.rb +1 -1
  4. data/app/controllers/pay/webhooks/paddle_controller.rb +1 -1
  5. data/app/controllers/pay/webhooks/stripe_controller.rb +1 -1
  6. data/app/jobs/pay/customer_sync_job.rb +0 -2
  7. data/app/mailers/pay/application_mailer.rb +1 -1
  8. data/app/mailers/pay/user_mailer.rb +3 -3
  9. data/app/models/pay/charge.rb +23 -0
  10. data/app/models/pay/customer.rb +2 -6
  11. data/app/models/pay/merchant.rb +6 -0
  12. data/app/models/pay/subscription.rb +35 -8
  13. data/app/views/pay/user_mailer/receipt.html.erb +6 -6
  14. data/app/views/pay/user_mailer/refund.html.erb +6 -6
  15. data/config/locales/en.yml +31 -24
  16. data/config/routes.rb +3 -3
  17. data/lib/pay/attributes.rb +28 -2
  18. data/lib/pay/billable/sync_customer.rb +3 -3
  19. data/lib/pay/braintree/billable.rb +61 -48
  20. data/lib/pay/braintree/subscription.rb +8 -3
  21. data/lib/pay/braintree/webhooks/subscription_canceled.rb +6 -1
  22. data/lib/pay/braintree/webhooks/subscription_charged_successfully.rb +2 -2
  23. data/lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb +1 -1
  24. data/lib/pay/braintree/webhooks/subscription_trial_ended.rb +1 -1
  25. data/lib/pay/braintree.rb +6 -2
  26. data/lib/pay/currency.rb +8 -2
  27. data/lib/pay/engine.rb +22 -4
  28. data/lib/pay/fake_processor/billable.rb +0 -4
  29. data/lib/pay/fake_processor/subscription.rb +8 -3
  30. data/lib/pay/paddle/billable.rb +0 -4
  31. data/lib/pay/paddle/subscription.rb +2 -2
  32. data/lib/pay/paddle/webhooks/signature_verifier.rb +45 -41
  33. data/lib/pay/paddle/webhooks/subscription_cancelled.rb +7 -2
  34. data/lib/pay/paddle/webhooks/subscription_payment_refunded.rb +3 -3
  35. data/lib/pay/paddle/webhooks/subscription_payment_succeeded.rb +7 -7
  36. data/lib/pay/paddle/webhooks/subscription_updated.rb +15 -15
  37. data/lib/pay/paddle.rb +14 -2
  38. data/lib/pay/receipts.rb +106 -32
  39. data/lib/pay/stripe/billable.rb +50 -18
  40. data/lib/pay/stripe/charge.rb +93 -11
  41. data/lib/pay/stripe/merchant.rb +1 -1
  42. data/lib/pay/stripe/subscription.rb +132 -30
  43. data/lib/pay/stripe/webhooks/charge_refunded.rb +2 -2
  44. data/lib/pay/stripe/webhooks/charge_succeeded.rb +2 -2
  45. data/lib/pay/stripe/webhooks/checkout_session_async_payment_succeeded.rb +1 -8
  46. data/lib/pay/stripe/webhooks/checkout_session_completed.rb +21 -2
  47. data/lib/pay/stripe/webhooks/payment_action_required.rb +6 -6
  48. data/lib/pay/stripe/webhooks/subscription_renewing.rb +6 -10
  49. data/lib/pay/stripe/webhooks/subscription_updated.rb +1 -1
  50. data/lib/pay/stripe.rb +10 -1
  51. data/lib/pay/version.rb +1 -1
  52. data/lib/pay.rb +39 -4
  53. data/lib/tasks/pay.rake +1 -1
  54. metadata +3 -4
  55. data/lib/pay/merchant.rb +0 -37
@@ -8,20 +8,16 @@ module Pay
8
8
  def call(event)
9
9
  # Event is of type "invoice" see:
10
10
  # https://stripe.com/docs/api/invoices/object
11
- subscription = Pay::Subscription.find_by_processor_and_id(:stripe, event.data.object.subscription)
12
- return unless subscription
11
+ pay_subscription = Pay::Subscription.find_by_processor_and_id(:stripe, event.data.object.subscription)
12
+ return unless pay_subscription
13
13
 
14
14
  # Stripe subscription items all have the same interval
15
15
  price = event.data.object.lines.data.first.price
16
- return unless price.type == "recurring"
17
16
 
18
- interval = price.recurring.interval
19
- return unless interval == "year"
20
-
21
- if Pay.send_emails
22
- Pay::UserMailer.with(
23
- pay_customer: subscription.customer,
24
- subscription: subscription,
17
+ if Pay.send_email?(:subscription_renewing, pay_subscription, price)
18
+ Pay.mailer.with(
19
+ pay_customer: pay_subscription.customer,
20
+ pay_subscription: pay_subscription,
25
21
  date: Time.zone.at(event.data.object.next_payment_attempt)
26
22
  ).subscription_renewing.deliver_later
27
23
  end
@@ -3,7 +3,7 @@ module Pay
3
3
  module Webhooks
4
4
  class SubscriptionUpdated
5
5
  def call(event)
6
- Pay::Stripe::Subscription.sync(event.data.object.id)
6
+ Pay::Stripe::Subscription.sync(event.data.object.id, stripe_account: event.try(:account))
7
7
  end
8
8
  end
9
9
  end
data/lib/pay/stripe.rb CHANGED
@@ -28,6 +28,12 @@ module Pay
28
28
 
29
29
  extend Env
30
30
 
31
+ def self.enabled?
32
+ return false unless Pay.enabled_processors.include?(:stripe) && defined?(::Stripe)
33
+
34
+ Pay::Engine.version_matches?(required: "~> 6", current: ::Stripe::VERSION) || (raise "[Pay] stripe gem must be version ~> 6")
35
+ end
36
+
31
37
  def self.setup
32
38
  ::Stripe.api_key = private_key
33
39
  ::Stripe.api_version = "2020-08-27"
@@ -35,7 +41,10 @@ module Pay
35
41
  # Used by Stripe to identify Pay for support
36
42
  ::Stripe.set_app_info("PayRails", partner_id: "pp_partner_IqhY0UExnJYLxg", version: Pay::VERSION, url: "https://github.com/pay-rails/pay")
37
43
 
38
- configure_webhooks
44
+ # Automatically retry requests that fail
45
+ # This automatically includes idempotency keys in the request to guarantee that retires are safe
46
+ # https://github.com/stripe/stripe-ruby#configuring-automatic-retries
47
+ ::Stripe.max_network_retries = 2
39
48
  end
40
49
 
41
50
  def self.public_key
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "3.0.24"
2
+ VERSION = "4.0.2"
3
3
  end
data/lib/pay.rb CHANGED
@@ -3,6 +3,8 @@ require "pay/engine"
3
3
  require "pay/errors"
4
4
  require "pay/adapter"
5
5
 
6
+ require "active_support/dependencies"
7
+
6
8
  module Pay
7
9
  autoload :Attributes, "pay/attributes"
8
10
  autoload :Env, "pay/env"
@@ -35,10 +37,6 @@ module Pay
35
37
  mattr_accessor :business_logo
36
38
  mattr_accessor :support_email
37
39
 
38
- # Email configuration
39
- mattr_accessor :send_emails
40
- @@send_emails = true
41
-
42
40
  mattr_accessor :automount_routes
43
41
  @@automount_routes = true
44
42
 
@@ -51,7 +49,44 @@ module Pay
51
49
  mattr_accessor :routes_path
52
50
  @@routes_path = "/pay"
53
51
 
52
+ mattr_accessor :enabled_processors
53
+ @@enabled_processors = [:stripe, :braintree, :paddle]
54
+
55
+ mattr_accessor :emails
56
+ @@emails = ActiveSupport::OrderedOptions.new
57
+ @@emails.payment_action_required = true
58
+ @@emails.receipt = true
59
+ @@emails.refund = true
60
+ # This only applies to Stripe, therefor we supply the second argument of price
61
+ @@emails.subscription_renewing = ->(pay_subscription, price) {
62
+ (price&.type == "recurring") && (price.recurring&.interval == "year")
63
+ }
64
+
65
+ @@mailer = "Pay::UserMailer"
66
+
67
+ def self.mailer=(value)
68
+ @@mailer = value
69
+ @@mailer_ref = nil
70
+ end
71
+
72
+ def self.mailer
73
+ @@mailer_ref ||= @@mailer&.constantize
74
+ end
75
+
76
+ mattr_accessor :parent_mailer
77
+ @@parent_mailer = "Pay::ApplicationMailer"
78
+
54
79
  def self.setup
55
80
  yield self
56
81
  end
82
+
83
+ def self.send_email?(email_option, *remaining_args)
84
+ config_option = emails.send(email_option)
85
+
86
+ if config_option.respond_to?(:call)
87
+ config_option.call(*remaining_args)
88
+ else
89
+ config_option
90
+ end
91
+ end
57
92
  end
data/lib/tasks/pay.rake CHANGED
@@ -21,7 +21,7 @@ def sync_default_payment_method(pay_customer, retries: 2)
21
21
  payment_method_id = pay_customer.customer.invoice_settings.default_payment_method
22
22
  Pay::Stripe::PaymentMethod.sync(payment_method_id) if payment_method_id
23
23
  when "paddle"
24
- Pay::Paddle::PaymentMethod.sync(pay_customer)
24
+ Pay::Paddle::PaymentMethod.sync(pay_customer: pay_customer)
25
25
  end
26
26
  rescue
27
27
  sleep 0.5
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.24
4
+ version: 4.0.2
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-12-02 00:00:00.000000000 Z
12
+ date: 2022-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -153,7 +153,6 @@ files:
153
153
  - lib/pay/fake_processor/error.rb
154
154
  - lib/pay/fake_processor/payment_method.rb
155
155
  - lib/pay/fake_processor/subscription.rb
156
- - lib/pay/merchant.rb
157
156
  - lib/pay/nano_id.rb
158
157
  - lib/pay/paddle.rb
159
158
  - lib/pay/paddle/billable.rb
@@ -217,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
216
  - !ruby/object:Gem::Version
218
217
  version: '0'
219
218
  requirements: []
220
- rubygems_version: 3.2.22
219
+ rubygems_version: 3.3.7
221
220
  signing_key:
222
221
  specification_version: 4
223
222
  summary: Payments engine for Ruby on Rails
data/lib/pay/merchant.rb DELETED
@@ -1,37 +0,0 @@
1
- module Pay
2
- module Merchant
3
- extend ActiveSupport::Concern
4
-
5
- # Keep track of which Merchant models we have
6
- class << self
7
- attr_reader :includers
8
- end
9
-
10
- def self.included(base = nil, &block)
11
- @includers ||= []
12
- @includers << base if base
13
- super
14
- end
15
-
16
- included do
17
- store_accessor :pay_data, :stripe_connect_account_id
18
- store_accessor :pay_data, :onboarding_complete
19
- end
20
-
21
- def merchant
22
- @merchant ||= merchant_processor_for(merchant_processor).new(self)
23
- end
24
-
25
- def merchant_processor_for(name)
26
- "Pay::#{name.to_s.classify}::Merchant".constantize
27
- end
28
-
29
- def stripe_connect_account_id?
30
- !!stripe_connect_account_id
31
- end
32
-
33
- def onboarding_complete?
34
- !!onboarding_complete
35
- end
36
- end
37
- end