pay 2.2.0 → 2.4.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/README.md +161 -11
- data/Rakefile +2 -4
- data/app/controllers/pay/payments_controller.rb +3 -0
- data/app/controllers/pay/webhooks/braintree_controller.rb +1 -1
- data/app/controllers/pay/webhooks/paddle_controller.rb +36 -0
- data/app/mailers/pay/user_mailer.rb +14 -35
- data/app/models/pay/application_record.rb +6 -1
- data/app/models/pay/charge.rb +7 -0
- data/app/models/pay/subscription.rb +27 -4
- data/app/views/pay/payments/show.html.erb +1 -1
- data/app/views/pay/user_mailer/payment_action_required.html.erb +1 -1
- data/app/views/pay/user_mailer/receipt.html.erb +6 -6
- data/app/views/pay/user_mailer/refund.html.erb +6 -6
- data/app/views/pay/user_mailer/subscription_renewing.html.erb +1 -1
- data/config/locales/en.yml +137 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20200603134434_add_data_to_pay_models.rb +17 -0
- data/lib/generators/active_record/pay_generator.rb +1 -1
- data/lib/generators/pay/orm_helpers.rb +1 -2
- data/lib/pay.rb +9 -41
- data/lib/pay/billable.rb +16 -11
- data/lib/pay/braintree/billable.rb +25 -19
- data/lib/pay/braintree/charge.rb +7 -3
- data/lib/pay/braintree/subscription.rb +15 -5
- data/lib/pay/engine.rb +7 -0
- data/lib/pay/errors.rb +73 -0
- data/lib/pay/paddle.rb +38 -0
- data/lib/pay/paddle/billable.rb +95 -0
- data/lib/pay/paddle/charge.rb +39 -0
- data/lib/pay/paddle/subscription.rb +70 -0
- data/lib/pay/paddle/webhooks.rb +1 -0
- data/lib/pay/paddle/webhooks/signature_verifier.rb +115 -0
- data/lib/pay/paddle/webhooks/subscription_cancelled.rb +18 -0
- data/lib/pay/paddle/webhooks/subscription_created.rb +59 -0
- data/lib/pay/paddle/webhooks/subscription_payment_refunded.rb +21 -0
- data/lib/pay/paddle/webhooks/subscription_payment_succeeded.rb +43 -0
- data/lib/pay/paddle/webhooks/subscription_updated.rb +37 -0
- data/lib/pay/receipts.rb +6 -6
- data/lib/pay/stripe.rb +1 -1
- data/lib/pay/stripe/billable.rb +12 -6
- data/lib/pay/stripe/charge.rb +6 -2
- data/lib/pay/stripe/subscription.rb +15 -5
- data/lib/pay/stripe/webhooks/charge_refunded.rb +2 -2
- data/lib/pay/stripe/webhooks/charge_succeeded.rb +7 -7
- data/lib/pay/stripe/webhooks/payment_action_required.rb +7 -8
- data/lib/pay/stripe/webhooks/subscription_created.rb +1 -1
- data/lib/pay/stripe/webhooks/subscription_renewing.rb +4 -3
- data/lib/pay/version.rb +1 -1
- metadata +35 -43
data/lib/pay/stripe/charge.rb
CHANGED
@@ -3,6 +3,10 @@ module Pay
|
|
3
3
|
module Charge
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
+
included do
|
7
|
+
scope :stripe, -> { where(processor: :stripe) }
|
8
|
+
end
|
9
|
+
|
6
10
|
def stripe?
|
7
11
|
processor == "stripe"
|
8
12
|
end
|
@@ -10,7 +14,7 @@ module Pay
|
|
10
14
|
def stripe_charge
|
11
15
|
::Stripe::Charge.retrieve(processor_id)
|
12
16
|
rescue ::Stripe::StripeError => e
|
13
|
-
raise Error, e
|
17
|
+
raise Pay::Stripe::Error, e
|
14
18
|
end
|
15
19
|
|
16
20
|
def stripe_refund!(amount_to_refund)
|
@@ -21,7 +25,7 @@ module Pay
|
|
21
25
|
|
22
26
|
update(amount_refunded: amount_to_refund)
|
23
27
|
rescue ::Stripe::StripeError => e
|
24
|
-
raise Error, e
|
28
|
+
raise Pay::Stripe::Error, e
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -1,6 +1,12 @@
|
|
1
1
|
module Pay
|
2
2
|
module Stripe
|
3
3
|
module Subscription
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
scope :stripe, -> { where(processor: :stripe) }
|
8
|
+
end
|
9
|
+
|
4
10
|
def stripe?
|
5
11
|
processor == "stripe"
|
6
12
|
end
|
@@ -13,14 +19,18 @@ module Pay
|
|
13
19
|
new_ends_at = on_trial? ? trial_ends_at : Time.at(subscription.current_period_end)
|
14
20
|
update(ends_at: new_ends_at)
|
15
21
|
rescue ::Stripe::StripeError => e
|
16
|
-
raise Error, e
|
22
|
+
raise Pay::Stripe::Error, e
|
17
23
|
end
|
18
24
|
|
19
25
|
def stripe_cancel_now!
|
20
26
|
processor_subscription.delete
|
21
27
|
update(ends_at: Time.zone.now, status: :canceled)
|
22
28
|
rescue ::Stripe::StripeError => e
|
23
|
-
raise Error, e
|
29
|
+
raise Pay::Stripe::Error, e
|
30
|
+
end
|
31
|
+
|
32
|
+
def stripe_on_grace_period?
|
33
|
+
canceled? && Time.zone.now < ends_at
|
24
34
|
end
|
25
35
|
|
26
36
|
def stripe_resume
|
@@ -30,19 +40,19 @@ module Pay
|
|
30
40
|
subscription.cancel_at_period_end = false
|
31
41
|
subscription.save
|
32
42
|
rescue ::Stripe::StripeError => e
|
33
|
-
raise Error, e
|
43
|
+
raise Pay::Stripe::Error, e
|
34
44
|
end
|
35
45
|
|
36
46
|
def stripe_swap(plan)
|
37
47
|
subscription = processor_subscription
|
38
48
|
subscription.cancel_at_period_end = false
|
39
49
|
subscription.plan = plan
|
40
|
-
subscription.proration_behavior = (prorate ?
|
50
|
+
subscription.proration_behavior = (prorate ? "create_prorations" : "none")
|
41
51
|
subscription.trial_end = on_trial? ? trial_ends_at.to_i : "now"
|
42
52
|
subscription.quantity = quantity if quantity?
|
43
53
|
subscription.save
|
44
54
|
rescue ::Stripe::StripeError => e
|
45
|
-
raise Error, e
|
55
|
+
raise Pay::Stripe::Error, e
|
46
56
|
end
|
47
57
|
end
|
48
58
|
end
|
@@ -12,9 +12,9 @@ module Pay
|
|
12
12
|
notify_user(charge.owner, charge)
|
13
13
|
end
|
14
14
|
|
15
|
-
def notify_user(
|
15
|
+
def notify_user(billable, charge)
|
16
16
|
if Pay.send_emails
|
17
|
-
Pay::UserMailer.
|
17
|
+
Pay::UserMailer.with(billable: billable, charge: charge).refund.deliver_later
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -9,13 +9,11 @@ module Pay
|
|
9
9
|
return unless billable.present?
|
10
10
|
return if billable.charges.where(processor_id: object.id).any?
|
11
11
|
|
12
|
-
|
13
|
-
notify_user(billable, charge)
|
14
|
-
charge
|
12
|
+
create_charge(billable, object)
|
15
13
|
end
|
16
14
|
|
17
|
-
def create_charge(
|
18
|
-
charge =
|
15
|
+
def create_charge(billable, object)
|
16
|
+
charge = billable.charges.find_or_initialize_by(
|
19
17
|
processor: :stripe,
|
20
18
|
processor_id: object.id
|
21
19
|
)
|
@@ -29,12 +27,14 @@ module Pay
|
|
29
27
|
created_at: Time.zone.at(object.created)
|
30
28
|
)
|
31
29
|
|
30
|
+
notify_user(billable, charge)
|
31
|
+
|
32
32
|
charge
|
33
33
|
end
|
34
34
|
|
35
|
-
def notify_user(
|
35
|
+
def notify_user(billable, charge)
|
36
36
|
if Pay.send_emails && charge.respond_to?(:receipt)
|
37
|
-
Pay::UserMailer.
|
37
|
+
Pay::UserMailer.with(billable: billable, charge: charge).receipt.deliver_later
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -6,19 +6,18 @@ module Pay
|
|
6
6
|
# Event is of type "invoice" see:
|
7
7
|
# https://stripe.com/docs/api/invoices/object
|
8
8
|
|
9
|
-
|
9
|
+
object = event.data.object
|
10
10
|
|
11
|
-
subscription = Pay.subscription_model.find_by(
|
12
|
-
|
13
|
-
|
14
|
-
)
|
11
|
+
subscription = Pay.subscription_model.find_by(processor: :stripe, processor_id: object.subscription)
|
12
|
+
return if subscription.nil?
|
13
|
+
billable = subscription.owner
|
15
14
|
|
16
|
-
notify_user(
|
15
|
+
notify_user(billable, event.data.object.payment_intent, subscription)
|
17
16
|
end
|
18
17
|
|
19
|
-
def notify_user(
|
18
|
+
def notify_user(billable, payment_intent_id, subscription)
|
20
19
|
if Pay.send_emails
|
21
|
-
Pay::UserMailer.
|
20
|
+
Pay::UserMailer.with(billable: billable, payment_intent_id: payment_intent_id, subscription: subscription).payment_action_required.deliver_later
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -18,7 +18,7 @@ module Pay
|
|
18
18
|
return
|
19
19
|
end
|
20
20
|
|
21
|
-
subscription = Pay.subscription_model.new(owner: owner)
|
21
|
+
subscription = Pay.subscription_model.new(name: Pay.default_product_name, owner: owner, processor: :stripe, processor_id: object.id)
|
22
22
|
end
|
23
23
|
|
24
24
|
subscription.quantity = object.quantity
|
@@ -9,12 +9,13 @@ module Pay
|
|
9
9
|
processor: :stripe,
|
10
10
|
processor_id: event.data.object.subscription
|
11
11
|
)
|
12
|
-
|
12
|
+
date = Time.zone.at(event.data.object.next_payment_attempt)
|
13
|
+
notify_user(subscription.owner, subscription, date) if subscription.present?
|
13
14
|
end
|
14
15
|
|
15
|
-
def notify_user(
|
16
|
+
def notify_user(billable, subscription, date)
|
16
17
|
if Pay.send_emails
|
17
|
-
Pay::UserMailer.
|
18
|
+
Pay::UserMailer.with(billable: billable, subscription: subscription, date: date).subscription_renewing.deliver_later
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/pay/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Charnes
|
8
8
|
- Chris Oliver
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 2.92.0
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
37
|
+
version: '4.0'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: 2.92.0
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '4.0'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: stripe
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,49 +74,41 @@ dependencies:
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '2.3'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
type: :development
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: minitest-rails
|
77
|
+
name: paddle_pay
|
92
78
|
requirement: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: 0.0.1
|
97
83
|
type: :development
|
98
84
|
prerelease: false
|
99
85
|
version_requirements: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
89
|
+
version: 0.0.1
|
104
90
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
91
|
+
name: minitest-rails
|
106
92
|
requirement: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '6'
|
97
|
+
- - "<"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '7.0'
|
111
100
|
type: :development
|
112
101
|
prerelease: false
|
113
102
|
version_requirements: !ruby/object:Gem::Requirement
|
114
103
|
requirements:
|
115
104
|
- - ">="
|
116
105
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
106
|
+
version: '6'
|
107
|
+
- - "<"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '7.0'
|
118
110
|
- !ruby/object:Gem::Dependency
|
119
|
-
name:
|
111
|
+
name: mocha
|
120
112
|
requirement: !ruby/object:Gem::Requirement
|
121
113
|
requirements:
|
122
114
|
- - ">="
|
@@ -143,20 +135,6 @@ dependencies:
|
|
143
135
|
- - ">="
|
144
136
|
- !ruby/object:Gem::Version
|
145
137
|
version: '0'
|
146
|
-
- !ruby/object:Gem::Dependency
|
147
|
-
name: sqlite3
|
148
|
-
requirement: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '1.4'
|
153
|
-
type: :development
|
154
|
-
prerelease: false
|
155
|
-
version_requirements: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - "~>"
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '1.4'
|
160
138
|
- !ruby/object:Gem::Dependency
|
161
139
|
name: vcr
|
162
140
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,6 +180,7 @@ files:
|
|
202
180
|
- app/controllers/pay/application_controller.rb
|
203
181
|
- app/controllers/pay/payments_controller.rb
|
204
182
|
- app/controllers/pay/webhooks/braintree_controller.rb
|
183
|
+
- app/controllers/pay/webhooks/paddle_controller.rb
|
205
184
|
- app/helpers/pay/application_helper.rb
|
206
185
|
- app/jobs/pay/application_job.rb
|
207
186
|
- app/jobs/pay/email_sync_job.rb
|
@@ -221,6 +200,7 @@ files:
|
|
221
200
|
- db/migrate/20170205020145_create_pay_subscriptions.rb
|
222
201
|
- db/migrate/20170727235816_create_pay_charges.rb
|
223
202
|
- db/migrate/20190816015720_add_status_to_pay_subscriptions.rb
|
203
|
+
- db/migrate/20200603134434_add_data_to_pay_models.rb
|
224
204
|
- lib/generators/active_record/pay_generator.rb
|
225
205
|
- lib/generators/active_record/templates/migration.rb
|
226
206
|
- lib/generators/pay/email_views_generator.rb
|
@@ -236,6 +216,18 @@ files:
|
|
236
216
|
- lib/pay/braintree/subscription.rb
|
237
217
|
- lib/pay/engine.rb
|
238
218
|
- lib/pay/env.rb
|
219
|
+
- lib/pay/errors.rb
|
220
|
+
- lib/pay/paddle.rb
|
221
|
+
- lib/pay/paddle/billable.rb
|
222
|
+
- lib/pay/paddle/charge.rb
|
223
|
+
- lib/pay/paddle/subscription.rb
|
224
|
+
- lib/pay/paddle/webhooks.rb
|
225
|
+
- lib/pay/paddle/webhooks/signature_verifier.rb
|
226
|
+
- lib/pay/paddle/webhooks/subscription_cancelled.rb
|
227
|
+
- lib/pay/paddle/webhooks/subscription_created.rb
|
228
|
+
- lib/pay/paddle/webhooks/subscription_payment_refunded.rb
|
229
|
+
- lib/pay/paddle/webhooks/subscription_payment_succeeded.rb
|
230
|
+
- lib/pay/paddle/webhooks/subscription_updated.rb
|
239
231
|
- lib/pay/payment.rb
|
240
232
|
- lib/pay/receipts.rb
|
241
233
|
- lib/pay/stripe.rb
|
@@ -258,7 +250,7 @@ homepage: https://github.com/jasoncharnes/pay
|
|
258
250
|
licenses:
|
259
251
|
- MIT
|
260
252
|
metadata: {}
|
261
|
-
post_install_message:
|
253
|
+
post_install_message:
|
262
254
|
rdoc_options: []
|
263
255
|
require_paths:
|
264
256
|
- lib
|
@@ -273,8 +265,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
265
|
- !ruby/object:Gem::Version
|
274
266
|
version: '0'
|
275
267
|
requirements: []
|
276
|
-
rubygems_version: 3.
|
277
|
-
signing_key:
|
268
|
+
rubygems_version: 3.2.3
|
269
|
+
signing_key:
|
278
270
|
specification_version: 4
|
279
271
|
summary: A Ruby on Rails subscription engine.
|
280
272
|
test_files: []
|