pay 4.0.0 → 4.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e717b53ed9818a630f87c3847987395e9c1b66659bab7b606f13b6981ac7169
4
- data.tar.gz: 367aab7c54a527c8933f2c64c8d1efd3b02af1e7982c377f5d00341d25e598e9
3
+ metadata.gz: 6659a95f47cd229375f090cb734b440ca8484cd9672b88bd482dede070fa6819
4
+ data.tar.gz: 408ef1cbfd3364d30d7e7bbfd78c58b585034c54e65346db92f1e9a7cf3ab279
5
5
  SHA512:
6
- metadata.gz: 84250ec5485c33c88f8300fb4568eca3b4a2a31ea398eb6770b23f7c08d25e56ac5341873b724c49d5ef2d691632ad9ea97d603b6a251a33de45d22aa862f348
7
- data.tar.gz: df0b4d5551925bb9a8dd4d69427c50c944b333a37bc3cdbd13e47963903d439691823213b211f99709e5caa79df1b39b0f879ae7f4aa43cc73bae1a94dc7ae6f
6
+ metadata.gz: 8ffbc4d1d685f994a1dc3e45d8b7f20a4a4d4f8852cd3ca7d349d2af5cc22445c2c526eef8906305aa80b8d37ae82c6f0101b271a121b66d4bc4624f82446480
7
+ data.tar.gz: 12332883526b3e321e70e8b30445b40dfa85715f3a7a7bfece32940fb857f8f747b586d48245f760b9e3866a54d2532d9ca9dce8b0da55441f3b619cec14072f
@@ -1,5 +1,5 @@
1
1
  module Pay
2
- class UserMailer < ApplicationMailer
2
+ class UserMailer < Pay.parent_mailer.constantize
3
3
  def receipt
4
4
  if params[:pay_charge].respond_to? :receipt
5
5
  attachments[params[:pay_charge].filename] = params[:pay_charge].receipt
@@ -15,7 +15,7 @@ module Pay
15
15
  pay_charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
16
16
 
17
17
  if pay_charge && Pay.send_email?(:receipt, pay_charge)
18
- Pay::UserMailer.with(pay_customer: pay_customer, pay_charge: pay_charge).receipt.deliver_later
18
+ Pay.mailer.with(pay_customer: pay_customer, pay_charge: pay_charge).receipt.deliver_later
19
19
  end
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ module Pay
15
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(pay_customer: pay_charge.customer, charge: pay_charge).receipt.deliver_later
18
+ # Pay.mailer.with(pay_customer: pay_charge.customer, charge: pay_charge).receipt.deliver_later
19
19
  # end
20
20
  end
21
21
  end
@@ -9,7 +9,7 @@ module Pay
9
9
  pay_charge.update!(amount_refunded: (event.gross_refund.to_f * 100).to_i)
10
10
 
11
11
  if Pay.send_email?(:refund, pay_charge)
12
- Pay::UserMailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).refund.deliver_later
12
+ Pay.mailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).refund.deliver_later
13
13
  end
14
14
  end
15
15
  end
@@ -44,7 +44,7 @@ module Pay
44
44
 
45
45
  def notify_user(pay_charge)
46
46
  if Pay.send_email?(:receipt, pay_charge)
47
- Pay::UserMailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).receipt.deliver_later
47
+ Pay.mailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).receipt.deliver_later
48
48
  end
49
49
  end
50
50
  end
data/lib/pay/receipts.rb CHANGED
@@ -60,7 +60,8 @@ module Pay
60
60
 
61
61
  # Tax rates
62
62
  Array.wrap(total_tax_amounts).each do |tax_amount|
63
- items << [nil, nil, tax_description(tax_amount), Pay::Currency.format(tax, currency: currency)]
63
+ next if tax_amount["amount"].zero?
64
+ items << [nil, nil, tax_description(tax_amount), Pay::Currency.format(tax_amount["amount"], currency: currency)]
64
65
  end
65
66
 
66
67
  items << [nil, nil, I18n.t("pay.line_items.total"), Pay::Currency.format(amount, currency: currency)]
@@ -104,7 +104,7 @@ module Pay
104
104
  def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
105
105
  quantity = options.delete(:quantity)
106
106
  opts = {
107
- expand: ["pending_setup_intent", "latest_invoice.payment_intent", "latest_invoice.charge.invoice"],
107
+ expand: ["pending_setup_intent", "latest_invoice.payment_intent", "latest_invoice.charge"],
108
108
  items: [plan: plan, quantity: quantity],
109
109
  off_session: true
110
110
  }.merge(options)
@@ -128,7 +128,7 @@ module Pay
128
128
  else
129
129
  ::Stripe::Refund.create(options.merge(charge: processor_id, amount: amount_to_refund), stripe_options)
130
130
  end
131
- pay_charge.update!(amount_refunded: amount_to_refund)
131
+ pay_charge.update!(amount_refunded: pay_charge.amount_refunded + amount_to_refund)
132
132
  rescue ::Stripe::StripeError => e
133
133
  raise Pay::Stripe::Error, e
134
134
  end
@@ -84,7 +84,7 @@ module Pay
84
84
 
85
85
  # Sync the latest charge if we already have it loaded (like during subscrbe), otherwise, let webhooks take care of creating it
86
86
  if (charge = object.try(:latest_invoice).try(:charge)) && charge.try(:status) == "succeeded"
87
- Pay::Stripe::Charge.sync(charge.id, object: charge)
87
+ Pay::Stripe::Charge.sync(charge.id, stripe_account: pay_subscription.stripe_account)
88
88
  end
89
89
 
90
90
  pay_subscription
