pay 2.5.0 → 2.6.4

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -2
  3. data/app/models/pay/charge.rb +22 -3
  4. data/app/models/pay/subscription.rb +23 -24
  5. data/app/views/pay/stripe/_checkout_button.html.erb +21 -0
  6. data/lib/pay.rb +12 -14
  7. data/lib/pay/billable.rb +44 -33
  8. data/lib/pay/billable/sync_email.rb +1 -1
  9. data/lib/pay/braintree.rb +34 -16
  10. data/lib/pay/braintree/authorization_error.rb +9 -0
  11. data/lib/pay/braintree/billable.rb +33 -30
  12. data/lib/pay/braintree/charge.rb +8 -10
  13. data/lib/pay/braintree/error.rb +9 -0
  14. data/lib/pay/braintree/subscription.rb +34 -15
  15. data/lib/pay/braintree/webhooks/subscription_charged_successfully.rb +1 -1
  16. data/lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb +1 -1
  17. data/lib/pay/engine.rb +0 -22
  18. data/lib/pay/errors.rb +0 -44
  19. data/lib/pay/fake_processor.rb +8 -0
  20. data/lib/pay/fake_processor/billable.rb +60 -0
  21. data/lib/pay/fake_processor/charge.rb +21 -0
  22. data/lib/pay/fake_processor/error.rb +6 -0
  23. data/lib/pay/fake_processor/subscription.rb +55 -0
  24. data/lib/pay/paddle.rb +30 -16
  25. data/lib/pay/paddle/billable.rb +26 -22
  26. data/lib/pay/paddle/charge.rb +8 -12
  27. data/lib/pay/paddle/error.rb +9 -0
  28. data/lib/pay/paddle/subscription.rb +33 -18
  29. data/lib/pay/paddle/webhooks/subscription_payment_succeeded.rb +1 -1
  30. data/lib/pay/stripe.rb +62 -14
  31. data/lib/pay/stripe/billable.rb +136 -69
  32. data/lib/pay/stripe/charge.rb +9 -15
  33. data/lib/pay/stripe/error.rb +9 -0
  34. data/lib/pay/stripe/subscription.rb +31 -11
  35. data/lib/pay/stripe/webhooks/charge_succeeded.rb +1 -20
  36. data/lib/pay/stripe/webhooks/customer_updated.rb +1 -1
  37. data/lib/pay/stripe/webhooks/payment_method_updated.rb +1 -1
  38. data/lib/pay/version.rb +1 -1
  39. data/lib/pay/webhooks.rb +13 -0
  40. metadata +16 -56
  41. data/lib/pay/braintree/webhooks.rb +0 -11
  42. data/lib/pay/paddle/webhooks.rb +0 -9
  43. data/lib/pay/stripe/webhooks.rb +0 -38
@@ -1,39 +1,59 @@
1
1
  module Pay
2
2
  module Stripe
3
- module Subscription
4
- extend ActiveSupport::Concern
3
+ class Subscription
4
+ attr_reader :pay_subscription
5
5
 
6
- def stripe_cancel
6
+ delegate :active?,
7
+ :canceled?,
8
+ :ends_at,
9
+ :name,
10
+ :on_trial?,
11
+ :owner,
12
+ :processor_id,
13
+ :processor_plan,
14
+ :processor_subscription,
15
+ :prorate,
16
+ :prorate?,
17
+ :quantity,
18
+ :quantity?,
19
+ :trial_ends_at,
20
+ to: :pay_subscription
21
+
22
+ def initialize(pay_subscription)
23
+ @pay_subscription = pay_subscription
24
+ end
25
+
26
+ def cancel
7
27
  subscription = processor_subscription
8
28
  subscription.cancel_at_period_end = true
9
29
  subscription.save
10
30
 
11
31
  new_ends_at = on_trial? ? trial_ends_at : Time.at(subscription.current_period_end)
12
- update(ends_at: new_ends_at)
32
+ pay_subscription.update(ends_at: new_ends_at)
13
33
  rescue ::Stripe::StripeError => e
14
34
  raise Pay::Stripe::Error, e
15
35
  end
16
36
 
17
- def stripe_cancel_now!
37
+ def cancel_now!
18
38
  processor_subscription.delete
19
- update(ends_at: Time.zone.now, status: :canceled)
39
+ pay_subscription.update(ends_at: Time.zone.now, status: :canceled)
20
40
  rescue ::Stripe::StripeError => e
