pay 3.0.15 → 3.0.19
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/paddle/subscription.rb +15 -2
- 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: '093c067bb867fddfbdb00486613ad7be4b9e1d3d0d5ff1e22ec3d892b6bb76b3'
|
4
|
+
data.tar.gz: d4b53a841c0e7cae39f6c73786dbfbe20bc61c81dbbfe3885cbe2a0b0f830936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cee4d5e1b4ed8954e7004b121165c5e4b4dc69f5a39a01b4f9b90197ef4a8dc04cca5660488b7b2da2975a78d9cf0e5356cd30e84923af56e2460277c6c79979
|
7
|
+
data.tar.gz: 261fdecca8eb33582d279ce18f76fe4c80e3efe5fb95c479549c8c4232e53b6096a69decd3915ac12fe7792035e14e88122ef35a459090b5f4e8a710588a2b80
|
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
|
@@ -75,9 +75,19 @@ module Pay
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def cancel
|
78
|
-
ends_at = on_trial?
|
78
|
+
ends_at = if on_trial?
|
79
|
+
trial_ends_at
|
80
|
+
elsif paused?
|
81
|
+
paddle_paused_from
|
82
|
+
else
|
83
|
+
processor_subscription.next_payment&.fetch(:date) || Time.current
|
84
|
+
end
|
85
|
+
|
79
86
|
PaddlePay::Subscription::User.cancel(processor_id)
|
80
87
|
pay_subscription.update(status: :canceled, ends_at: ends_at)
|
88
|
+
|
89
|
+
# Remove payment methods since customer cannot be reused after cancelling
|
90
|
+
Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all
|
81
91
|
rescue ::PaddlePay::PaddlePayError => e
|
82
92
|
raise Pay::Paddle::Error, e
|
83
93
|
end
|
@@ -85,6 +95,9 @@ module Pay
|
|
85
95
|
def cancel_now!
|
86
96
|
PaddlePay::Subscription::User.cancel(processor_id)
|
87
97
|
pay_subscription.update(status: :canceled, ends_at: Time.current)
|
98
|
+
|
99
|
+
# Remove payment methods since customer cannot be reused after cancelling
|
100
|
+
Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all
|
88
101
|
rescue ::PaddlePay::PaddlePayError => e
|
89
102
|
raise Pay::Paddle::Error, e
|
90
103
|
end
|
@@ -100,7 +113,7 @@ module Pay
|
|
100
113
|
def pause
|
101
114
|
attributes = {pause: true}
|
102
115
|
response = PaddlePay::Subscription::User.update(processor_id, attributes)
|
103
|
-
pay_subscription.update(paddle_paused_from: Time.zone.parse(response
|
116
|
+
pay_subscription.update(paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
|
104
117
|
rescue ::PaddlePay::PaddlePayError => e
|
105
118
|
raise Pay::Paddle::Error, e
|
106
119
|
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.19
|
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
|