pay 4.0.4 → 4.2.0

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: 6659a95f47cd229375f090cb734b440ca8484cd9672b88bd482dede070fa6819
4
- data.tar.gz: 408ef1cbfd3364d30d7e7bbfd78c58b585034c54e65346db92f1e9a7cf3ab279
3
+ metadata.gz: 21dbf64c59853ff5226ba4896f3d25c29625182637cc4ac43f9eaffb60433ec7
4
+ data.tar.gz: e0cd4bfa462306aa0ddf15244a2d536c36a97e45b2d4acb2564cee9c8143351b
5
5
  SHA512:
6
- metadata.gz: 8ffbc4d1d685f994a1dc3e45d8b7f20a4a4d4f8852cd3ca7d349d2af5cc22445c2c526eef8906305aa80b8d37ae82c6f0101b271a121b66d4bc4624f82446480
7
- data.tar.gz: 12332883526b3e321e70e8b30445b40dfa85715f3a7a7bfece32940fb857f8f747b586d48245f760b9e3866a54d2532d9ca9dce8b0da55441f3b619cec14072f
6
+ metadata.gz: e3b007b3190cb534dec8953486a21fca0b9fe82d26a1caa80dc27a405f835bbb8424c034508e8adc5f36ce3d9ae526a4334d1a5a315b43ebba472dc60f0772f1
7
+ data.tar.gz: 0f0390f51f53fad304ceb5866d1f68a3a5af7272ce33403c27b0362e916d0ad20de756f77a3375f466ec8866d0d2a97e006a15c6dd3f18ac221fb4fc10d3f467
@@ -41,6 +41,8 @@ module Pay
41
41
  store_accessor :data, :discounts # array of discount IDs applied to the Stripe Invoice
42
42
  store_accessor :data, :total_discount_amounts # array of discount details
43
43
  store_accessor :data, :total_tax_amounts # array of tax details for each jurisdiction
44
+ store_accessor :data, :credit_notes # array of credit notes for the Stripe Invoice
45
+ store_accessor :data, :refunds # array of refunds
44
46
 
45
47
  # Helpers for payment processors
46
48
  %w[braintree stripe paddle fake_processor].each do |processor_name|
@@ -11,7 +11,9 @@ module Pay
11
11
  scope :on_trial, -> { where.not(trial_ends_at: nil).where("#{table_name}.trial_ends_at > ?", Time.zone.now) }
12
12
  scope :cancelled, -> { where.not(ends_at: nil) }
13
13
  scope :on_grace_period, -> { cancelled.where("#{table_name}.ends_at > ?", Time.zone.now) }
14
- scope :active, -> { where(status: ["trialing", "active"], ends_at: nil).or(on_grace_period).or(on_trial) }
14
+ # Stripe considers paused subscriptions to be active, therefore we reflect that in this scope and
15
+ # make it consistent across all processors
16
+ scope :active, -> { where(status: ["trialing", "active", "paused"], ends_at: nil).or(on_grace_period).or(on_trial) }
15
17
  scope :incomplete, -> { where(status: :incomplete) }
16
18
  scope :past_due, -> { where(status: :past_due) }
17
19
  scope :with_active_customer, -> { joins(:customer).merge(Customer.active) }
@@ -49,6 +51,18 @@ module Pay
49
51
  scope processor_name, -> { joins(:customer).where(pay_customers: {processor: processor_name}) }
50
52
  end
51
53
 
54
+ def self.active_without_paused
55
+ case Pay::Adapter.current_adapter
56
+ when "postgresql", "postgis"
57
+ active.where("data->>'pause_behavior' IS NULL AND status != 'paused'")
58
+ when "mysql2"
59
+ active.where("data->>'$.pause_behavior' IS NULL AND status != 'paused'")
60
+ when "sqlite3"
61
+ # sqlite 3.38 supports ->> syntax, however, sqlite 3.37 is what ships with Ubuntu 22.04.
62
+ active.where("json_extract(data, '$.pause_behavior') IS NULL AND status != 'paused'")
63
+ end
64
+ end
65
+
52
66
  def self.with_metered_items
53
67
  case Pay::Adapter.current_adapter
54
68
  when "sqlite3"
@@ -108,7 +122,7 @@ module Pay
108
122
  end
109
123
 
110
124
  def active?
111
- ["trialing", "active"].include?(status) && (ends_at.nil? || on_grace_period? || on_trial?)
125
+ ["trialing", "active", "paused"].include?(status) && (ends_at.nil? || on_grace_period? || on_trial?)
112
126
  end
113
127
 
114
128
  def past_due?