21
41
  raise Pay::Stripe::Error, e
22
42
  end
23
43
 
24
- def stripe_on_grace_period?
44
+ def on_grace_period?
25
45
  canceled? && Time.zone.now < ends_at
26
46
  end
27
47
 
28
- def stripe_paused?
48
+ def paused?
29
49
  false
30
50
  end
31
51
 
32
- def stripe_pause
52
+ def pause
33
53
  raise NotImplementedError, "Stripe does not support pausing subscriptions"
34
54
  end
35
55
 
36
- def stripe_resume
56
+ def resume
37
57
  unless on_grace_period?
38
58
  raise StandardError, "You can only resume subscriptions within their grace period."
39
59
  end
@@ -47,7 +67,7 @@ module Pay
47
67
  raise Pay::Stripe::Error, e
48
68
  end
49
69
 
50
- def stripe_swap(plan)
70
+ def swap(plan)
51
71
  subscription = processor_subscription
52
72
  subscription.cancel_at_period_end = false
53
73
  subscription.plan = plan
@@ -9,27 +9,8 @@ module Pay
9
9
  return unless billable.present?
10
10
  return if billable.charges.where(processor_id: object.id).any?
11
11
 
12
- create_charge(billable, object)
13
- end
14
-
15
- def create_charge(billable, object)
16
- charge = billable.charges.find_or_initialize_by(
17
- processor: :stripe,
18
- processor_id: object.id
19
- )
20
-
21
- charge.update(
22
- amount: object.amount,
23
- card_last4: object.payment_method_details.card.last4,
24
- card_type: object.payment_method_details.card.brand,
25
- card_exp_month: object.payment_method_details.card.exp_month,
26
- card_exp_year: object.payment_method_details.card.exp_year,
27
- created_at: Time.zone.at(object.created)
28
- )
29
-
12
+ charge = Pay::Stripe::Billable.new(billable).save_pay_charge(object)
30
13
  notify_user(billable, charge)
31
-
32
- charge
33
14
  end
34
15
 
35
16
  def notify_user(billable, charge)
@@ -9,7 +9,7 @@ module Pay
9
9
  # Couldn't find user, we can skip
10
10
  return unless billable.present?
11
11
 
12
- billable.sync_card_from_stripe
12
+ Pay::Stripe::Billable.new(billable).sync_card_from_stripe
13
13
  end
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module Pay
9
9
  # Couldn't find user, we can skip
10
10
  return unless billable.present?
11
11
 
12
- billable.sync_card_from_stripe
12
+ Pay::Stripe::Billable.new(billable).sync_card_from_stripe
13
13
  end
14
14
  end
15
15
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "2.5.0"
2
+ VERSION = "2.6.4"
3
3
  end
@@ -0,0 +1,13 @@
1
+ module Pay
2
+ module Webhooks
3
+ autoload :Delegator, "pay/webhooks/delegator"
4
+
5
+ class << self
6
+ delegate :configure, :instrument, to: :delegator
7
+
8
+ def delegator
9
+ @delegator ||= Delegator.new
10
+ end
11
+ end
12
+ end
13
+ 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: 2.5.0
4
+ version: 2.6.4
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-02-15 00:00:00.000000000 Z
12
+ date: 2021-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -25,54 +25,6 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.2'
28
- - !ruby/object:Gem::Dependency
29
- name: braintree
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 2.92.0
35
- - - "<"
36
- - !ruby/object:Gem::Version
37
- version: '4.0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- version: 2.92.0
45
- - - "<"
46
- - !ruby/object:Gem::Version
47
- version: '4.0'
48
- - !ruby/object:Gem::Dependency
49
- name: stripe
50
- requirement: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '2.8'
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '2.8'
62
- - !ruby/object:Gem::Dependency
63
- name: paddle_pay
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.0.1
69
- type: :development
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.0.1
76
28
  - !ruby/object:Gem::Dependency
77
29
  name: minitest-rails
78
30
  requirement: !ruby/object:Gem::Requirement
@@ -149,7 +101,7 @@ dependencies:
149
101
  - - ">="
150
102
  - !ruby/object:Gem::Version
151
103
  version: '0'
152
- description: A Ruby on Rails subscription engine.
104
+ description: Stripe, Paddle, and Braintree payments for Ruby on Rails apps
153
105
  email:
