pay 2.6.10 → 2.7.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.
- checksums.yaml +4 -4
- data/README.md +93 -54
- data/app/models/pay/application_record.rb +1 -0
- data/app/models/pay/charge.rb +3 -1
- data/app/models/pay/subscription.rb +5 -3
- data/db/migrate/20200603134434_add_data_to_pay_models.rb +2 -18
- data/db/migrate/20210309004259_add_data_to_pay_billable.rb +10 -0
- data/db/migrate/20210406215234_add_currency_to_pay_charges.rb +5 -0
- data/db/migrate/20210406215506_add_application_fee_to_pay_models.rb +7 -0
- data/db/migrate/20210714175351_add_uniqueness_to_pay_models.rb +6 -0
- data/lib/generators/active_record/billable_generator.rb +44 -0
- data/lib/generators/active_record/merchant_generator.rb +44 -0
- data/lib/generators/active_record/templates/billable_migration.rb +17 -0
- data/lib/generators/active_record/templates/merchant_migration.rb +12 -0
- data/lib/generators/pay/{pay_generator.rb → billable_generator.rb} +2 -3
- data/lib/generators/pay/merchant_generator.rb +17 -0
- data/lib/generators/pay/orm_helpers.rb +10 -6
- data/lib/pay.rb +22 -0
- data/lib/pay/adapter.rb +22 -0
- data/lib/pay/billable.rb +4 -0
- data/lib/pay/braintree/billable.rb +8 -1
- data/lib/pay/braintree/subscription.rb +6 -0
- data/lib/pay/env.rb +8 -0
- data/lib/pay/fake_processor/subscription.rb +6 -0
- data/lib/pay/merchant.rb +37 -0
- data/lib/pay/paddle/subscription.rb +9 -0
- data/lib/pay/paddle/webhooks/subscription_payment_succeeded.rb +3 -1
- data/lib/pay/stripe.rb +11 -0
- data/lib/pay/stripe/billable.rb +39 -36
- data/lib/pay/stripe/charge.rb +62 -4
- data/lib/pay/stripe/merchant.rb +66 -0
- data/lib/pay/stripe/subscription.rb +87 -21
- data/lib/pay/stripe/webhooks/account_updated.rb +17 -0
- data/lib/pay/stripe/webhooks/charge_refunded.rb +2 -7
- data/lib/pay/stripe/webhooks/charge_succeeded.rb +2 -8
- data/lib/pay/stripe/webhooks/checkout_session_async_payment_succeeded.rb +13 -0
- data/lib/pay/stripe/webhooks/checkout_session_completed.rb +13 -0
- data/lib/pay/stripe/webhooks/payment_intent_succeeded.rb +2 -8
- data/lib/pay/stripe/webhooks/payment_method_attached.rb +17 -0
- data/lib/pay/stripe/webhooks/payment_method_automatically_updated.rb +17 -0
- data/lib/pay/stripe/webhooks/payment_method_detached.rb +17 -0
- data/lib/pay/stripe/webhooks/subscription_created.rb +1 -35
- data/lib/pay/stripe/webhooks/subscription_deleted.rb +1 -9
- data/lib/pay/stripe/webhooks/subscription_renewing.rb +4 -6
- data/lib/pay/stripe/webhooks/subscription_updated.rb +1 -28
- data/lib/pay/version.rb +1 -1
- metadata +22 -6
- data/lib/generators/active_record/pay_generator.rb +0 -58
- data/lib/generators/active_record/templates/migration.rb +0 -9
@@ -3,41 +3,7 @@ module Pay
|
|
3
3
|
module Webhooks
|
4
4
|
class SubscriptionCreated
|
5
5
|
def call(event)
|
6
|
-
|
7
|
-
|
8
|
-
# We may already have the subscription in the database, so we can update that record
|
9
|
-
subscription = Pay.subscription_model.find_by(processor: :stripe, processor_id: object.id)
|
10
|
-
|
11
|
-
# Create the subscription in the database if we don't have it already
|
12
|
-
if subscription.nil?
|
13
|
-
# The customer should already be in the database
|
14
|
-
owner = Pay.find_billable(processor: :stripe, processor_id: object.customer)
|
15
|
-
|
16
|
-
if owner.nil?
|
17
|
-
Rails.logger.error("[Pay] Unable to find Pay::Billable with processor: :stripe and processor_id: '#{object.customer}'. Searched these models: #{Pay.billable_models.join(", ")}")
|
18
|
-
return
|
19
|
-
end
|
20
|
-
|
21
|
-
subscription = Pay.subscription_model.new(name: Pay.default_product_name, owner: owner, processor: :stripe, processor_id: object.id)
|
22
|
-
end
|
23
|
-
|
24
|
-
subscription.quantity = object.quantity
|
25
|
-
subscription.status = object.status
|
26
|
-
subscription.processor_plan = object.plan.id
|
27
|
-
subscription.trial_ends_at = Time.at(object.trial_end) if object.trial_end.present?
|
28
|
-
|
29
|
-
# If user was on trial, their subscription ends at the end of the trial
|
30
|
-
subscription.ends_at = if object.cancel_at_period_end && subscription.on_trial?
|
31
|
-
subscription.trial_ends_at
|
32
|
-
|
33
|
-
# User wasn't on trial, so subscription ends at period end
|
34
|
-
elsif object.cancel_at_period_end
|
35
|
-
Time.at(object.current_period_end)
|
36
|
-
|
37
|
-
# Subscription isn't marked to cancel at period end
|
38
|
-
end
|
39
|
-
|
40
|
-
subscription.save!
|
6
|
+
Pay::Stripe::Subscription.sync(event.data.object.id)
|
41
7
|
end
|
42
8
|
end
|
43
9
|
end
|
@@ -3,15 +3,7 @@ module Pay
|
|
3
3
|
module Webhooks
|
4
4
|
class SubscriptionDeleted
|
5
5
|
def call(event)
|
6
|
-
|
7
|
-
subscription = Pay.subscription_model.find_by(processor: :stripe, processor_id: object.id)
|
8
|
-
|
9
|
-
# We couldn't find the subscription for some reason, maybe it's from another service
|
10
|
-
return if subscription.nil?
|
11
|
-
|
12
|
-
# User canceled subscriptions have an ends_at
|
13
|
-
# Automatically canceled subscriptions need this value set
|
14
|
-
subscription.update!(ends_at: Time.at(object.ended_at)) if subscription.ends_at.blank? && object.ended_at.present?
|
6
|
+
Pay::Stripe::Subscription.sync(event.data.object.id)
|
15
7
|
end
|
16
8
|
end
|
17
9
|
end
|
@@ -5,12 +5,10 @@ module Pay
|
|
5
5
|
def call(event)
|
6
6
|
# Event is of type "invoice" see:
|
7
7
|
# https://stripe.com/docs/api/invoices/object
|
8
|
-
subscription = Pay.subscription_model.find_by(
|
9
|
-
|
10
|
-
|
11
|
-
)
|
12
|
-
date = Time.zone.at(event.data.object.next_payment_attempt)
|
13
|
-
notify_user(subscription.owner, subscription, date) if subscription.present?
|
8
|
+
subscription = Pay.subscription_model.find_by(processor: :stripe, processor_id: event.data.object.subscription)
|
9
|
+
return unless subscription
|
10
|
+
|
11
|
+
notify_user(subscription.owner, subscription, Time.zone.at(event.data.object.next_payment_attempt))
|
14
12
|
end
|
15
13
|
|
16
14
|
def notify_user(billable, subscription, date)
|
@@ -3,34 +3,7 @@ module Pay
|
|
3
3
|
module Webhooks
|
4
4
|
class SubscriptionUpdated
|
5
5
|
def call(event)
|
6
|
-
|
7
|
-
subscription = Pay.subscription_model.find_by(processor: :stripe, processor_id: object.id)
|
8
|
-
|
9
|
-
return if subscription.nil?
|
10
|
-
|
11
|
-
# Delete any subscription attempts that have expired
|
12
|
-
if object.status == "incomplete_expired"
|
13
|
-
subscription.destroy
|
14
|
-
return
|
15
|
-
end
|
16
|
-
|
17
|
-
subscription.status = object.status
|
18
|
-
subscription.quantity = object.quantity
|
19
|
-
subscription.processor_plan = object.plan.id
|
20
|
-
subscription.trial_ends_at = Time.at(object.trial_end) if object.trial_end.present?
|
21
|
-
|
22
|
-
# If user was on trial, their subscription ends at the end of the trial
|
23
|
-
subscription.ends_at = if object.cancel_at_period_end && subscription.on_trial?
|
24
|
-
subscription.trial_ends_at
|
25
|
-
|
26
|
-
# User wasn't on trial, so subscription ends at period end
|
27
|
-
elsif object.cancel_at_period_end
|
28
|
-
Time.at(object.current_period_end)
|
29
|
-
|
30
|
-
# Subscription isn't marked to cancel at period end
|
31
|
-
end
|
32
|
-
|
33
|
-
subscription.save!
|
6
|
+
Pay::Stripe::Subscription.sync(event.data.object.id)
|
34
7
|
end
|
35
8
|
end
|
36
9
|
end
|
data/lib/pay/version.rb
CHANGED
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.7.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
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -141,13 +141,21 @@ files:
|
|
141
141
|
- db/migrate/20170727235816_create_pay_charges.rb
|
142
142
|
- db/migrate/20190816015720_add_status_to_pay_subscriptions.rb
|
143
143
|
- db/migrate/20200603134434_add_data_to_pay_models.rb
|
144
|
-
-
|
145
|
-
-
|
144
|
+
- db/migrate/20210309004259_add_data_to_pay_billable.rb
|
145
|
+
- db/migrate/20210406215234_add_currency_to_pay_charges.rb
|
146
|
+
- db/migrate/20210406215506_add_application_fee_to_pay_models.rb
|
147
|
+
- db/migrate/20210714175351_add_uniqueness_to_pay_models.rb
|
148
|
+
- lib/generators/active_record/billable_generator.rb
|
149
|
+
- lib/generators/active_record/merchant_generator.rb
|
150
|
+
- lib/generators/active_record/templates/billable_migration.rb
|
151
|
+
- lib/generators/active_record/templates/merchant_migration.rb
|
152
|
+
- lib/generators/pay/billable_generator.rb
|
146
153
|
- lib/generators/pay/email_views_generator.rb
|
154
|
+
- lib/generators/pay/merchant_generator.rb
|
147
155
|
- lib/generators/pay/orm_helpers.rb
|
148
|
-
- lib/generators/pay/pay_generator.rb
|
149
156
|
- lib/generators/pay/views_generator.rb
|
150
157
|
- lib/pay.rb
|
158
|
+
- lib/pay/adapter.rb
|
151
159
|
- lib/pay/billable.rb
|
152
160
|
- lib/pay/billable/sync_email.rb
|
153
161
|
- lib/pay/braintree.rb
|
@@ -171,6 +179,7 @@ files:
|
|
171
179
|
- lib/pay/fake_processor/charge.rb
|
172
180
|
- lib/pay/fake_processor/error.rb
|
173
181
|
- lib/pay/fake_processor/subscription.rb
|
182
|
+
- lib/pay/merchant.rb
|
174
183
|
- lib/pay/paddle.rb
|
175
184
|
- lib/pay/paddle/billable.rb
|
176
185
|
- lib/pay/paddle/charge.rb
|
@@ -188,13 +197,20 @@ files:
|
|
188
197
|
- lib/pay/stripe/billable.rb
|
189
198
|
- lib/pay/stripe/charge.rb
|
190
199
|
- lib/pay/stripe/error.rb
|
200
|
+
- lib/pay/stripe/merchant.rb
|
191
201
|
- lib/pay/stripe/subscription.rb
|
202
|
+
- lib/pay/stripe/webhooks/account_updated.rb
|
192
203
|
- lib/pay/stripe/webhooks/charge_refunded.rb
|
193
204
|
- lib/pay/stripe/webhooks/charge_succeeded.rb
|
205
|
+
- lib/pay/stripe/webhooks/checkout_session_async_payment_succeeded.rb
|
206
|
+
- lib/pay/stripe/webhooks/checkout_session_completed.rb
|
194
207
|
- lib/pay/stripe/webhooks/customer_deleted.rb
|
195
208
|
- lib/pay/stripe/webhooks/customer_updated.rb
|
196
209
|
- lib/pay/stripe/webhooks/payment_action_required.rb
|
197
210
|
- lib/pay/stripe/webhooks/payment_intent_succeeded.rb
|
211
|
+
- lib/pay/stripe/webhooks/payment_method_attached.rb
|
212
|
+
- lib/pay/stripe/webhooks/payment_method_automatically_updated.rb
|
213
|
+
- lib/pay/stripe/webhooks/payment_method_detached.rb
|
198
214
|
- lib/pay/stripe/webhooks/payment_method_updated.rb
|
199
215
|
- lib/pay/stripe/webhooks/subscription_created.rb
|
200
216
|
- lib/pay/stripe/webhooks/subscription_deleted.rb
|
@@ -222,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
238
|
- !ruby/object:Gem::Version
|
223
239
|
version: '0'
|
224
240
|
requirements: []
|
225
|
-
rubygems_version: 3.2.
|
241
|
+
rubygems_version: 3.2.15
|
226
242
|
signing_key:
|
227
243
|
specification_version: 4
|
228
244
|
summary: Payments engine for Ruby on Rails
|
@@ -1,58 +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 PayGenerator < 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 "migration.rb", "#{migration_path}/add_pay_billable_to_#{table_name}.rb", migration_version: migration_version
|
15
|
-
end
|
16
|
-
# TODO: Throw error here that model should already exist if it doesn't
|
17
|
-
end
|
18
|
-
|
19
|
-
def inject_pay_billable_content
|
20
|
-
content = model_contents
|
21
|
-
|
22
|
-
class_path = if namespaced?
|
23
|
-
class_name.to_s.split("::")
|
24
|
-
else
|
25
|
-
[class_name]
|
26
|
-
end
|
27
|
-
|
28
|
-
indent_depth = class_path.size - 1
|
29
|
-
content = content.split("\n").map { |line| " " * indent_depth + line }.join("\n") << "\n"
|
30
|
-
|
31
|
-
inject_into_class(model_path, class_path.last, content) if model_exists?
|
32
|
-
end
|
33
|
-
|
34
|
-
def migration_data
|
35
|
-
<<RUBY
|
36
|
-
t.string :processor
|
37
|
-
t.string :processor_id
|
38
|
-
t.datetime :trial_ends_at
|
39
|
-
t.string :card_type
|
40
|
-
t.string :card_last4
|
41
|
-
t.string :card_exp_month
|
42
|
-
t.string :card_exp_year
|
43
|
-
t.text :extra_billing_info
|
44
|
-
RUBY
|
45
|
-
end
|
46
|
-
|
47
|
-
def rails5_and_up?
|
48
|
-
Rails::VERSION::MAJOR >= 5
|
49
|
-
end
|
50
|
-
|
51
|
-
def migration_version
|
52
|
-
if rails5_and_up?
|
53
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|