@@ -35,6 +35,7 @@ en:
35
35
  payment_method: "Payment Method"
36
36
  amount_paid: "Amount paid"
37
37
  refunded: "Refunded"
38
+ refunded_on: "Refunded on %{date}"
38
39
  invoice:
39
40
  number: "Invoice Number"
40
41
  date: "Date"
@@ -107,13 +107,13 @@ module Pay
107
107
  end
108
108
 
109
109
  def paused?
110
- paddle_paused_from.present?
110
+ pay_subscription.status == "paused"
111
111
  end
112
112
 
113
113
  def pause
114
114
  attributes = {pause: true}
115
115
  response = PaddlePay::Subscription::User.update(processor_id, attributes)
116
- pay_subscription.update(paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
116
+ pay_subscription.update(status: :paused, paddle_paused_from: Time.zone.parse(response.dig(:next_payment, :date)))
117
117
  rescue ::PaddlePay::PaddlePayError => e
118
118
  raise Pay::Paddle::Error, e
119
119
  end
data/lib/pay/receipts.rb CHANGED
@@ -86,16 +86,29 @@ module Pay
86
86
  "#{tax_rate["display_name"]} - #{tax_rate["jurisdiction"]} (#{percent})"
87
87
  end
88
88
 
89
- def receipt_pdf(**options)
90
- receipt_line_items = pdf_line_items
89
+ def receipt_line_items
90
+ line_items = pdf_line_items
91
91
 
92
92
  # Include total paid
93
- receipt_line_items << [nil, nil, I18n.t("pay.receipt.amount_paid"), Pay::Currency.format(amount, currency: currency)]
93
+ line_items << [nil, nil, I18n.t("pay.receipt.amount_paid"), Pay::Currency.format(amount, currency: currency)]
94
94
 
95
95
  if refunded?
96
- receipt_line_items << [nil, nil, I18n.t("pay.receipt.refunded_on"), Pay::Currency.format(amount_refunded, currency: currency)]
96
+ # If we have a list of individual refunds, add each entry
97
+ if refunds&.any?
98
+ refunds.each do |refund|
99
+ next unless refund["status"] == "succeeded"
100
+ refunded_at = Time.at(refund["created"]).to_date
101
+ line_items << [nil, nil, I18n.t("pay.receipt.refunded_on", date: I18n.l(refunded_at, format: :long)), Pay::Currency.format(refund["amount"], currency: refund["currency"])]
102
+ end
103
+ else
104
+ line_items << [nil, nil, I18n.t("pay.receipt.refunded"), Pay::Currency.format(amount_refunded, currency: currency)]
105
+ end
97
106
  end
98
107
 
108
+ line_items
109
+ end
110
+
111
+ def receipt_pdf(**options)
99
112
  defaults = {
100
113
  details: receipt_details,
101
114
  recipient: [
@@ -22,6 +22,9 @@ module Pay
22
22
  pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
23
23
  return unless pay_customer
24
24
 
25
+ refunds = []
26
+ object.refunds.auto_paging_each { |refund| refunds << refund }
27
+
25
28
  payment_method = object.payment_method_details.send(object.payment_method_details.type)
26
29
  attrs = {
27
30
  amount: object.amount,
@@ -42,7 +45,8 @@ module Pay
42
45
  payment_method_type: object.payment_method_details.type,
43
46
  stripe_account: pay_customer.stripe_account,
44
47
  stripe_receipt_url: object.receipt_url,
45
- total_tax_amounts: []
48
+ total_tax_amounts: [],
49
+ refunds: refunds.sort_by! { |r| r["created"] }
46
50
  }
47
51
 
48
52
  # Associate charge with subscription if we can
@@ -75,7 +79,6 @@ module Pay
75
79
  period_end: Time.at(line_item.period.end)
76
80
  }
77
81
  end
78
-
79
82
  # Charges without invoices
80
83
  else
81
84
  attrs[:period_start] = Time.at(object.created)
@@ -100,7 +100,15 @@ 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"]}
103
+ {
104
+ expand: [
105
+ "pending_setup_intent",
106
+ "latest_invoice.payment_intent",
107
+ "latest_invoice.charge",
108
+ "latest_invoice.total_discount_amounts.discount",
109
+ "latest_invoice.total_tax_amounts.tax_rate"
110
+ ]
111
+ }
104
112
  end
105
113
 
106
114
  def initialize(pay_subscription)
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "4.0.4"
2
+ VERSION = "4.2.0"
3
3
  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.4
4
+ version: 4.2.0
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-07-28 00:00:00.000000000 Z
12
+ date: 2022-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails