pay 3.0.14 → 3.0.18
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 +2 -2
- data/app/mailers/pay/user_mailer.rb +1 -5
- data/app/models/pay/subscription.rb +10 -0
- data/app/views/pay/user_mailer/receipt.html.erb +1 -1
- data/app/views/pay/user_mailer/refund.html.erb +1 -1
- data/lib/pay/braintree/webhooks/subscription_charged_successfully.rb +3 -3
- data/lib/pay/braintree/webhooks/subscription_charged_unsuccessfully.rb +3 -3
- data/lib/pay/currency.rb +2 -2
- data/lib/pay/paddle/subscription.rb +6 -0
- data/lib/pay/paddle/webhooks/subscription_cancelled.rb +1 -1
- data/lib/pay/paddle/webhooks/subscription_payment_refunded.rb +4 -7
- data/lib/pay/paddle/webhooks/subscription_payment_succeeded.rb +4 -4
- data/lib/pay/stripe/webhooks/charge_refunded.rb +2 -5
- data/lib/pay/stripe/webhooks/charge_succeeded.rb +2 -5
- data/lib/pay/stripe/webhooks/payment_action_required.rb +5 -6
- data/lib/pay/stripe/webhooks/subscription_renewing.rb +5 -5
- data/lib/pay/version.rb +1 -1
- data/lib/pay.rb +0 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a37f4ee9640c9f48545166512e3ce5dfd8f17555c6181794807db5a6cc88e4ac
|
4
|
+
data.tar.gz: 994889fa6c1e3c55b836d3597f95046eaed46d1c551154c57c83543312153965
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6e97f172fb3a5fbb9b62e3867fb29e363f9c5ea3f1fc385ab22a9ea59f27547ea84ca357eac1473e2ca4b25584d0c28f58f9124ca80e729cd5fa1da465d5b71
|
7
|
+
data.tar.gz: f455c3cc02a3b93f7eb5dd04c2edf0c67d0f72c3e2bddd3ced8e509a8b557705609b20dab00b0b40daab19734b46e097f2c4fcbe2f6aaf5df79f8291b75f6d3d
|
data/README.md
CHANGED
@@ -23,11 +23,11 @@ Our supported payment processors are:
|
|
23
23
|
- Stripe ([SCA Compatible](https://stripe.com/docs/strong-customer-authentication) using API version `2020-08-27`)
|
24
24
|
- Paddle (SCA Compatible & supports PayPal)
|
25
25
|
- Braintree (supports PayPal)
|
26
|
-
- [Fake Processor](docs/fake_processor.md) (used for generic trials without cards, free subscriptions, testing, etc)
|
26
|
+
- [Fake Processor](docs/fake_processor/1_overview.md) (used for generic trials without cards, free subscriptions, testing, etc)
|
27
27
|
|
28
28
|
Want to add a new payment provider? Contributions are welcome.
|
29
29
|
|
30
|
-
> We make our best attempt to standardize the different payment providers. They function differently so keep that in mind if you plan on doing more complex payments. It would be best to stick
|
30
|
+
> We make our best attempt to standardize the different payment providers. They function differently so keep that in mind if you plan on doing more complex payments. It would be best to stick with a single payment provider in that case so you don't run into discrepancies.
|
31
31
|
|
32
32
|
## 📚 Docs
|
33
33
|
|
@@ -23,11 +23,7 @@ module Pay
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def to
|
26
|
-
|
27
|
-
"#{params[:billable].customer_name} <#{params[:billable].email}>"
|
28
|
-
else
|
29
|
-
params[:billable].email
|
30
|
-
end
|
26
|
+
"#{params[:pay_customer].customer_name} <#{params[:pay_customer].email}>"
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -70,6 +70,10 @@ module Pay
|
|
70
70
|
self.trial_ends_at = nil
|
71
71
|
end
|
72
72
|
|
73
|
+
def generic_trial?
|
74
|
+
fake_processor? && trial_ends_at?
|
75
|
+
end
|
76
|
+
|
73
77
|
def on_trial?
|
74
78
|
trial_ends_at? && Time.zone.now < trial_ends_at
|
75
79
|
end
|
@@ -128,6 +132,12 @@ module Pay
|
|
128
132
|
processor_subscription(expand: ["latest_invoice.payment_intent"]).latest_invoice.payment_intent
|
129
133
|
end
|
130
134
|
|
135
|
+
def paddle_paused_from
|
136
|
+
if (timestamp = super)
|
137
|
+
Time.zone.parse(timestamp)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
131
141
|
private
|
132
142
|
|
133
143
|
def cancel_if_active
|
@@ -5,7 +5,7 @@ Questions? Please reply to this email.<br/>
|
|
5
5
|
------------------------------------<br/>
|
6
6
|
RECEIPT - SUBSCRIPTION<br/>
|
7
7
|
<br/>
|
8
|
-
Amount:
|
8
|
+
Amount: <%= params[:charge].amount_with_currency %><br/>
|
9
9
|
<br/>
|
10
10
|
Charged to: <%= params[:charge].charged_to %><br/>
|
11
11
|
Transaction ID: <%= params[:charge].id %><br/>
|
@@ -6,7 +6,7 @@ Questions? Please reply to this email.<br/>
|
|
6
6
|
------------------------------------<br/>
|
7
7
|
RECEIPT - REFUND<br/>
|
8
8
|
<br/>
|
9
|
-
Amount:
|
9
|
+
Amount: <%= params[:charge].amount_refunded_with_currency %><br/>
|
10
10
|
<br/>
|
11
11
|
Refunded to: <%= params[:charge].charged_to %><br/>
|
12
12
|
Transaction ID: <%= params[:charge].id %><br/>
|
@@ -12,10 +12,10 @@ module Pay
|
|
12
12
|
return unless pay_subscription.present?
|
13
13
|
|
14
14
|
pay_customer = pay_subscription.customer
|
15
|
-
|
15
|
+
pay_charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
|
16
16
|
|
17
|
-
if Pay.send_emails
|
18
|
-
Pay::UserMailer.with(
|
17
|
+
if pay_charge && Pay.send_emails
|
18
|
+
Pay::UserMailer.with(pay_customer: pay_customer, charge: pay_charge).receipt.deliver_later
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -11,11 +11,11 @@ module Pay
|
|
11
11
|
pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
|
12
12
|
return unless pay_subscription.present?
|
13
13
|
|
14
|
-
#
|
15
|
-
#
|
14
|
+
# pay_customer = pay_subscription.customer
|
15
|
+
# pay_charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
|
16
16
|
|
17
17
|
# if Pay.send_emails
|
18
|
-
# Pay::UserMailer.with(
|
18
|
+
# Pay::UserMailer.with(pay_customer: pay_charge.customer, charge: pay_charge).receipt.deliver_later
|
19
19
|
# end
|
20
20
|
end
|
21
21
|
end
|
data/lib/pay/currency.rb
CHANGED
@@ -12,9 +12,9 @@ module Pay
|
|
12
12
|
end
|
13
13
|
|
14
14
|
# Takes an amount (in cents) and currency and returns the formatted version for the currency
|
15
|
-
def self.format(amount, currency
|
15
|
+
def self.format(amount, currency:, **options)
|
16
16
|
currency ||= :usd
|
17
|
-
new(currency).format_amount(amount)
|
17
|
+
new(currency).format_amount(amount, **options)
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize(iso_code)
|
@@ -78,6 +78,9 @@ module Pay
|
|
78
78
|
ends_at = on_trial? ? trial_ends_at : processor_subscription.next_payment[:date]
|
79
79
|
PaddlePay::Subscription::User.cancel(processor_id)
|
80
80
|
pay_subscription.update(status: :canceled, ends_at: ends_at)
|
81
|
+
|
82
|
+
# Remove payment methods since customer cannot be reused after cancelling
|
83
|
+
Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all
|
81
84
|
rescue ::PaddlePay::PaddlePayError => e
|
82
85
|
raise Pay::Paddle::Error, e
|
83
86
|
end
|
@@ -85,6 +88,9 @@ module Pay
|
|
85
88
|
def cancel_now!
|
86
89
|
PaddlePay::Subscription::User.cancel(processor_id)
|
87
90
|
pay_subscription.update(status: :canceled, ends_at: Time.current)
|
91
|
+
|
92
|
+
# Remove payment methods since customer cannot be reused after cancelling
|
93
|
+
Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all
|
88
94
|
rescue ::PaddlePay::PaddlePayError => e
|
89
95
|
raise Pay::Paddle::Error, e
|
90
96
|
end
|
@@ -13,7 +13,7 @@ module Pay
|
|
13
13
|
pay_subscription.update!(ends_at: Time.zone.parse(event.cancellation_effective_date)) if pay_subscription.ends_at.blank? && event.cancellation_effective_date.present?
|
14
14
|
|
15
15
|
# Paddle doesn't allow reusing customers, so we should remove their payment methods
|
16
|
-
pay_subscription.
|
16
|
+
Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -3,16 +3,13 @@ module Pay
|
|
3
3
|
module Webhooks
|
4
4
|
class SubscriptionPaymentRefunded
|
5
5
|
def call(event)
|
6
|
-
|
7
|
-
return unless
|
6
|
+
pay_charge = Pay::Charge.find_by_processor_and_id(:paddle, event.subscription_payment_id)
|
7
|
+
return unless pay_charge.present?
|
8
8
|
|
9
|
-
|
10
|
-
notify_user(charge.customer.owner, charge)
|
11
|
-
end
|
9
|
+
pay_charge.update(amount_refunded: (event.gross_refund.to_f * 100).to_i)
|
12
10
|
|
13
|
-
def notify_user(billable, charge)
|
14
11
|
if Pay.send_emails
|
15
|
-
Pay::UserMailer.with(
|
12
|
+
Pay::UserMailer.with(pay_customer: pay_charge.customer, charge: pay_charge).refund.deliver_later
|
16
13
|
end
|
17
14
|
end
|
18
15
|
end
|
@@ -18,7 +18,7 @@ module Pay
|
|
18
18
|
return if pay_customer.charges.where(processor_id: event.subscription_payment_id).any?
|
19
19
|
|
20
20
|
charge = create_charge(pay_customer, event)
|
21
|
-
notify_user(
|
21
|
+
notify_user(charge)
|
22
22
|
end
|
23
23
|
|
24
24
|
def create_charge(pay_customer, event)
|
@@ -42,9 +42,9 @@ module Pay
|
|
42
42
|
charge
|
43
43
|
end
|
44
44
|
|
45
|
-
def notify_user(
|
46
|
-
if Pay.send_emails
|
47
|
-
Pay::UserMailer.with(
|
45
|
+
def notify_user(pay_charge)
|
46
|
+
if Pay.send_emails
|
47
|
+
Pay::UserMailer.with(pay_customer: pay_charge.customer, charge: pay_charge).receipt.deliver_later
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -4,12 +4,9 @@ module Pay
|
|
4
4
|
class ChargeRefunded
|
5
5
|
def call(event)
|
6
6
|
pay_charge = Pay::Stripe::Charge.sync(event.data.object.id, stripe_account: event.try(:account))
|
7
|
-
notify_user(pay_charge.customer.owner, pay_charge) if pay_charge
|
8
|
-
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
Pay::UserMailer.with(billable: billable, charge: charge).refund.deliver_later
|
8
|
+
if pay_charge && Pay.send_emails
|
9
|
+
Pay::UserMailer.with(pay_customer: pay_charge.customer, charge: pay_charge).refund.deliver_later
|
13
10
|
end
|
14
11
|
end
|
15
12
|
end
|
@@ -4,12 +4,9 @@ module Pay
|
|
4
4
|
class ChargeSucceeded
|
5
5
|
def call(event)
|
6
6
|
pay_charge = Pay::Stripe::Charge.sync(event.data.object.id, stripe_account: event.try(:account))
|
7
|
-
notify_user(pay_charge.customer.owner, pay_charge) if pay_charge
|
8
|
-
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
Pay::UserMailer.with(billable: billable, charge: charge).receipt.deliver_later
|
8
|
+
if pay_charge && Pay.send_emails
|
9
|
+
Pay::UserMailer.with(pay_customer: pay_charge.customer, charge: pay_charge).receipt.deliver_later
|
13
10
|
end
|
14
11
|
end
|
15
12
|
end
|
@@ -10,14 +10,13 @@ module Pay
|
|
10
10
|
|
11
11
|
subscription = Pay::Subscription.find_by_processor_and_id(:stripe, object.subscription)
|
12
12
|
return if subscription.nil?
|
13
|
-
billable = subscription.customer.owner
|
14
13
|
|
15
|
-
notify_user(billable, event.data.object.payment_intent, subscription)
|
16
|
-
end
|
17
|
-
|
18
|
-
def notify_user(billable, payment_intent_id, subscription)
|
19
14
|
if Pay.send_emails
|
20
|
-
Pay::UserMailer.with(
|
15
|
+
Pay::UserMailer.with(
|
16
|
+
pay_customer: subscription.customer,
|
17
|
+
payment_intent_id: event.data.object.payment_intent,
|
18
|
+
subscription: subscription
|
19
|
+
).payment_action_required.deliver_later
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
@@ -18,12 +18,12 @@ module Pay
|
|
18
18
|
interval = price.recurring.interval
|
19
19
|
return unless interval == "year"
|
20
20
|
|
21
|
-
notify_user(subscription.customer.owner, subscription, Time.zone.at(event.data.object.next_payment_attempt))
|
22
|
-
end
|
23
|
-
|
24
|
-
def notify_user(billable, subscription, date)
|
25
21
|
if Pay.send_emails
|
26
|
-
Pay::UserMailer.with(
|
22
|
+
Pay::UserMailer.with(
|
23
|
+
pay_customer: subscription.customer,
|
24
|
+
subscription: subscription,
|
25
|
+
date: Time.zone.at(event.data.object.next_payment_attempt)
|
26
|
+
).subscription_renewing.deliver_later
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/pay/version.rb
CHANGED
data/lib/pay.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: 3.0.
|
4
|
+
version: 3.0.18
|
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-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|