154
106
  - jason@thecharnes.com
155
107
  - excid3@gmail.com
@@ -178,6 +130,7 @@ files:
178
130
  - app/models/pay/subscription.rb
179
131
  - app/views/layouts/pay/application.html.erb
180
132
  - app/views/pay/payments/show.html.erb
133
+ - app/views/pay/stripe/_checkout_button.html.erb
181
134
  - app/views/pay/user_mailer/payment_action_required.html.erb
182
135
  - app/views/pay/user_mailer/receipt.html.erb
183
136
  - app/views/pay/user_mailer/refund.html.erb
@@ -198,10 +151,11 @@ files:
198
151
  - lib/pay/billable.rb
199
152
  - lib/pay/billable/sync_email.rb
200
153
  - lib/pay/braintree.rb
154
+ - lib/pay/braintree/authorization_error.rb
201
155
  - lib/pay/braintree/billable.rb
202
156
  - lib/pay/braintree/charge.rb
157
+ - lib/pay/braintree/error.rb
203
158
  - lib/pay/braintree/subscription.rb
204
- - lib/pay/braintree/webhooks.rb
205
159
  - lib/pay/braintree/webhooks/subscription_canceled.rb
206
160
  - lib/pay/braintree/webhooks/subscription_charged_successfully.rb
207
161
  - lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb
@@ -212,11 +166,16 @@ files:
212
166
  - lib/pay/engine.rb
213
167
  - lib/pay/env.rb
214
168
  - lib/pay/errors.rb
169
+ - lib/pay/fake_processor.rb
170
+ - lib/pay/fake_processor/billable.rb
171
+ - lib/pay/fake_processor/charge.rb
172
+ - lib/pay/fake_processor/error.rb
173
+ - lib/pay/fake_processor/subscription.rb
215
174
  - lib/pay/paddle.rb
216
175
  - lib/pay/paddle/billable.rb
217
176
  - lib/pay/paddle/charge.rb
177
+ - lib/pay/paddle/error.rb
218
178
  - lib/pay/paddle/subscription.rb
219
- - lib/pay/paddle/webhooks.rb
220
179
  - lib/pay/paddle/webhooks/signature_verifier.rb
221
180
  - lib/pay/paddle/webhooks/subscription_cancelled.rb
222
181
  - lib/pay/paddle/webhooks/subscription_created.rb
@@ -228,8 +187,8 @@ files:
228
187
  - lib/pay/stripe.rb
229
188
  - lib/pay/stripe/billable.rb
230
189
  - lib/pay/stripe/charge.rb
190
+ - lib/pay/stripe/error.rb
231
191
  - lib/pay/stripe/subscription.rb
232
- - lib/pay/stripe/webhooks.rb
233
192
  - lib/pay/stripe/webhooks/charge_refunded.rb
234
193
  - lib/pay/stripe/webhooks/charge_succeeded.rb
235
194
  - lib/pay/stripe/webhooks/customer_deleted.rb
@@ -241,8 +200,9 @@ files:
241
200
  - lib/pay/stripe/webhooks/subscription_renewing.rb
242
201
  - lib/pay/stripe/webhooks/subscription_updated.rb
243
202
  - lib/pay/version.rb
203
+ - lib/pay/webhooks.rb
244
204
  - lib/pay/webhooks/delegator.rb
245
- homepage: https://github.com/jasoncharnes/pay
205
+ homepage: https://github.com/pay-rails/pay
246
206
  licenses:
247
207
  - MIT
248
208
  metadata: {}
@@ -264,5 +224,5 @@ requirements: []
264
224
  rubygems_version: 3.2.3
265
225
  signing_key:
266
226
  specification_version: 4
267
- summary: A Ruby on Rails subscription engine.
227
+ summary: Payments engine for Ruby on Rails
268
228
  test_files: []