@@ -100,7 +100,7 @@ module Pay
100
100
 
101
101
  # Common expand options for all requests that create, retrieve, or update a Stripe Subscription
102
102
  def self.expand_options
103
- {expand: ["pending_setup_intent", "latest_invoice.payment_intent", "latest_invoice.charge.invoice"]}
103
+ {expand: ["pending_setup_intent", "latest_invoice.payment_intent", "latest_invoice.charge"]}
104
104
  end
105
105
 
106
106
  def initialize(pay_subscription)
@@ -6,7 +6,7 @@ module Pay
6
6
  pay_charge = Pay::Stripe::Charge.sync(event.data.object.id, stripe_account: event.try(:account))
7
7
 
8
8
  if pay_charge && Pay.send_email?(:refund, pay_charge)
9
- Pay::UserMailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).refund.deliver_later
9
+ Pay.mailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).refund.deliver_later
10
10
  end
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Pay
6
6
  pay_charge = Pay::Stripe::Charge.sync(event.data.object.id, stripe_account: event.try(:account))
7
7
 
8
8
  if pay_charge && Pay.send_email?(:receipt, pay_charge)
9
- Pay::UserMailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).receipt.deliver_later
9
+ Pay.mailer.with(pay_customer: pay_charge.customer, pay_charge: pay_charge).receipt.deliver_later
10
10
  end
11
11
  end
12
12
  end
@@ -1,14 +1,7 @@
1
1
  module Pay
2
2
  module Stripe
3
3
  module Webhooks
4
- class CheckoutSessionAsyncPaymentSucceeded
5
- def call(event)
6
- # TODO: Also handle payment intents
7
-
8
- if event.data.object.subscription
9
- Pay::Stripe::Subscription.sync(event.data.object.subscription, stripe_account: event.try(:account))
10
- end
11
- end
4
+ class CheckoutSessionAsyncPaymentSucceeded < CheckoutSessionCompleted
12
5
  end
13
6
  end
14
7
  end
@@ -5,10 +5,29 @@ module Pay
5
5
  def call(event)
6
6
  # TODO: Also handle payment intents
7
7
 
8
- if event.data.object.subscription
9
- Pay::Stripe::Subscription.sync(event.data.object.subscription, stripe_account: event.try(:account))
8
+ locate_owner(event.data.object)
9
+
10
+ if (payment_intent_id = event.data.object.payment_intent)
11
+ payment_intent = ::Stripe::PaymentIntent.retrieve(payment_intent_id, {stripe_account: event.try(:account)}.compact)
12
+ payment_intent.charges.each do |charge|
13
+ Pay::Stripe::Charge.sync(charge.id, stripe_account: event.try(:account))
14
+ end
15
+ end
16
+
17
+ if (subscription_id = event.data.object.subscription)
18
+ Pay::Stripe::Subscription.sync(subscription_id, stripe_account: event.try(:account))
10
19
  end
11
20
  end
21
+
22
+ def locate_owner(object)
23
+ return if object.client_reference_id.nil?
24
+
25
+ # If there is a client reference ID, make sure we have a Pay::Customer record
26
+ owner = GlobalID::Locator.locate_signed(object.client_reference_id)
27
+ owner&.add_payment_processor(:stripe, processor_id: object.customer)
28
+ rescue
29
+ Rails.logger.debug "[Pay] Unable to locate record with SGID: #{object.client_reference_id}"
30
+ end
12
31
  end
13
32
  end
14
33
  end
@@ -12,7 +12,7 @@ module Pay
12
12
  return if pay_subscription.nil?
13
13
 
14
14
  if Pay.send_email?(:payment_action_required, pay_subscription)
15
- Pay::UserMailer.with(
15
+ Pay.mailer.with(
16
16
  pay_customer: pay_subscription.customer,
17
17
  payment_intent_id: event.data.object.payment_intent,
18
18
  pay_subscription: pay_subscription
@@ -15,7 +15,7 @@ module Pay
15
15
  price = event.data.object.lines.data.first.price
16
16
 
17
17
  if Pay.send_email?(:subscription_renewing, pay_subscription, price)
18
- Pay::UserMailer.with(
18
+ Pay.mailer.with(
19
19
  pay_customer: pay_subscription.customer,
20
20
  pay_subscription: pay_subscription,
21
21
  date: Time.zone.at(event.data.object.next_payment_attempt)
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "4.0.0"
2
+ VERSION = "4.0.4"
3
3
  end
data/lib/pay.rb CHANGED
@@ -3,6 +3,8 @@ require "pay/engine"
3
3
  require "pay/errors"
4
4
  require "pay/adapter"
5
5
 
6
+ require "active_support/dependencies"
7
+
6
8
  module Pay
7
9
  autoload :Attributes, "pay/attributes"
8
10
  autoload :Env, "pay/env"
@@ -60,6 +62,20 @@ module Pay
60
62
  (price&.type == "recurring") && (price.recurring&.interval == "year")
61
63
  }
62
64
 
65
+ @@mailer = "Pay::UserMailer"
66
+
67
+ def self.mailer=(value)
68
+ @@mailer = value
69
+ @@mailer_ref = nil
70
+ end
71
+
72
+ def self.mailer
73
+ @@mailer_ref ||= @@mailer&.constantize
74
+ end
75
+
76
+ mattr_accessor :parent_mailer
77
+ @@parent_mailer = "Pay::ApplicationMailer"
78
+
63
79
  def self.setup
64
80
  yield self
65
81
  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: 4.0.0
4
+ version: 4.0.4
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: 2022-05-10 00:00:00.000000000 Z
12
+ date: 2022-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails