pay 3.0.14 → 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: 775a299c417f1325003083f1a919358c46169daa859454e987adbb7eeab1393e
4
- data.tar.gz: 7315d0e4ea8905ceb3f90b4edc3882f122934423f1a3d591e930a0c3f7c68195
3
+ metadata.gz: a37f4ee9640c9f48545166512e3ce5dfd8f17555c6181794807db5a6cc88e4ac
4
+ data.tar.gz: 994889fa6c1e3c55b836d3597f95046eaed46d1c551154c57c83543312153965
5
5
  SHA512:
6
- metadata.gz: 336cba7171af162ec7f7bc3251bda72f94c4ae36bd5795cb7b0f0930da13de06a0d8f1cf0746d22199de513cbc59d753f70b704748dc2d531e581b5f5b697f00
7
- data.tar.gz: 5e21ad2c19091786ec6d8fb35a261b644dc6142d3452fdec2681543824e3f81fbe45c37f7f15463565036801a3f3253c4ce2e589920d11df05b596f32b12ad8e
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 witha single payment provider in that case so you don't run into discrepancies.
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
- 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
@@ -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: USD <%= params[:charge].amount_with_currency %><br/>
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: USD <%= params[:charge].amount_refunded_with_currency %><br/>
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
- 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
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.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.14"
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.14
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-11 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