@@ -1,11 +0,0 @@
1
- Dir[File.join(__dir__, "webhooks", "**", "*.rb")].sort.each { |file| require file }
2
-
3
- Pay::Webhooks.configure do |events|
4
- events.subscribe "braintree.subscription_canceled", Pay::Braintree::Webhooks::SubscriptionCanceled.new
5
- events.subscribe "braintree.subscription_charged_successfully", Pay::Braintree::Webhooks::SubscriptionChargedSuccessfully.new
6
- events.subscribe "braintree.subscription_charged_unsuccessfully", Pay::Braintree::Webhooks::SubscriptionChargedUnsuccessfully.new
7
- events.subscribe "braintree.subscription_expired", Pay::Braintree::Webhooks::SubscriptionExpired.new
8
- events.subscribe "braintree.subscription_trial_ended", Pay::Braintree::Webhooks::SubscriptionTrialEnded.new
9
- events.subscribe "braintree.subscription_went_active", Pay::Braintree::Webhooks::SubscriptionWentActive.new
10
- events.subscribe "braintree.subscription_went_past_due", Pay::Braintree::Webhooks::SubscriptionWentPastDue.new
11
- end
@@ -1,9 +0,0 @@
1
- Dir[File.join(__dir__, "webhooks", "**", "*.rb")].sort.each { |file| require file }
2
-
3
- Pay::Webhooks.configure do |events|
4
- events.subscribe "paddle.subscription_created", Pay::Paddle::Webhooks::SubscriptionCreated.new
5
- events.subscribe "paddle.subscription_updated", Pay::Paddle::Webhooks::SubscriptionUpdated.new
6
- events.subscribe "paddle.subscription_cancelled", Pay::Paddle::Webhooks::SubscriptionCancelled.new
7
- events.subscribe "paddle.subscription_payment_succeeded", Pay::Paddle::Webhooks::SubscriptionPaymentSucceeded.new
8
- events.subscribe "paddle.subscription_payment_refunded", Pay::Paddle::Webhooks::SubscriptionPaymentRefunded.new
9
- end
@@ -1,38 +0,0 @@
1
- Dir[File.join(__dir__, "webhooks", "**", "*.rb")].sort.each { |file| require file }
2
-
3
- Pay::Webhooks.configure do |events|
4
- # Listen to the charge event to make sure we get non-subscription
5
- # purchases as well. Invoice is only for subscriptions and manual creation
6
- # so it does not include individual charges.
7
- events.subscribe "stripe.charge.succeeded", Pay::Stripe::Webhooks::ChargeSucceeded.new
8
- events.subscribe "stripe.charge.refunded", Pay::Stripe::Webhooks::ChargeRefunded.new
9
-
10
- # Warn user of upcoming charges for their subscription. This is handy for
11
- # notifying annual users their subscription will renew shortly.
12
- # This probably should be ignored for monthly subscriptions.
13
- events.subscribe "stripe.invoice.upcoming", Pay::Stripe::Webhooks::SubscriptionRenewing.new
14
-
15
- # Payment action is required to process an invoice
16
- events.subscribe "stripe.invoice.payment_action_required", Pay::Stripe::Webhooks::PaymentActionRequired.new
17
-
18
- # If a subscription is manually created on Stripe, we want to sync
19
- events.subscribe "stripe.customer.subscription.created", Pay::Stripe::Webhooks::SubscriptionCreated.new
20
-
21
- # If the plan, quantity, or trial ending date is updated on Stripe, we want to sync
22
- events.subscribe "stripe.customer.subscription.updated", Pay::Stripe::Webhooks::SubscriptionUpdated.new
23
-
24
- # When a customers subscription is canceled, we want to update our records
25
- events.subscribe "stripe.customer.subscription.deleted", Pay::Stripe::Webhooks::SubscriptionDeleted.new
26
-
27
- # Monitor changes for customer's default card changing
28
- events.subscribe "stripe.customer.updated", Pay::Stripe::Webhooks::CustomerUpdated.new
29
-
30
- # If a customer was deleted in Stripe, their subscriptions should be cancelled
31
- events.subscribe "stripe.customer.deleted", Pay::Stripe::Webhooks::CustomerDeleted.new
32
-
33
- # If a customer's payment source was deleted in Stripe, we should update as well
34
- events.subscribe "stripe.payment_method.attached", Pay::Stripe::Webhooks::PaymentMethodUpdated.new
35
- events.subscribe "stripe.payment_method.updated", Pay::Stripe::Webhooks::PaymentMethodUpdated.new
36
- events.subscribe "stripe.payment_method.card_automatically_updated", Pay::Stripe::Webhooks::PaymentMethodUpdated.new
37
- events.subscribe "stripe.payment_method.detached", Pay::Stripe::Webhooks::PaymentMethodUpdated.new
38
- end