spree_core 6.0.5 → 6.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/jobs/spree/payments/handle_modification_webhook_job.rb +93 -0
- data/app/jobs/spree/payments/handle_webhook_job.rb +4 -2
- data/app/maintenance_tasks/spree/maintenance_tasks/upgrade/backfill_settlement_statuses.rb +40 -0
- data/app/models/concerns/spree/customer_methods.rb +1 -1
- data/app/models/concerns/spree/product_scopes.rb +5 -2
- data/app/models/concerns/spree/purchase/payment_processing.rb +11 -0
- data/app/models/concerns/spree/purchase/purchase_order.rb +21 -0
- data/app/models/concerns/spree/purchase/totals.rb +3 -2
- data/app/models/concerns/spree/ransackable_attributes.rb +81 -4
- data/app/models/concerns/spree/settlement_status.rb +29 -0
- data/app/models/concerns/spree/stores/markets.rb +0 -30
- data/app/models/spree/base.rb +3 -3
- data/app/models/spree/category.rb +53 -32
- data/app/models/spree/collection_rule.rb +5 -1
- data/app/models/spree/export.rb +3 -1
- data/app/models/spree/exports/products.rb +9 -1
- data/app/models/spree/fulfillment.rb +23 -6
- data/app/models/spree/fulfillment_group.rb +2 -2
- data/app/models/spree/gateway/bogus.rb +41 -2
- data/app/models/spree/gift_card.rb +14 -2
- data/app/models/spree/media.rb +1 -1
- data/app/models/spree/option_type.rb +1 -0
- data/app/models/spree/order.rb +10 -4
- data/app/models/spree/order_group.rb +2 -2
- data/app/models/spree/payment/custom_events.rb +2 -1
- data/app/models/spree/payment/processing.rb +20 -3
- data/app/models/spree/payment.rb +186 -7
- data/app/models/spree/payment_capture_event.rb +2 -0
- data/app/models/spree/payment_method/store_credit.rb +6 -0
- data/app/models/spree/payment_method.rb +54 -2
- data/app/models/spree/payment_response.rb +19 -0
- data/app/models/spree/payment_session.rb +15 -3
- data/app/models/spree/payment_split.rb +14 -2
- data/app/models/spree/price.rb +1 -0
- data/app/models/spree/product.rb +4 -4
- data/app/models/spree/purchase_order.rb +20 -3
- data/app/models/spree/refund.rb +7 -1
- data/app/models/spree/return.rb +7 -1
- data/app/models/spree/search_provider/base.rb +10 -0
- data/app/models/spree/search_provider/database.rb +8 -5
- data/app/models/spree/store.rb +22 -0
- data/app/models/spree/store_credit.rb +1 -1
- data/app/models/spree/variant.rb +33 -0
- data/app/presenters/spree/csv/product_variant_presenter.rb +17 -8
- data/app/serializers/spree/emails/store_serializer.rb +1 -1
- data/app/services/spree/carts/split_by_seller.rb +4 -13
- data/app/services/spree/orders/create_from_cart.rb +2 -0
- data/app/services/spree/orders/update_statuses.rb +4 -2
- data/app/services/spree/store_credits/apply.rb +1 -1
- data/app/subscribers/spree/order_status_subscriber.rb +4 -3
- data/app/subscribers/spree/payment_split_subscriber.rb +39 -21
- data/app/subscribers/spree/seller_transfer_reversal_subscriber.rb +19 -7
- data/app/tools/spree/agent_tools/query_report.rb +116 -14
- data/app/workflows/spree/carts/complete.rb +1 -19
- data/app/workflows/spree/carts/recalculate_totals.rb +3 -3
- data/app/workflows/spree/orders/cancel.rb +19 -0
- data/app/workflows/spree/orders/complete.rb +7 -1
- data/app/workflows/spree/payments/capture.rb +99 -5
- data/app/workflows/spree/payments/handle_modification_webhook.rb +218 -0
- data/app/workflows/spree/payments/handle_webhook.rb +7 -1
- data/app/workflows/spree/payments/process.rb +47 -4
- data/app/workflows/spree/payments/void.rb +4 -1
- data/app/workflows/spree/products/approve.rb +17 -0
- data/app/workflows/spree/refunds/create.rb +10 -1
- data/app/workflows/spree/refunds/order_payments.rb +3 -1
- data/config/locales/be.yml +2 -2
- data/config/locales/bg.yml +4 -4
- data/config/locales/en.yml +8 -0
- data/config/locales/ru.yml +3 -3
- data/db/migrate/20261116100001_add_status_to_spree_payment_capture_events_and_refunds.rb +17 -0
- data/lib/spree/agent_tool.rb +11 -4
- data/lib/spree/core/dependencies.rb +1 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/reporting/adapters/live.rb +69 -8
- data/lib/spree/reporting/default_vocabulary.rb +10 -4
- data/lib/spree/reporting/query.rb +4 -1
- data/lib/spree/reporting/registry.rb +50 -3
- data/lib/spree/testing_support/factories/payment_capture_event_factory.rb +10 -0
- data/lib/spree/testing_support/factories/refund_factory.rb +10 -0
- data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +57 -0
- metadata +23 -4
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Payments
|
|
3
|
+
# Applies a provider's answer to a capture, void or refund it accepted
|
|
4
|
+
# earlier: the outcome a gateway that answered +requested?+ reports by
|
|
5
|
+
# webhook.
|
|
6
|
+
#
|
|
7
|
+
# A repeat delivery changes nothing: an outcome for a record already past
|
|
8
|
+
# +requested+ is ignored, except a failure arriving after a success, which
|
|
9
|
+
# providers may send days later and which takes the money back.
|
|
10
|
+
class HandleModificationWebhook < Spree::Workflow
|
|
11
|
+
# The record each outcome settles, as PaymentMethod#modification_record finds it.
|
|
12
|
+
RECORD_CLASSES = {
|
|
13
|
+
'capture_event' => 'Spree::PaymentCaptureEvent',
|
|
14
|
+
'payment' => 'Spree::Payment',
|
|
15
|
+
'refund' => 'Spree::Refund'
|
|
16
|
+
}.freeze
|
|
17
|
+
OUTCOME_RECORDS = {
|
|
18
|
+
capture_succeeded: 'capture_event', capture_failed: 'capture_event',
|
|
19
|
+
void_succeeded: 'payment', void_failed: 'payment',
|
|
20
|
+
refund_succeeded: 'refund', refund_failed: 'refund'
|
|
21
|
+
}.freeze
|
|
22
|
+
|
|
23
|
+
# @param payment_method [Spree::PaymentMethod] the method that received the webhook
|
|
24
|
+
# @param action [Symbol] one of the six outcomes
|
|
25
|
+
# @param record [Spree::PaymentCaptureEvent, Spree::Payment, Spree::Refund]
|
|
26
|
+
# the capture event, payment or refund the outcome names
|
|
27
|
+
# @param metadata [Hash] the provider's reason for a failure under 'reason'
|
|
28
|
+
def perform(payment_method:, action:, record:, metadata: {})
|
|
29
|
+
super
|
|
30
|
+
@payment = record.is_a?(Spree::Payment) ? record : record.payment
|
|
31
|
+
@events = []
|
|
32
|
+
|
|
33
|
+
step :ensure_known_outcome
|
|
34
|
+
step :ensure_payment_method_owns_record
|
|
35
|
+
|
|
36
|
+
step :apply_outcome
|
|
37
|
+
external_step :authorize_remainder
|
|
38
|
+
step :rederive_order_figures
|
|
39
|
+
|
|
40
|
+
@events.each { |(publisher, name, metadata)| publisher.publish_event(name, nil, metadata || {}) }
|
|
41
|
+
success(record)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
attr_reader :payment, :remainder
|
|
47
|
+
|
|
48
|
+
def ensure_known_outcome
|
|
49
|
+
expected = RECORD_CLASSES[OUTCOME_RECORDS[action]]&.constantize
|
|
50
|
+
|
|
51
|
+
mismatch!("#{action} does not name a #{record.class.name}") unless expected && record.is_a?(expected)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def ensure_payment_method_owns_record
|
|
55
|
+
mismatch!('The outcome names a payment of another payment method') unless payment.payment_method_id == payment_method.id
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# A parser naming the wrong record fails the same way on every retry, so
|
|
59
|
+
# it is reported and the delivery is not acted on.
|
|
60
|
+
def mismatch!(message)
|
|
61
|
+
Rails.error.report(ArgumentError.new(message),
|
|
62
|
+
handled: true, context: { record: record.class.name, record_id: record.id },
|
|
63
|
+
source: 'spree.payments.modification_webhook')
|
|
64
|
+
halt!(record)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Locked because a redelivery of the same outcome races this one, and
|
|
68
|
+
# the capture request that wrote the record may still be finishing.
|
|
69
|
+
def apply_outcome
|
|
70
|
+
payment.with_lock do
|
|
71
|
+
record.reload
|
|
72
|
+
# A session payment carries no Spree-side source unless its gateway
|
|
73
|
+
# built one, so the requirement is skipped, as settlement does.
|
|
74
|
+
payment.skip_source_requirement = true if payment.source.blank?
|
|
75
|
+
|
|
76
|
+
case action
|
|
77
|
+
when :capture_succeeded then capture_succeeded
|
|
78
|
+
when :capture_failed then capture_failed
|
|
79
|
+
when :void_succeeded then void_succeeded
|
|
80
|
+
when :void_failed then void_failed
|
|
81
|
+
when :refund_succeeded then refund_succeeded
|
|
82
|
+
when :refund_failed then refund_failed
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def capture_succeeded
|
|
88
|
+
return unless record.requested?
|
|
89
|
+
|
|
90
|
+
record.update!(status: 'completed')
|
|
91
|
+
# Split before completing, so payment.completed publishes with the
|
|
92
|
+
# captured amount, as the capture workflow does for an answer given at once.
|
|
93
|
+
@remainder = payment.split_uncaptured_amount
|
|
94
|
+
payment.complete!
|
|
95
|
+
settle_claimed_share(record.amount, captured: true)
|
|
96
|
+
@events << [payment, 'payment.captured']
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def capture_failed
|
|
100
|
+
return if record.failed?
|
|
101
|
+
|
|
102
|
+
@late_failure = record.completed?
|
|
103
|
+
record.update!(status: 'failed')
|
|
104
|
+
payment.update!(status: 'failed')
|
|
105
|
+
record_reason_on_payment
|
|
106
|
+
|
|
107
|
+
if @late_failure
|
|
108
|
+
take_back_captured_share(record.amount)
|
|
109
|
+
else
|
|
110
|
+
settle_claimed_share(record.amount, captured: false)
|
|
111
|
+
end
|
|
112
|
+
@events << [payment, 'payment.capture_failed']
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def void_succeeded
|
|
116
|
+
return unless payment.requested_action == 'void'
|
|
117
|
+
|
|
118
|
+
payment.void!
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# The authorization still holds, so the payment goes back to what it was:
|
|
122
|
+
# captured if money was taken, otherwise waiting for a capture.
|
|
123
|
+
def void_failed
|
|
124
|
+
return unless payment.requested_action == 'void'
|
|
125
|
+
|
|
126
|
+
payment.update!(status: payment.captured_amount.positive? ? 'completed' : 'pending')
|
|
127
|
+
record_reason_on_payment
|
|
128
|
+
@events << [payment, 'payment.void_failed']
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def refund_succeeded
|
|
132
|
+
return unless record.requested?
|
|
133
|
+
|
|
134
|
+
record.update!(status: 'completed')
|
|
135
|
+
@events << [payment, 'payment.refunded', { refund_id: record.prefixed_id }]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def refund_failed
|
|
139
|
+
return if record.failed?
|
|
140
|
+
|
|
141
|
+
record.update!(status: 'failed', failure_reason: reason)
|
|
142
|
+
@events << [record, 'refund.failed']
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# A split-checkout parcel reserved its share before asking the provider;
|
|
146
|
+
# the outcome turns that claim into captured money, or releases it.
|
|
147
|
+
def settle_claimed_share(amount, captured:)
|
|
148
|
+
remaining = amount
|
|
149
|
+
payment.payment_splits.each do |split|
|
|
150
|
+
next unless split.capture_in_flight? && remaining.positive?
|
|
151
|
+
|
|
152
|
+
# Under the share's own lock, as dispatch writes it, so a parcel
|
|
153
|
+
# claiming the same share meanwhile is not overwritten.
|
|
154
|
+
settled = split.with_lock do
|
|
155
|
+
[split.claimed_amount, remaining].min.tap { |amount| split.settle_claim!(amount, captured: captured) }
|
|
156
|
+
end
|
|
157
|
+
remaining -= settled
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def take_back_captured_share(amount)
|
|
162
|
+
remaining = amount
|
|
163
|
+
payment.payment_splits.each do |split|
|
|
164
|
+
taken_back = split.with_lock do
|
|
165
|
+
[split.captured_amount, remaining].min.tap do |amount|
|
|
166
|
+
split.update!(captured_amount: split.captured_amount - amount) if amount.positive?
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
remaining -= taken_back if taken_back.positive?
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def record_reason_on_payment
|
|
174
|
+
payment.add_gateway_processing_error(reason) if reason.present?
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def reason
|
|
178
|
+
metadata['reason'] || metadata[:reason]
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# The remainder's authorization is its own network call, so it stays
|
|
182
|
+
# outside the lock. The capture is already recorded, so a remainder the
|
|
183
|
+
# gateway cannot authorize (one with no session of its own) is reported
|
|
184
|
+
# and left pending rather than failing the outcome, which a retry could
|
|
185
|
+
# not change.
|
|
186
|
+
def authorize_remainder
|
|
187
|
+
return if remainder.blank?
|
|
188
|
+
# Holding more than the order still owes would only keep the
|
|
189
|
+
# customer's money tied up.
|
|
190
|
+
return unless remainder.trim_remainder_to_amount_owed!
|
|
191
|
+
|
|
192
|
+
result = Spree.payment_process_workflow.call(payment: remainder, action: :authorize)
|
|
193
|
+
return if result.success?
|
|
194
|
+
|
|
195
|
+
Rails.error.report(Spree::Core::GatewayError.new(result.error.value.to_s),
|
|
196
|
+
handled: true, context: { payment_id: remainder.id }, source: 'spree.payments.modification_webhook')
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# A refund settled or a capture failed, so the orders' totals and
|
|
200
|
+
# statuses are derived again. Decided by the outcome, not by whether this
|
|
201
|
+
# delivery moved the record, so a redelivery or a retried job repairs a
|
|
202
|
+
# refresh that failed after the outcome committed; deriving is idempotent.
|
|
203
|
+
def rederive_order_figures
|
|
204
|
+
return unless record.is_a?(Spree::Refund) || action.to_sym == :capture_failed
|
|
205
|
+
|
|
206
|
+
orders = record.is_a?(Spree::Refund) ? [record.order] : payment_orders
|
|
207
|
+
orders.compact.each do |order|
|
|
208
|
+
order.recalculate_totals!
|
|
209
|
+
order.update_statuses!
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def payment_orders
|
|
214
|
+
payment.grouped? ? Spree::Order.where(id: payment.payment_splits.select(:order_id)).to_a : [payment.order]
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
@@ -60,7 +60,7 @@ module Spree
|
|
|
60
60
|
# earlier delivery) while the order is not, and a redelivery or job
|
|
61
61
|
# retry must still place the order or the buyer stays charged
|
|
62
62
|
# without one.
|
|
63
|
-
step :ensure_payment unless
|
|
63
|
+
step :ensure_payment unless payment_settled?
|
|
64
64
|
step :complete_session
|
|
65
65
|
step :complete_owner unless order.reload.completed?
|
|
66
66
|
end
|
|
@@ -75,6 +75,12 @@ module Spree
|
|
|
75
75
|
failure(payment_session, error.message)
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
+
# A requested payment waits on its provider's answer to a capture or
|
|
79
|
+
# void, so a redelivered authorization leaves it alone.
|
|
80
|
+
def payment_settled?
|
|
81
|
+
payment_session.reload.payment&.status.in?(Spree::Payment::SETTLED_OR_WAITING_STATUSES)
|
|
82
|
+
end
|
|
83
|
+
|
|
78
84
|
# :captured means the gateway reports the funds as moved, so the payment
|
|
79
85
|
# completes with a capture event; :authorized pends it (auth-only,
|
|
80
86
|
# payment_state=balance_due) until an explicit capture. The webhook's
|
|
@@ -44,14 +44,57 @@ module Spree
|
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
#
|
|
48
|
-
#
|
|
47
|
+
# Several live payments can sit on one order, so one is charged only
|
|
48
|
+
# what the others leave owing. Under the order's row lock, the payment's
|
|
49
|
+
# current status, what is owed, the resize to it and the claim are read
|
|
50
|
+
# and written together: of two payments processed at once on one order,
|
|
51
|
+
# the second reads after the first has claimed (processing), so it is
|
|
52
|
+
# limited to what the first leaves owing rather than both taking the
|
|
53
|
+
# full balance.
|
|
49
54
|
def claim
|
|
50
|
-
|
|
55
|
+
outcome = with_order_lock { claim_within_amount_owed }
|
|
56
|
+
failure(payment, I18n.t('spree.order_payment_already_covered')) if outcome == :covered
|
|
57
|
+
halt!(payment) if outcome == :settled
|
|
51
58
|
rescue Spree::Core::GatewayError => error
|
|
52
59
|
failure(payment, error.message)
|
|
53
60
|
end
|
|
54
61
|
|
|
62
|
+
# The row decides, since the instance may be stale: its amount is the one
|
|
63
|
+
# charged, and its status says whose the payment is. A payment another
|
|
64
|
+
# run claimed (processing) or one that settled is that run's — a success
|
|
65
|
+
# here, not an error. A dead one (void, invalid) is left to
|
|
66
|
+
# started_processing!, which raises for it, so it still fails.
|
|
67
|
+
def claim_within_amount_owed
|
|
68
|
+
status = refresh_from_row
|
|
69
|
+
return :settled if %w[processing completed].include?(status)
|
|
70
|
+
|
|
71
|
+
if Spree::Payment::RESIZABLE_STATUSES.include?(status)
|
|
72
|
+
owed = payment.amount_owed_by_order(including_in_flight: true)
|
|
73
|
+
if owed && payment.amount > owed
|
|
74
|
+
return :covered unless owed.positive?
|
|
75
|
+
return claim_within_amount_owed unless payment.resize_if_unclaimed!(owed)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
payment.started_processing! ? :claimed : :settled
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Reads the status and amount another run may have written since this
|
|
83
|
+
# instance was loaded. Deliberately not a reload, which would discard the
|
|
84
|
+
# in-memory source (card numbers never persist).
|
|
85
|
+
def refresh_from_row
|
|
86
|
+
return payment.status unless payment.persisted?
|
|
87
|
+
|
|
88
|
+
status, amount = Spree::Payment.unscoped.where(id: payment.id).pick(:status, :amount)
|
|
89
|
+
payment.amount = amount
|
|
90
|
+
payment.clear_attribute_changes(%i[amount])
|
|
91
|
+
status
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def with_order_lock(&)
|
|
95
|
+
payment.order_id ? payment.owner.with_lock(&) : yield
|
|
96
|
+
end
|
|
97
|
+
|
|
55
98
|
def process_at_gateway
|
|
56
99
|
verb = action || (payment.payment_method&.capture_at_checkout? ? :purchase : :authorize)
|
|
57
100
|
|
|
@@ -66,7 +109,7 @@ module Spree
|
|
|
66
109
|
payment.handle_response(response, verb == :purchase ? :complete : :pend)
|
|
67
110
|
# Only reached when handle_response accepted the response — a
|
|
68
111
|
# purchase moved the funds, so the capture is recorded.
|
|
69
|
-
payment.capture_events.create!(amount: payment.amount) if verb == :purchase
|
|
112
|
+
payment.capture_events.create!(amount: payment.amount, status: 'completed') if verb == :purchase
|
|
70
113
|
rescue Spree::Core::GatewayError => error
|
|
71
114
|
failure(payment, error.message)
|
|
72
115
|
end
|
|
@@ -32,6 +32,7 @@ module Spree
|
|
|
32
32
|
# surface as errors.
|
|
33
33
|
def ensure_voidable
|
|
34
34
|
halt!(payment) if payment.void?
|
|
35
|
+
failure(payment, I18n.t('spree.payment_requested_awaiting_provider')) if payment.requested?
|
|
35
36
|
failure(payment, :payment_not_voidable) unless payment.can_void?
|
|
36
37
|
end
|
|
37
38
|
|
|
@@ -54,7 +55,9 @@ module Spree
|
|
|
54
55
|
end
|
|
55
56
|
end
|
|
56
57
|
|
|
57
|
-
if response.success?
|
|
58
|
+
if response.success? && response.requested?
|
|
59
|
+
payment.request_void!
|
|
60
|
+
elsif response.success?
|
|
58
61
|
# Payment#void! is the compare-and-swap — of two racing voids only
|
|
59
62
|
# one moves the row and publishes. There is no pre-gateway claim
|
|
60
63
|
# here, unlike capture: the gateway is the authority on whether
|
|
@@ -22,6 +22,7 @@ module Spree
|
|
|
22
22
|
|
|
23
23
|
ApplicationRecord.transaction do
|
|
24
24
|
step :mark_active
|
|
25
|
+
step :list_on_default_channel
|
|
25
26
|
step :close_submission
|
|
26
27
|
run_hooks :after_approve
|
|
27
28
|
end
|
|
@@ -36,6 +37,22 @@ module Spree
|
|
|
36
37
|
failure(product) unless product.update(status: 'active')
|
|
37
38
|
end
|
|
38
39
|
|
|
40
|
+
# A seller's product is created on no sales channel, so approving it
|
|
41
|
+
# alone would leave it active but on sale nowhere. On its first approval
|
|
42
|
+
# it goes on the store's default channel, as the dashboard's new product
|
|
43
|
+
# form does, unless it is already listed somewhere. A product approved
|
|
44
|
+
# before keeps the channels the operator left it on, even none.
|
|
45
|
+
def list_on_default_channel
|
|
46
|
+
return if product.product_publications.exists?
|
|
47
|
+
return if product.submissions.with_status(:approved).exists?
|
|
48
|
+
|
|
49
|
+
channel = product.store&.default_channel
|
|
50
|
+
return unless channel&.active?
|
|
51
|
+
|
|
52
|
+
channel.add_products(product.id)
|
|
53
|
+
product.product_publications.reset
|
|
54
|
+
end
|
|
55
|
+
|
|
39
56
|
# An auto-approval says so on the row: a blank reviewer must read as
|
|
40
57
|
# "this store does not review listings", never as a lost name.
|
|
41
58
|
def close_submission
|
|
@@ -44,7 +44,13 @@ module Spree
|
|
|
44
44
|
external_step :credit_at_gateway
|
|
45
45
|
|
|
46
46
|
run_hooks :after_refund
|
|
47
|
-
|
|
47
|
+
# A requested refund is confirmed by the provider's webhook, which
|
|
48
|
+
# publishes payment.refunded then.
|
|
49
|
+
if refund.requested?
|
|
50
|
+
refund.publish_event('refund.requested')
|
|
51
|
+
else
|
|
52
|
+
payment.publish_event('payment.refunded', nil, refund_id: refund.prefixed_id)
|
|
53
|
+
end
|
|
48
54
|
success(refund)
|
|
49
55
|
end
|
|
50
56
|
|
|
@@ -93,7 +99,10 @@ module Spree
|
|
|
93
99
|
payment.with_lock do
|
|
94
100
|
ensure_share_still_available
|
|
95
101
|
|
|
102
|
+
# Requested until the gateway answers, so a crash before then leaves
|
|
103
|
+
# a visible requested row, not one that reads as completed.
|
|
96
104
|
@refund = payment.refunds.create!(
|
|
105
|
+
status: 'requested',
|
|
97
106
|
amount: @amount_to_refund,
|
|
98
107
|
order: order || payment.order,
|
|
99
108
|
reason: reason || Spree::RefundReason.return_processing_reason(refund_store),
|
|
@@ -160,7 +160,9 @@ module Spree
|
|
|
160
160
|
# One query for the whole run rather than one per share — this runs
|
|
161
161
|
# ahead of a gateway round trip per payment, and there is no reason to
|
|
162
162
|
# add N more of its own.
|
|
163
|
-
|
|
163
|
+
# Every refund that has not failed, so one still requested keeps its
|
|
164
|
+
# amount reserved.
|
|
165
|
+
refunded = Spree::Refund.not_failed.where(order_id: order.id).group(:payment_id).sum(:amount)
|
|
164
166
|
|
|
165
167
|
order.payment_splits.includes(:payment).order(:created_at).each_with_object({}) do |split, found|
|
|
166
168
|
next unless split.payment&.completed?
|
data/config/locales/be.yml
CHANGED
|
@@ -555,7 +555,7 @@ be:
|
|
|
555
555
|
no_matching_channel: Гэты прамакод не дзейнічае для дадзенага канала продажаў.
|
|
556
556
|
no_matching_market: Гэты прамакод не дзейнічае на вашым рынку.
|
|
557
557
|
no_matching_taxons: Дадайце тавар з акцыйнай катэгорыі, каб прымяніць гэты код купона.
|
|
558
|
-
no_user_or_email_specified:
|
|
558
|
+
no_user_or_email_specified: Увайдзіце або увядзіце e-mail, каб прымяніць гэты код купона.
|
|
559
559
|
no_user_specified: Каб прымяніць гэты купон.
|
|
560
560
|
not_first_order: Гэты код купона можна ўжыць толькі да вашай першай замовы.
|
|
561
561
|
wrong_country: Гэты купонны код не дзейнічае ў вашай краіне
|
|
@@ -812,7 +812,7 @@ be:
|
|
|
812
812
|
unable_to_credit: 'Немагчыма залічыць код: %{auth_code}'
|
|
813
813
|
unable_to_find: Не ўдалося знайсці крэдыт крамы
|
|
814
814
|
unable_to_find_for_action: 'Не ўдалося знайсці крэдыт крамы для кода аўтарызацыі: %{auth_code} для дзеяння: %{action}'
|
|
815
|
-
unable_to_void: 'Немагчыма
|
|
815
|
+
unable_to_void: 'Немагчыма ануліраваць код: %{auth_code}'
|
|
816
816
|
success: Поспех
|
|
817
817
|
tags: Тэгі
|
|
818
818
|
tax: Падатак
|
data/config/locales/bg.yml
CHANGED
|
@@ -377,11 +377,11 @@ bg:
|
|
|
377
377
|
one: Данъчен процент
|
|
378
378
|
other: данъчни проценти
|
|
379
379
|
spree/taxon:
|
|
380
|
-
one:
|
|
381
|
-
other:
|
|
380
|
+
one: Таксономична единица
|
|
381
|
+
other: Таксономични единици
|
|
382
382
|
spree/taxonomy:
|
|
383
|
-
one:
|
|
384
|
-
other:
|
|
383
|
+
one: Таксономия
|
|
384
|
+
other: Таксономии
|
|
385
385
|
spree/user:
|
|
386
386
|
one: Потребител
|
|
387
387
|
other: Потребители
|
data/config/locales/en.yml
CHANGED
|
@@ -327,8 +327,12 @@ en:
|
|
|
327
327
|
price_list_required: Choose a price list to export.
|
|
328
328
|
spree/gift_card:
|
|
329
329
|
attributes:
|
|
330
|
+
amount:
|
|
331
|
+
cannot_change_once_used: can't be changed once the gift card has been used
|
|
330
332
|
base:
|
|
331
333
|
cannot_destroy_used_gift_card: Can't delete a used gift card
|
|
334
|
+
currency:
|
|
335
|
+
cannot_change_once_used: can't be changed once the gift card has been used
|
|
332
336
|
spree/import:
|
|
333
337
|
attributes:
|
|
334
338
|
attachment:
|
|
@@ -689,6 +693,7 @@ en:
|
|
|
689
693
|
cannot_be_destroyed: Order cannot be destroyed.
|
|
690
694
|
capture: Capture
|
|
691
695
|
capture_amount_not_positive: The capture amount must be greater than zero.
|
|
696
|
+
capture_exceeds_amount_owed: The capture amount cannot exceed the %{amount} the order still owes.
|
|
692
697
|
capture_exceeds_payment_amount: The capture amount cannot exceed the payment amount.
|
|
693
698
|
cart: Cart
|
|
694
699
|
cart_already_updated: The cart has already been updated.
|
|
@@ -1070,6 +1075,7 @@ en:
|
|
|
1070
1075
|
order: Order
|
|
1071
1076
|
order_canceled: Order canceled
|
|
1072
1077
|
order_cannot_be_deleted: Completed orders and orders with settled payments cannot be deleted
|
|
1078
|
+
order_payment_already_covered: The order's other payments already cover what it owes, so this payment was not charged.
|
|
1073
1079
|
order_routing:
|
|
1074
1080
|
strategies:
|
|
1075
1081
|
legacy: Legacy
|
|
@@ -1097,6 +1103,7 @@ en:
|
|
|
1097
1103
|
payment_method_not_supported: That payment method is unsupported. Please choose another one.
|
|
1098
1104
|
payment_methods: Payment Methods
|
|
1099
1105
|
payment_processing_failed: Payment could not be processed, please check the details you entered
|
|
1106
|
+
payment_requested_awaiting_provider: The payment provider has not answered yet. Try again once it has.
|
|
1100
1107
|
payment_source: Payment source
|
|
1101
1108
|
pending: Pending
|
|
1102
1109
|
percent: Percent
|
|
@@ -1793,6 +1800,7 @@ en:
|
|
|
1793
1800
|
credit: Credit
|
|
1794
1801
|
eligible: Eligible
|
|
1795
1802
|
store_credit_name: Store Credit
|
|
1803
|
+
store_credit_not_applied: No Store Credit could be applied to this order.
|
|
1796
1804
|
store_credit_payment_method:
|
|
1797
1805
|
currency_mismatch: Store credit currency does not match order currency
|
|
1798
1806
|
insufficient_authorized_amount: Unable to capture more than authorized amount
|
data/config/locales/ru.yml
CHANGED
|
@@ -366,9 +366,9 @@ ru:
|
|
|
366
366
|
one: Доставка
|
|
367
367
|
other: Доставки
|
|
368
368
|
spree/shipping_method:
|
|
369
|
-
many:
|
|
370
|
-
one:
|
|
371
|
-
other:
|
|
369
|
+
many: Способов доставки
|
|
370
|
+
one: Способ доставки
|
|
371
|
+
other: Способы доставки
|
|
372
372
|
spree/state:
|
|
373
373
|
many: Областей/Регионов
|
|
374
374
|
one: Область/Регион
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Statuses are added empty: an empty status reads as completed until the
|
|
2
|
+
# backfill_settlement_statuses upgrade step fills it in.
|
|
3
|
+
class AddStatusToSpreePaymentCaptureEventsAndRefunds < ActiveRecord::Migration[8.1]
|
|
4
|
+
def change
|
|
5
|
+
change_table :spree_payment_capture_events, bulk: true do |t|
|
|
6
|
+
t.string :status
|
|
7
|
+
t.string :transaction_id
|
|
8
|
+
t.index :transaction_id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
change_table :spree_refunds, bulk: true do |t|
|
|
12
|
+
t.string :status
|
|
13
|
+
t.string :failure_reason
|
|
14
|
+
t.index :transaction_id
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/spree/agent_tool.rb
CHANGED
|
@@ -115,9 +115,10 @@ class AgentTool
|
|
|
115
115
|
# @param type [Symbol] JSON schema type
|
|
116
116
|
# @param description [String]
|
|
117
117
|
# @param required [Boolean]
|
|
118
|
-
# @param items [Symbol] what an array holds — a JSON
|
|
119
|
-
# it is ambiguous, and a client that validates
|
|
120
|
-
# schema rejects the call before the tool ever
|
|
118
|
+
# @param items [Symbol, Array<Symbol>] what an array holds — a JSON
|
|
119
|
+
# Schema array without it is ambiguous, and a client that validates
|
|
120
|
+
# arguments against the schema rejects the call before the tool ever
|
|
121
|
+
# runs. Several types mean each element may be any one of them.
|
|
121
122
|
# @return [void]
|
|
122
123
|
def param(name, type: :string, description: nil, required: false, items: nil)
|
|
123
124
|
# Reassigned rather than mutated, so declaring a param on a subclass
|
|
@@ -143,7 +144,7 @@ class AgentTool
|
|
|
143
144
|
property['description'] = options[:description] if options[:description].present?
|
|
144
145
|
# An array must say what it holds: a client validating arguments
|
|
145
146
|
# against the schema refuses the call otherwise.
|
|
146
|
-
property['items'] =
|
|
147
|
+
property['items'] = items_schema(options[:items]) if property['type'] == 'array'
|
|
147
148
|
|
|
148
149
|
[name.to_s, property]
|
|
149
150
|
end
|
|
@@ -157,6 +158,12 @@ class AgentTool
|
|
|
157
158
|
|
|
158
159
|
private
|
|
159
160
|
|
|
161
|
+
def items_schema(items)
|
|
162
|
+
types = (Array(items).presence || [:string]).map { |type| { 'type' => json_type(type) } }
|
|
163
|
+
|
|
164
|
+
types.one? ? types.first : { 'anyOf' => types }
|
|
165
|
+
end
|
|
166
|
+
|
|
160
167
|
# A tool declares Ruby-ish types; JSON Schema wants its own names, and
|
|
161
168
|
# anything unrecognised is a string, which every client can render.
|
|
162
169
|
def json_type(type)
|
|
@@ -262,6 +262,7 @@ module Spree
|
|
|
262
262
|
seller_payout_sweep_workflow: 'Spree::SellerPayouts::Sweep',
|
|
263
263
|
seller_payout_complete_workflow: 'Spree::SellerPayouts::Complete',
|
|
264
264
|
payments_handle_webhook_workflow: 'Spree::Payments::HandleWebhook',
|
|
265
|
+
payments_handle_modification_webhook_workflow: 'Spree::Payments::HandleModificationWebhook',
|
|
265
266
|
payment_session_complete_workflow: 'Spree::PaymentSessions::Complete',
|
|
266
267
|
email_template_save_draft_workflow: 'Spree::EmailTemplates::SaveDraft',
|
|
267
268
|
email_template_publish_workflow: 'Spree::EmailTemplates::Publish',
|
data/lib/spree/core/version.rb
CHANGED