pay 4.0.2 → 4.1.1

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: cd5f149f88ae66352491ff4da889e6e252d491fa37467a1a7a05d635ef855f61
4
- data.tar.gz: 970ca6f6183aba7795368d5b2b78c3ddb932498bd54af20567c467d126246e10
3
+ metadata.gz: e9178fdc2803ccfa6b8552a26e34a3849702c5f0ea7143a00773dc8d51b7f373
4
+ data.tar.gz: c8da4c71a2317213e3e23b4be9651eafc4ce3df5848b4ac918d89fab916d731e
5
5
  SHA512:
6
- metadata.gz: e7fd623efada808362cef4f67d1a66919a2a74103c69cf16c859d854dc5e4ef8aed9e58cccd6addc1b2328b663824d7fa0830144ec44bceff3c2fde32a6f7131
7
- data.tar.gz: 27cad2d3b9a1fb239c5dc68282f728fadf07451b2a9c9aa29d77274077d52b608865a39f90de5d3416f69c418f75493a545f4f41f00b58bccf722a52dcfabf3e
6
+ metadata.gz: fff2d403ce33d8fe02b869b4387d164a8f50ec5b2bdfdb7d747e11987ba586e14958dc220e77379e5649340b44a12352b61e2862395ccf0991c4b3597b7261f0
7
+ data.tar.gz: 9a98e720f18f9e2572410c52d86ea3b46c08490a1a7749ea627bc7cb4ee8fe717ac7d45c90e58c8799a92d602d8b91712d08eea7ccfec7d0ec1a93b7c20af004
@@ -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|
@@ -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"
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)]
@@ -85,16 +86,29 @@ module Pay
85
86
  "#{tax_rate["display_name"]} - #{tax_rate["jurisdiction"]} (#{percent})"
86
87
  end
87
88
 
88
- def receipt_pdf(**options)
89
- receipt_line_items = pdf_line_items
89
+ def receipt_line_items
90
+ line_items = pdf_line_items
90
91
 
91
92
  # Include total paid
92
- 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)]
93
94
 
94
95
  if refunded?
95
- 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
96
106
  end
97
107
 
108
+ line_items
109
+ end
110
+
111
+ def receipt_pdf(**options)
98
112
  defaults = {
99
113
  details: receipt_details,
100
114
  recipient: [
@@ -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)
@@ -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)
@@ -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,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.invoice"]}
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.2"
2
+ VERSION = "4.1.1"
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.2
4
+ version: 4.1.1
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-27 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