pay 4.0.1 → 4.1.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 +4 -4
- data/app/models/pay/charge.rb +2 -0
- data/config/locales/en.yml +1 -0
- data/lib/pay/receipts.rb +19 -5
- data/lib/pay/stripe/billable.rb +1 -1
- data/lib/pay/stripe/charge.rb +5 -2
- data/lib/pay/stripe/subscription.rb +2 -2
- data/lib/pay/stripe/webhooks/checkout_session_async_payment_succeeded.rb +1 -8
- data/lib/pay/stripe/webhooks/checkout_session_completed.rb +21 -2
- data/lib/pay/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b424cae3cd4905b55f734e86687c12fba5972aeade9dc81f430d364d29bd9ea6
|
4
|
+
data.tar.gz: 709ca786d171e5b5652fb1a4de5206b2564155a0adabfb02476282eefbfe473a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d153b66802f9ffea402b973ea2420f2cbb9ae6666dfe4c81d49457ac11045c06ee2e54f2ea3410fd5a7b3452461ca580e1cf52cde6831ab9238c624862cbe831
|
7
|
+
data.tar.gz: 2c22450d862a9d39d6abed5b3cc1454c657e15ab92399f64d2c306b69cf600fb2cf838d8d2080d285d42d62b0554de526a72bb7602b342eeecdeff4b49670cbd
|
data/app/models/pay/charge.rb
CHANGED
@@ -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|
|
data/config/locales/en.yml
CHANGED
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
|
-
|
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
|
89
|
-
|
89
|
+
def receipt_line_items
|
90
|
+
line_items = pdf_line_items
|
90
91
|
|
91
92
|
# Include total paid
|
92
|
-
|
93
|
+
line_items << [nil, nil, I18n.t("pay.receipt.amount_paid"), Pay::Currency.format(amount, currency: currency)]
|
93
94
|
|
94
95
|
if refunded?
|
95
|
-
|
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: [
|
data/lib/pay/stripe/billable.rb
CHANGED
@@ -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
|
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)
|
data/lib/pay/stripe/charge.rb
CHANGED
@@ -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,
|
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
|
103
|
+
{expand: ["pending_setup_intent", "latest_invoice.payment_intent", "latest_invoice.charge"]}
|
104
104
|
end
|
105
105
|
|
106
106
|
def initialize(pay_subscription)
|
@@ -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
|
-
|
9
|
-
|
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
|
data/lib/pay/version.rb
CHANGED
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
|
+
version: 4.1.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-
|
12
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|