pay 3.0.17 → 3.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2268e7ac1a9c24a08f77336d8e17b46cc0dcefc17762dfd48ad698b11a3e990c
4
- data.tar.gz: 8227fdb6f1fb10a657f5a731a200ddeb8e711884dcffafe1ffedaf06a1988c0e
3
+ metadata.gz: a37f4ee9640c9f48545166512e3ce5dfd8f17555c6181794807db5a6cc88e4ac
4
+ data.tar.gz: 994889fa6c1e3c55b836d3597f95046eaed46d1c551154c57c83543312153965
5
5
  SHA512:
6
- metadata.gz: 7b7131afb212c9ff2e0bc657ad26440b09765f2eaa7d2d50c38f110efed513c42547994b65fea9354e5d8429185ca5c5cb109e8cf5d42b57af2f95d69743cf30
7
- data.tar.gz: d0a9cabba6b63a6a087687efe94f7c13a3040550e57c150dd171ebb4d2b3df6157cd87592de10d216d7c12a4f8bff5ce6e7cb0fd72411930ba6778c0cf0f7de9
6
+ metadata.gz: d6e97f172fb3a5fbb9b62e3867fb29e363f9c5ea3f1fc385ab22a9ea59f27547ea84ca357eac1473e2ca4b25584d0c28f58f9124ca80e729cd5fa1da465d5b71
7
+ data.tar.gz: f455c3cc02a3b93f7eb5dd04c2edf0c67d0f72c3e2bddd3ced8e509a8b557705609b20dab00b0b40daab19734b46e097f2c4fcbe2f6aaf5df79f8291b75f6d3d
data/README.md CHANGED
@@ -23,7 +23,7 @@ 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
 
@@ -23,11 +23,7 @@ module Pay
23
23
  private
24
24
 
25
25
  def to
26
- if params[:billable].respond_to?(:customer_name)
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
@@ -12,10 +12,10 @@ module Pay
12
12
  return unless pay_subscription.present?
13
13
 
14
14
  pay_customer = pay_subscription.customer
15
- charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
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(billable: pay_customer.owner, charge: charge).receipt.deliver_later
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
- # billable = pay_subscription.owner
15
- # charge = Pay::Braintree::Billable.new(billable).save_transaction(subscription.transactions.first)
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(billable: billable, charge: charge).receipt.deliver_later
18
+ # Pay::UserMailer.with(pay_customer: pay_charge.customer, charge: pay_charge).receipt.deliver_later
19
19
  # end
20
20
  end
21
21
  end
@@ -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.customer.payment_methods.destroy_all
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
- charge = Pay::Charge.find_by_processor_and_id(:paddle, event.subscription_payment_id)
7
- return unless charge.present?
6
+ pay_charge = Pay::Charge.find_by_processor_and_id(:paddle, event.subscription_payment_id)
7
+ return unless pay_charge.present?
8
8
 
9
- charge.update(amount_refunded: (event.gross_refund.to_f * 100).to_i)
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(billable: billable, charge: charge).refund.deliver_later
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(pay_customer.owner, charge)
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(billable, charge)
46
- if Pay.send_emails && charge.respond_to?(:receipt)
47
- Pay::UserMailer.with(billable: billable, charge: charge).receipt.deliver_later
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
- def notify_user(billable, charge)
11
- if Pay.send_emails
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
- def notify_user(billable, charge)
11
- if Pay.send_emails && charge.respond_to?(:receipt)
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(billable: billable, payment_intent_id: payment_intent_id, subscription: subscription).payment_action_required.deliver_later
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(billable: billable, subscription: subscription, date: date).subscription_renewing.deliver_later
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
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "3.0.17"
2
+ VERSION = "3.0.18"
3
3
  end
data/lib/pay.rb CHANGED
@@ -54,12 +54,4 @@ module Pay
54
54
  def self.setup
55
55
  yield self
56
56
  end
57
-
58
- def self.receipts_supported?
59
- charge_model.respond_to?(:receipt) &&
60
- application_name.present? &&
61
- business_name &&
62
- business_address &&
63
- support_email
64
- end
65
57
  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.17
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-14 00:00:00.000000000 Z
12
+ date: 2021-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  - !ruby/object:Gem::Version
225
225
  version: '0'
226
226
  requirements: []
227
- rubygems_version: 3.2.3
227
+ rubygems_version: 3.2.22
228
228
  signing_key:
229
229
  specification_version: 4
230
230
  summary: Payments engine for Ruby on Rails