pay 2.5.0 → 2.6.0
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 +4 -4
- data/app/models/pay/charge.rb +22 -3
- data/app/models/pay/subscription.rb +23 -24
- data/app/views/pay/stripe/_checkout_button.html.erb +21 -0
- data/lib/pay.rb +9 -12
- data/lib/pay/billable.rb +33 -33
- data/lib/pay/billable/sync_email.rb +1 -1
- data/lib/pay/braintree.rb +34 -16
- data/lib/pay/braintree/authorization_error.rb +9 -0
- data/lib/pay/braintree/billable.rb +33 -30
- data/lib/pay/braintree/charge.rb +8 -10
- data/lib/pay/braintree/error.rb +9 -0
- data/lib/pay/braintree/subscription.rb +34 -15
- data/lib/pay/braintree/webhooks/subscription_charged_successfully.rb +1 -1
- data/lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb +1 -1
- data/lib/pay/engine.rb +0 -22
- data/lib/pay/errors.rb +0 -44
- data/lib/pay/paddle.rb +30 -16
- data/lib/pay/paddle/billable.rb +26 -22
- data/lib/pay/paddle/charge.rb +8 -12
- data/lib/pay/paddle/error.rb +9 -0
- data/lib/pay/paddle/subscription.rb +29 -18
- data/lib/pay/paddle/webhooks/subscription_payment_succeeded.rb +1 -1
- data/lib/pay/stripe.rb +62 -14
- data/lib/pay/stripe/billable.rb +127 -69
- data/lib/pay/stripe/charge.rb +9 -15
- data/lib/pay/stripe/error.rb +9 -0
- data/lib/pay/stripe/subscription.rb +27 -11
- data/lib/pay/stripe/webhooks/charge_succeeded.rb +1 -20
- data/lib/pay/version.rb +1 -1
- data/lib/pay/webhooks.rb +13 -0
- metadata +11 -56
- data/lib/pay/braintree/webhooks.rb +0 -11
- data/lib/pay/paddle/webhooks.rb +0 -9
- data/lib/pay/stripe/webhooks.rb +0 -38
data/lib/pay/stripe/charge.rb
CHANGED
@@ -1,29 +1,23 @@
|
|
1
1
|
module Pay
|
2
2
|
module Stripe
|
3
|
-
|
4
|
-
|
3
|
+
class Charge
|
4
|
+
attr_reader :pay_charge
|
5
5
|
|
6
|
-
|
7
|
-
scope :stripe, -> { where(processor: :stripe) }
|
8
|
-
end
|
6
|
+
delegate :processor_id, :owner, to: :pay_charge
|
9
7
|
|
10
|
-
def
|
11
|
-
|
8
|
+
def initialize(pay_charge)
|
9
|
+
@pay_charge = pay_charge
|
12
10
|
end
|
13
11
|
|
14
|
-
def
|
12
|
+
def charge
|
15
13
|
::Stripe::Charge.retrieve(processor_id)
|
16
14
|
rescue ::Stripe::StripeError => e
|
17
15
|
raise Pay::Stripe::Error, e
|
18
16
|
end
|
19
17
|
|
20
|
-
def
|
21
|
-
::Stripe::Refund.create(
|
22
|
-
|
23
|
-
amount: amount_to_refund
|
24
|
-
)
|
25
|
-
|
26
|
-
update(amount_refunded: amount_to_refund)
|
18
|
+
def refund!(amount_to_refund)
|
19
|
+
::Stripe::Refund.create(charge: processor_id, amount: amount_to_refund)
|
20
|
+
pay_charge.update(amount_refunded: amount_to_refund)
|
27
21
|
rescue ::Stripe::StripeError => e
|
28
22
|
raise Pay::Stripe::Error, e
|
29
23
|
end
|
@@ -1,39 +1,55 @@
|
|
1
1
|
module Pay
|
2
2
|
module Stripe
|
3
|
-
|
4
|
-
|
3
|
+
class Subscription
|
4
|
+
attr_reader :pay_subscription
|
5
5
|
|
6
|
-
|
6
|
+
delegate :canceled?,
|
7
|
+
:ends_at,
|
8
|
+
:on_trial?,
|
9
|
+
:owner,
|
10
|
+
:processor_subscription,
|
11
|
+
:processor_id,
|
12
|
+
:prorate,
|
13
|
+
:processor_plan,
|
14
|
+
:quantity?,
|
15
|
+
:quantity,
|
16
|
+
to: :pay_subscription
|
17
|
+
|
18
|
+
def initialize(pay_subscription)
|
19
|
+
@pay_subscription = pay_subscription
|
20
|
+
end
|
21
|
+
|
22
|
+
def cancel
|
7
23
|
subscription = processor_subscription
|
8
24
|
subscription.cancel_at_period_end = true
|
9
25
|
subscription.save
|
10
26
|
|
11
27
|
new_ends_at = on_trial? ? trial_ends_at : Time.at(subscription.current_period_end)
|
12
|
-
update(ends_at: new_ends_at)
|
28
|
+
pay_subscription.update(ends_at: new_ends_at)
|
13
29
|
rescue ::Stripe::StripeError => e
|
14
30
|
raise Pay::Stripe::Error, e
|
15
31
|
end
|
16
32
|
|
17
|
-
def
|
33
|
+
def cancel_now!
|
18
34
|
processor_subscription.delete
|
19
|
-
update(ends_at: Time.zone.now, status: :canceled)
|
35
|
+
pay_subscription.update(ends_at: Time.zone.now, status: :canceled)
|
20
36
|
rescue ::Stripe::StripeError => e
|
21
37
|
raise Pay::Stripe::Error, e
|
22
38
|
end
|
23
39
|
|
24
|
-
def
|
40
|
+
def on_grace_period?
|
25
41
|
canceled? && Time.zone.now < ends_at
|
26
42
|
end
|
27
43
|
|
28
|
-
def
|
44
|
+
def paused?
|
29
45
|
false
|
30
46
|
end
|
31
47
|
|
32
|
-
def
|
48
|
+
def pause
|
33
49
|
raise NotImplementedError, "Stripe does not support pausing subscriptions"
|
34
50
|
end
|
35
51
|
|
36
|
-
def
|
52
|
+
def resume
|
37
53
|
unless on_grace_period?
|
38
54
|
raise StandardError, "You can only resume subscriptions within their grace period."
|
39
55
|
end
|
@@ -47,7 +63,7 @@ module Pay
|
|
47
63
|
raise Pay::Stripe::Error, e
|
48
64
|
end
|
49
65
|
|
50
|
-
def
|
66
|
+
def swap(plan)
|
51
67
|
subscription = processor_subscription
|
52
68
|
subscription.cancel_at_period_end = false
|
53
69
|
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
|
-
|
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)
|
data/lib/pay/version.rb
CHANGED
data/lib/pay/webhooks.rb
ADDED
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.
|
4
|
+
version: 2.6.0
|
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-
|
12
|
+
date: 2021-02-16 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:
|
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
|
@@ -215,8 +169,8 @@ files:
|
|
215
169
|
- lib/pay/paddle.rb
|
216
170
|
- lib/pay/paddle/billable.rb
|
217
171
|
- lib/pay/paddle/charge.rb
|
172
|
+
- lib/pay/paddle/error.rb
|
218
173
|
- lib/pay/paddle/subscription.rb
|
219
|
-
- lib/pay/paddle/webhooks.rb
|
220
174
|
- lib/pay/paddle/webhooks/signature_verifier.rb
|
221
175
|
- lib/pay/paddle/webhooks/subscription_cancelled.rb
|
222
176
|
- lib/pay/paddle/webhooks/subscription_created.rb
|
@@ -228,8 +182,8 @@ files:
|
|
228
182
|
- lib/pay/stripe.rb
|
229
183
|
- lib/pay/stripe/billable.rb
|
230
184
|
- lib/pay/stripe/charge.rb
|
185
|
+
- lib/pay/stripe/error.rb
|
231
186
|
- lib/pay/stripe/subscription.rb
|
232
|
-
- lib/pay/stripe/webhooks.rb
|
233
187
|
- lib/pay/stripe/webhooks/charge_refunded.rb
|
234
188
|
- lib/pay/stripe/webhooks/charge_succeeded.rb
|
235
189
|
- lib/pay/stripe/webhooks/customer_deleted.rb
|
@@ -241,8 +195,9 @@ files:
|
|
241
195
|
- lib/pay/stripe/webhooks/subscription_renewing.rb
|
242
196
|
- lib/pay/stripe/webhooks/subscription_updated.rb
|
243
197
|
- lib/pay/version.rb
|
198
|
+
- lib/pay/webhooks.rb
|
244
199
|
- lib/pay/webhooks/delegator.rb
|
245
|
-
homepage: https://github.com/
|
200
|
+
homepage: https://github.com/pay-rails/pay
|
246
201
|
licenses:
|
247
202
|
- MIT
|
248
203
|
metadata: {}
|
@@ -264,5 +219,5 @@ requirements: []
|
|
264
219
|
rubygems_version: 3.2.3
|
265
220
|
signing_key:
|
266
221
|
specification_version: 4
|
267
|
-
summary:
|
222
|
+
summary: Payments engine for Ruby on Rails
|
268
223
|
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
|
data/lib/pay/paddle/webhooks.rb
DELETED
@@ -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
|
data/lib/pay/stripe/webhooks.rb
DELETED
@@ -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
|