pay 3.0.0 → 3.0.5
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 +1 -1
- data/app/models/pay/charge.rb +25 -1
- data/app/models/pay/customer.rb +10 -0
- data/app/models/pay/subscription.rb +12 -2
- data/app/views/pay/payments/show.html.erb +0 -1
- data/lib/pay/braintree/billable.rb +8 -3
- data/lib/pay/braintree/payment_method.rb +9 -0
- data/lib/pay/paddle/payment_method.rb +2 -0
- data/lib/pay/stripe/webhooks/customer_updated.rb +1 -1
- data/lib/pay/version.rb +1 -1
- data/lib/tasks/pay.rake +31 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d201890dfc59215167a68fe0c2fc23d071ecdc831931eb51c1be85b12d0091
|
4
|
+
data.tar.gz: 86dbc8f7bebcda970cdbdc9eb22b97ce2716570daeb4a8b64f1d794a350b19fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321eef31d462caade5b3099d3897a7f8e7bf9374e05a76dca1c165329156eb83266c3655f13fb658a1756b91899b4b70e322f131d042c5668431e67529a88214
|
7
|
+
data.tar.gz: cd2e93563744dec1081687c26e4ad496ed7a9a04e918f95f57c2ff8340e7b15d3b4ef85d948891a6be0a34f09ca69b63787751de2ca42f65a4bafd10449922ec
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
Pay is a payments engine for Ruby on Rails 6.0 and higher.
|
10
10
|
|
11
|
-
**Upgrading?** Check the [UPGRADE](UPGRADE.md) guide for required changes and/or migration when upgrading from a previous version of Pay.
|
11
|
+
⚠️ **Upgrading?** Check the [UPGRADE](UPGRADE.md) guide for required changes and/or migration when upgrading from a previous version of Pay.
|
12
12
|
|
13
13
|
## 🧑💻 Tutorial
|
14
14
|
|
data/app/models/pay/charge.rb
CHANGED
@@ -63,9 +63,33 @@ module Pay
|
|
63
63
|
def charged_to
|
64
64
|
case payment_method_type
|
65
65
|
when "card"
|
66
|
-
"#{brand} (**** **** **** #{last4})"
|
66
|
+
"#{brand.titleize} (**** **** **** #{last4})"
|
67
67
|
when "paypal"
|
68
68
|
"#{brand} (#{email})"
|
69
|
+
|
70
|
+
# Braintree
|
71
|
+
when "venmo"
|
72
|
+
"#{brand.titleize} #{username}"
|
73
|
+
when "us_bank_account"
|
74
|
+
"#{bank} #{last4}"
|
75
|
+
|
76
|
+
# Stripe
|
77
|
+
when "acss_debit"
|
78
|
+
"#{bank} #{last4}"
|
79
|
+
when "eps", "fpx", "ideal", "p24"
|
80
|
+
bank
|
81
|
+
|
82
|
+
when "au_becs_debit"
|
83
|
+
"BECS Debit #{last4}"
|
84
|
+
|
85
|
+
when "bacs_debit"
|
86
|
+
"Bacs Debit #{last4}"
|
87
|
+
|
88
|
+
when "sepa_debit"
|
89
|
+
"SEPA Debit #{last4}"
|
90
|
+
|
91
|
+
else
|
92
|
+
payment_method_type&.titleize
|
69
93
|
end
|
70
94
|
end
|
71
95
|
end
|
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
|
|
@@ -18,7 +18,7 @@ module Pay
|
|
18
18
|
scope :with_deleted_customer, -> { joins(:customer).merge(Customer.deleted) }
|
19
19
|
|
20
20
|
# Callbacks
|
21
|
-
before_destroy :
|
21
|
+
before_destroy :cancel_if_active
|
22
22
|
|
23
23
|
store_accessor :data, :paddle_update_url
|
24
24
|
store_accessor :data, :paddle_cancel_url
|
@@ -110,7 +110,7 @@ module Pay
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def swap(plan)
|
113
|
-
raise ArgumentError, "plan must be a string" unless plan.is_a?(String)
|
113
|
+
raise ArgumentError, "plan must be a string. Got `#{plan.inspect}` instead." unless plan.is_a?(String)
|
114
114
|
payment_processor.swap(plan)
|
115
115
|
update(processor_plan: plan, ends_at: nil, status: :active)
|
116
116
|
end
|
@@ -127,5 +127,15 @@ module Pay
|
|
127
127
|
def latest_payment
|
128
128
|
processor_subscription(expand: ["latest_invoice.payment_intent"]).latest_invoice.payment_intent
|
129
129
|
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def cancel_if_active
|
134
|
+
if active?
|
135
|
+
cancel_now!
|
136
|
+
end
|
137
|
+
rescue => e
|
138
|
+
Rails.logger.info "[Pay] Unable to automatically cancel subscription `#{processor} #{id}`: #{e.message}"
|
139
|
+
end
|
130
140
|
end
|
131
141
|
end
|
@@ -160,8 +160,6 @@ module Pay
|
|
160
160
|
charge
|
161
161
|
end
|
162
162
|
|
163
|
-
private
|
164
|
-
|
165
163
|
def gateway
|
166
164
|
Pay.braintree_gateway
|
167
165
|
end
|
@@ -197,7 +195,14 @@ module Pay
|
|
197
195
|
}
|
198
196
|
else
|
199
197
|
{
|
200
|
-
payment_method_type: payment_method.class.name.demodulize.underscore
|
198
|
+
payment_method_type: payment_method.class.name.demodulize.underscore,
|
199
|
+
brand: payment_method.try(:card_type),
|
200
|
+
last4: payment_method.try(:last_4),
|
201
|
+
exp_month: payment_method.try(:expiration_month),
|
202
|
+
exp_year: payment_method.try(:expiration_year),
|
203
|
+
bank: payment_method.try(:bank_name),
|
204
|
+
username: payment_method.try(:username),
|
205
|
+
email: payment_method.try(:email)
|
201
206
|
}
|
202
207
|
end
|
203
208
|
|
@@ -5,6 +5,15 @@ module Pay
|
|
5
5
|
|
6
6
|
delegate :customer, :processor_id, to: :pay_payment_method
|
7
7
|
|
8
|
+
def self.sync(id, object: nil, try: 0, retries: 1)
|
9
|
+
object ||= gateway.payment_method.find(id)
|
10
|
+
|
11
|
+
pay_customer = Pay::Customer.find_by(processor: :braintree, processor_id: object.customer_id)
|
12
|
+
return unless pay_customer
|
13
|
+
|
14
|
+
pay_customer.save_payment_method(object, default: object.default?)
|
15
|
+
end
|
16
|
+
|
8
17
|
def initialize(pay_payment_method)
|
9
18
|
@pay_payment_method = pay_payment_method
|
10
19
|
end
|
@@ -7,6 +7,8 @@ module Pay
|
|
7
7
|
|
8
8
|
# Paddle doesn't provide PaymentMethod IDs, so we have to lookup via the Customer
|
9
9
|
def self.sync(pay_customer:, attributes: nil)
|
10
|
+
return unless pay_customer.subscription
|
11
|
+
|
10
12
|
payment_method = pay_customer.default_payment_method || pay_customer.build_default_payment_method
|
11
13
|
payment_method.processor_id ||= NanoId.generate
|
12
14
|
|
@@ -11,7 +11,7 @@ module Pay
|
|
11
11
|
|
12
12
|
# Sync default card
|
13
13
|
if (payment_method_id = pay_customer.customer.invoice_settings.default_payment_method)
|
14
|
-
Pay::Stripe::PaymentMethod.sync(payment_method_id, {stripe_account: event.account}.compact)
|
14
|
+
Pay::Stripe::PaymentMethod.sync(payment_method_id, {stripe_account: event.try(:account)}.compact)
|
15
15
|
|
16
16
|
else
|
17
17
|
# No default payment method set
|
data/lib/pay/version.rb
CHANGED
data/lib/tasks/pay.rake
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
namespace :pay do
|
2
|
+
namespace :payment_methods do
|
3
|
+
desc "Sync default payment methods for Pay::Customers"
|
4
|
+
task sync_default: :environment do
|
5
|
+
Pay::Customer.find_each do |pay_customer|
|
6
|
+
sync_default_payment_method(pay_customer)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
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
|
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: 3.0.
|
4
|
+
version: 3.0.5
|
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-09-
|
12
|
+
date: 2021-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -202,6 +202,7 @@ files:
|
|
202
202
|
- lib/pay/webhooks.rb
|
203
203
|
- lib/pay/webhooks/delegator.rb
|
204
204
|
- lib/pay/webhooks/process_job.rb
|
205
|
+
- lib/tasks/pay.rake
|
205
206
|
homepage: https://github.com/pay-rails/pay
|
206
207
|
licenses:
|
207
208
|
- MIT
|