pay 3.0.2 → 3.0.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.
- checksums.yaml +4 -4
- data/app/models/pay/customer.rb +10 -0
- data/lib/pay/version.rb +1 -1
- data/lib/tasks/pay.rake +22 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef0b3b501b5c25692a192c44b7bac08fe9980a7764f11d17332ae0c5db27b37a
|
4
|
+
data.tar.gz: 9be9f1a40979bf0ec042c536bae0b93654902b9c33625cb58da3dabc0e6c448e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1adeb3e84b859998c32c943e00cace51cf2014496c836919d7258761d7c782cb5088f3a53454aed7bfda75e1d47dac7786404f4077ccdaab5d928e5479b500a3
|
7
|
+
data.tar.gz: 62dc7337b2dd15ec65ec2ca685cb4e0af650b79977e9f6465291887b07c598a33bde25d9af9bdfd091bf960982dc00cb9d2bceebf53243a1ca18f1a1fe623495
|
data/app/models/pay/customer.rb
CHANGED
@@ -76,6 +76,16 @@ module Pay
|
|
76
76
|
deleted_at.present?
|
77
77
|
end
|
78
78
|
|
79
|
+
def on_generic_trial?
|
80
|
+
return false unless fake_processor?
|
81
|
+
|
82
|
+
subscription = subscriptions.active.last
|
83
|
+
return false unless subscription
|
84
|
+
|
85
|
+
# If these match, consider it a generic trial
|
86
|
+
subscription.trial_ends_at == subscription.ends_at
|
87
|
+
end
|
88
|
+
|
79
89
|
%w[stripe braintree paddle fake_processor].each do |processor_name|
|
80
90
|
scope processor_name, -> { where(processor: processor_name) }
|
81
91
|
|
data/lib/pay/version.rb
CHANGED
data/lib/tasks/pay.rake
CHANGED
@@ -3,18 +3,29 @@ namespace :pay do
|
|
3
3
|
desc "Sync default payment methods for Pay::Customers"
|
4
4
|
task sync_default: :environment do
|
5
5
|
Pay::Customer.find_each do |pay_customer|
|
6
|
-
|
7
|
-
case pay_customer.processor
|
8
|
-
when "braintree"
|
9
|
-
payment_method = pay_customer.customer.payment_methods.find(&:default?)
|
10
|
-
Pay::Braintree::PaymentMethod.sync(payment_method.token, object: payment_method) if payment_method
|
11
|
-
when "stripe"
|
12
|
-
payment_method_id = pay_customer.customer.invoice_settings.default_payment_method
|
13
|
-
Pay::Stripe::PaymentMethod.sync(payment_method_id) if payment_method_id
|
14
|
-
when "paddle"
|
15
|
-
Pay::Paddle::PaymentMethod.sync(pay_customer)
|
16
|
-
end
|
6
|
+
sync_default_payment_method(pay_customer)
|
17
7
|
end
|
18
8
|
end
|
19
9
|
end
|
20
10
|
end
|
11
|
+
|
12
|
+
def sync_default_payment_method(pay_customer, retries: 2)
|
13
|
+
try = 0
|
14
|
+
begin
|
15
|
+
puts "Syncing Pay::Customer ##{pay_customer.id} attempt #{try + 1}: #{pay_customer.processor.titleize} #{pay_customer.processor_id}"
|
16
|
+
case pay_customer.processor
|
17
|
+
when "braintree"
|
18
|
+
payment_method = pay_customer.customer.payment_methods.find(&:default?)
|
19
|
+
Pay::Braintree::PaymentMethod.sync(payment_method.token, object: payment_method) if payment_method
|
20
|
+
when "stripe"
|
21
|
+
payment_method_id = pay_customer.customer.invoice_settings.default_payment_method
|
22
|
+
Pay::Stripe::PaymentMethod.sync(payment_method_id) if payment_method_id
|
23
|
+
when "paddle"
|
24
|
+
Pay::Paddle::PaymentMethod.sync(pay_customer)
|
25
|
+
end
|
26
|
+
rescue
|
27
|
+
sleep 0.5
|
28
|
+
try += 1
|
29
|
+
try <= retries ? retry : raise
|
30
|
+
end
|
31
|
+
end
|