spree_core 6.0.4 → 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.
Files changed (233) hide show
  1. checksums.yaml +4 -4
  2. data/app/jobs/spree/imports/create_rows_job.rb +4 -2
  3. data/app/jobs/spree/imports/process_rows_job.rb +4 -2
  4. data/app/jobs/spree/payments/handle_modification_webhook_job.rb +93 -0
  5. data/app/jobs/spree/payments/handle_webhook_job.rb +4 -2
  6. data/app/jobs/spree/products/auto_match_taxons_job.rb +5 -2
  7. data/app/jobs/spree/search_provider/index_job.rb +8 -0
  8. data/app/jobs/spree/search_provider/remove_job.rb +3 -0
  9. data/app/jobs/spree/stock_locations/stock_items/create_job.rb +5 -2
  10. data/app/mailers/spree/base_mailer.rb +1 -1
  11. data/app/maintenance_tasks/spree/maintenance_tasks/upgrade/backfill_settlement_statuses.rb +40 -0
  12. data/app/models/concerns/spree/acted_by.rb +2 -2
  13. data/app/models/concerns/spree/customer_methods.rb +7 -5
  14. data/app/models/concerns/spree/deprecated_customer_alias.rb +11 -3
  15. data/app/models/concerns/spree/derived_number.rb +1 -1
  16. data/app/models/concerns/spree/has_custom_fields.rb +12 -10
  17. data/app/models/concerns/spree/integrations_concern.rb +5 -3
  18. data/app/models/concerns/spree/label_translatable.rb +4 -4
  19. data/app/models/concerns/spree/metadata.rb +3 -3
  20. data/app/models/concerns/spree/presentation_translatable.rb +1 -1
  21. data/app/models/concerns/spree/product_scopes.rb +5 -2
  22. data/app/models/concerns/spree/purchase/addresses.rb +8 -5
  23. data/app/models/concerns/spree/purchase/deprecated_aliases.rb +2 -2
  24. data/app/models/concerns/spree/purchase/payment_processing.rb +11 -0
  25. data/app/models/concerns/spree/purchase/purchase_order.rb +21 -0
  26. data/app/models/concerns/spree/purchase/totals.rb +3 -2
  27. data/app/models/concerns/spree/ransackable_attributes.rb +81 -4
  28. data/app/models/concerns/spree/settlement_status.rb +29 -0
  29. data/app/models/concerns/spree/stores/markets.rb +4 -32
  30. data/app/models/concerns/spree/user_address.rb +5 -2
  31. data/app/models/concerns/spree/user_methods.rb +2 -2
  32. data/app/models/spree/address.rb +29 -14
  33. data/app/models/spree/asset.rb +3 -3
  34. data/app/models/spree/base.rb +4 -4
  35. data/app/models/spree/calculator/shipping/flat_rate.rb +6 -4
  36. data/app/models/spree/cart.rb +2 -2
  37. data/app/models/spree/category.rb +61 -38
  38. data/app/models/spree/classification.rb +2 -2
  39. data/app/models/spree/collection_rule.rb +5 -1
  40. data/app/models/spree/current.rb +19 -0
  41. data/app/models/spree/custom_field.rb +6 -6
  42. data/app/models/spree/custom_field_definition.rb +10 -7
  43. data/app/models/spree/delivery_method.rb +21 -15
  44. data/app/models/spree/delivery_rate.rb +1 -1
  45. data/app/models/spree/digital.rb +1 -1
  46. data/app/models/spree/digital_asset.rb +2 -2
  47. data/app/models/spree/digital_link.rb +4 -4
  48. data/app/models/spree/export.rb +32 -3
  49. data/app/models/spree/exports/products.rb +9 -1
  50. data/app/models/spree/fulfillment/custom_events.rb +18 -10
  51. data/app/models/spree/fulfillment.rb +53 -29
  52. data/app/models/spree/fulfillment_group.rb +2 -2
  53. data/app/models/spree/fulfillment_item.rb +3 -3
  54. data/app/models/spree/fulfilment_changer.rb +1 -1
  55. data/app/models/spree/gateway/bogus.rb +41 -2
  56. data/app/models/spree/gift_card.rb +26 -14
  57. data/app/models/spree/import.rb +23 -15
  58. data/app/models/spree/import_row.rb +6 -6
  59. data/app/models/spree/inventory_unit.rb +1 -1
  60. data/app/models/spree/invitation.rb +8 -4
  61. data/app/models/spree/line_item.rb +10 -8
  62. data/app/models/spree/media.rb +3 -3
  63. data/app/models/spree/metafield.rb +1 -1
  64. data/app/models/spree/metafield_definition.rb +1 -1
  65. data/app/models/spree/metafields.rb +2 -2
  66. data/app/models/spree/option_type.rb +27 -0
  67. data/app/models/spree/option_value.rb +3 -3
  68. data/app/models/spree/order.rb +97 -49
  69. data/app/models/spree/order_group.rb +2 -2
  70. data/app/models/spree/order_inventory.rb +2 -2
  71. data/app/models/spree/order_merger.rb +2 -2
  72. data/app/models/spree/order_updater.rb +34 -20
  73. data/app/models/spree/payment/custom_events.rb +2 -1
  74. data/app/models/spree/payment/processing.rb +20 -3
  75. data/app/models/spree/payment.rb +194 -15
  76. data/app/models/spree/payment_capture_event.rb +2 -0
  77. data/app/models/spree/payment_method/store_credit.rb +6 -0
  78. data/app/models/spree/payment_method.rb +65 -11
  79. data/app/models/spree/payment_response.rb +19 -0
  80. data/app/models/spree/payment_session.rb +15 -3
  81. data/app/models/spree/payment_split.rb +14 -2
  82. data/app/models/spree/price.rb +20 -8
  83. data/app/models/spree/price_list.rb +12 -6
  84. data/app/models/spree/price_rules/zone_rule.rb +1 -1
  85. data/app/models/spree/product.rb +30 -28
  86. data/app/models/spree/product_category.rb +3 -3
  87. data/app/models/spree/promotion/rules/category.rb +27 -10
  88. data/app/models/spree/promotion/rules/country.rb +1 -1
  89. data/app/models/spree/promotion/rules/taxon.rb +4 -2
  90. data/app/models/spree/promotion/rules/user.rb +1 -1
  91. data/app/models/spree/promotion_action.rb +1 -1
  92. data/app/models/spree/promotion_rule_category.rb +5 -5
  93. data/app/models/spree/promotion_rule_taxon.rb +2 -2
  94. data/app/models/spree/prototype.rb +4 -1
  95. data/app/models/spree/purchase_order.rb +20 -3
  96. data/app/models/spree/refund.rb +7 -1
  97. data/app/models/spree/return.rb +7 -1
  98. data/app/models/spree/return_authorization_reason.rb +3 -3
  99. data/app/models/spree/return_reason.rb +1 -1
  100. data/app/models/spree/search_provider/base.rb +12 -2
  101. data/app/models/spree/search_provider/database.rb +8 -5
  102. data/app/models/spree/search_provider.rb +7 -5
  103. data/app/models/spree/shipment.rb +4 -1
  104. data/app/models/spree/shipping_method.rb +4 -1
  105. data/app/models/spree/shipping_rate.rb +1 -1
  106. data/app/models/spree/stock/coordinator.rb +2 -2
  107. data/app/models/spree/stock/estimator.rb +7 -5
  108. data/app/models/spree/stock/package.rb +10 -8
  109. data/app/models/spree/stock_item.rb +1 -1
  110. data/app/models/spree/stock_level/custom_events.rb +1 -1
  111. data/app/models/spree/stock_level.rb +1 -1
  112. data/app/models/spree/stock_location.rb +12 -8
  113. data/app/models/spree/stock_movement.rb +6 -6
  114. data/app/models/spree/stock_reservation.rb +5 -5
  115. data/app/models/spree/store.rb +64 -16
  116. data/app/models/spree/store_credit.rb +3 -3
  117. data/app/models/spree/store_credit_category.rb +5 -5
  118. data/app/models/spree/store_credit_type.rb +2 -2
  119. data/app/models/spree/subscriber.rb +7 -7
  120. data/app/models/spree/tax_rate.rb +5 -5
  121. data/app/models/spree/taxon.rb +3 -3
  122. data/app/models/spree/taxon_rule.rb +2 -2
  123. data/app/models/spree/taxonomy.rb +1 -1
  124. data/app/models/spree/variant.rb +45 -10
  125. data/app/models/spree/variant_media.rb +1 -1
  126. data/app/models/spree/wished_item.rb +1 -1
  127. data/app/models/spree/wishlist.rb +2 -2
  128. data/app/models/spree/wishlist_item/custom_events.rb +2 -2
  129. data/app/models/spree/zone.rb +1 -1
  130. data/app/models/spree/zone_member.rb +1 -1
  131. data/app/presenters/spree/csv/product_variant_presenter.rb +17 -8
  132. data/app/serializers/spree/emails/store_serializer.rb +1 -1
  133. data/app/services/spree/carts/associate.rb +6 -2
  134. data/app/services/spree/carts/create.rb +1 -1
  135. data/app/services/spree/carts/destroy.rb +1 -1
  136. data/app/services/spree/carts/remove_item.rb +1 -1
  137. data/app/services/spree/carts/remove_line_item.rb +2 -2
  138. data/app/services/spree/carts/remove_out_of_stock_items.rb +3 -1
  139. data/app/services/spree/carts/set_quantity.rb +2 -2
  140. data/app/services/spree/carts/split_by_seller.rb +4 -13
  141. data/app/services/spree/carts/update.rb +17 -0
  142. data/app/services/spree/checkout/add_store_credit.rb +3 -3
  143. data/app/services/spree/checkout/remove_store_credit.rb +2 -2
  144. data/app/services/spree/imports/row_processors/product_variant.rb +19 -0
  145. data/app/services/spree/orders/approve.rb +3 -3
  146. data/app/services/spree/orders/create_from_cart.rb +2 -0
  147. data/app/services/spree/orders/create_user_account.rb +2 -2
  148. data/app/services/spree/orders/update_statuses.rb +4 -2
  149. data/app/services/spree/products/auto_match_taxons.rb +5 -2
  150. data/app/services/spree/shipments/update.rb +2 -2
  151. data/app/services/spree/stock_locations/stock_items/create.rb +5 -2
  152. data/app/services/spree/stock_reservations/extend.rb +3 -1
  153. data/app/services/spree/stock_reservations/reserve.rb +3 -1
  154. data/app/services/spree/store_credits/apply.rb +1 -1
  155. data/app/services/spree/taxons/add_products.rb +4 -2
  156. data/app/services/spree/taxons/regenerate_products.rb +5 -2
  157. data/app/services/spree/taxons/remove_products.rb +4 -2
  158. data/app/subscribers/spree/order_status_subscriber.rb +4 -3
  159. data/app/subscribers/spree/payment_split_subscriber.rb +39 -21
  160. data/app/subscribers/spree/seller_transfer_reversal_subscriber.rb +19 -7
  161. data/app/tools/spree/agent_tools/query_report.rb +116 -14
  162. data/app/workflows/spree/carts/add_item.rb +1 -1
  163. data/app/workflows/spree/carts/complete.rb +1 -19
  164. data/app/workflows/spree/carts/recalculate.rb +1 -1
  165. data/app/workflows/spree/carts/recalculate_totals.rb +3 -3
  166. data/app/workflows/spree/fulfillments/update.rb +1 -1
  167. data/app/workflows/spree/orders/cancel.rb +22 -1
  168. data/app/workflows/spree/orders/complete.rb +7 -1
  169. data/app/workflows/spree/payments/capture.rb +101 -7
  170. data/app/workflows/spree/payments/handle_modification_webhook.rb +218 -0
  171. data/app/workflows/spree/payments/handle_webhook.rb +7 -1
  172. data/app/workflows/spree/payments/process.rb +47 -4
  173. data/app/workflows/spree/payments/void.rb +4 -1
  174. data/app/workflows/spree/products/approve.rb +17 -0
  175. data/app/workflows/spree/refunds/create.rb +10 -1
  176. data/app/workflows/spree/refunds/order_payments.rb +3 -1
  177. data/app/workflows/spree/seller_transfers/create.rb +1 -1
  178. data/config/locales/be.yml +2 -2
  179. data/config/locales/bg.yml +4 -4
  180. data/config/locales/en.yml +12 -0
  181. data/config/locales/ru.yml +3 -3
  182. data/db/migrate/20260710000001_rename_taxons_to_categories.rb +1 -1
  183. data/db/migrate/20260728000004_rename_shipping_to_fulfillment_and_delivery.rb +1 -1
  184. data/db/migrate/20260806000001_add_store_id_to_spree_tax_rates_and_categories.rb +1 -1
  185. data/db/migrate/20260807130001_add_country_state_codes_to_consumers.rb +1 -1
  186. data/db/migrate/20260809000001_rename_metafields_to_custom_fields.rb +1 -1
  187. data/db/migrate/20260809150001_promote_shipping_categories_to_delivery_profiles.rb +1 -1
  188. data/db/migrate/20260811000001_add_delivery_tracking_to_fulfillments.rb +1 -1
  189. data/db/migrate/20260824000001_add_store_to_spree_media.rb +1 -1
  190. data/db/migrate/20260828100001_unify_import_and_export_tenancy.rb +1 -1
  191. data/db/migrate/20261016000001_remove_default_from_spree_tax_rates_included_in_price.rb +1 -1
  192. data/db/migrate/20261116100001_add_status_to_spree_payment_capture_events_and_refunds.rb +17 -0
  193. data/lib/spree/agent_tool.rb +11 -4
  194. data/lib/spree/agent_tools/default_catalog.rb +2 -2
  195. data/lib/spree/agent_tools/legacy_tools.rb +1 -1
  196. data/lib/spree/core/dependencies.rb +11 -10
  197. data/lib/spree/core/engine.rb +4 -0
  198. data/lib/spree/core/number_generator.rb +4 -3
  199. data/lib/spree/core/preferences/preferable.rb +1 -1
  200. data/lib/spree/core/preferences/preferable_class_methods.rb +5 -1
  201. data/lib/spree/core/pricing/resolver.rb +2 -2
  202. data/lib/spree/core/version.rb +1 -1
  203. data/lib/spree/core.rb +37 -10
  204. data/lib/spree/i18n.rb +6 -2
  205. data/lib/spree/localized_number.rb +1 -1
  206. data/lib/spree/removed_apis.rb +274 -0
  207. data/lib/spree/reporting/adapters/live.rb +69 -8
  208. data/lib/spree/reporting/default_vocabulary.rb +11 -5
  209. data/lib/spree/reporting/query.rb +4 -1
  210. data/lib/spree/reporting/registry.rb +50 -3
  211. data/lib/spree/testing_support/factories/digital_asset_factory.rb +1 -1
  212. data/lib/spree/testing_support/factories/payment_capture_event_factory.rb +10 -0
  213. data/lib/spree/testing_support/factories/refund_factory.rb +10 -0
  214. data/lib/spree/testing_support/factories/stock_level_factory.rb +1 -1
  215. data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
  216. data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
  217. data/lib/spree/testing_support/factories/wishlist_item_factory.rb +1 -1
  218. data/lib/spree/testing_support/i18n.rb +7 -2
  219. data/lib/spree/testing_support/order_walkthrough.rb +5 -2
  220. data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +71 -14
  221. data/lib/tasks/carts_migration.rake +1 -1
  222. data/lib/tasks/categories_and_collections.rake +1 -1
  223. data/lib/tasks/deliveries_migration.rake +1 -1
  224. data/lib/tasks/delivery_method_rules_migration.rake +1 -1
  225. data/lib/tasks/delivery_migration.rake +1 -1
  226. data/lib/tasks/delivery_profiles_migration.rake +2 -2
  227. data/lib/tasks/fold_store_credit_categories.rake +1 -1
  228. data/lib/tasks/migrate_country_state_codes.rake +1 -1
  229. data/lib/tasks/migrate_returns.rake +4 -4
  230. data/lib/tasks/migrate_rich_text_to_columns.rake +1 -1
  231. data/lib/tasks/store_settings.rake +1 -1
  232. data/lib/tasks/typed_stock_movements_migration.rake +1 -1
  233. metadata +26 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e465daf49ecae5d15b57e998d9ea505ee2eba53224668e370c290536aad30736
4
- data.tar.gz: 1a7596942af23ef5da1830f75c76acf3f6bad00e92e1b95b1f400424ddfa7603
3
+ metadata.gz: a5194af3427b9ca7bc42294f49a00db40225b42ef85b129625545f91da07ce74
4
+ data.tar.gz: a4f7d851aefe2c406973b9e3f034f9523e99c1e2d83f90e2965d35d28ac02799
5
5
  SHA512:
6
- metadata.gz: 3fab6326b8031e792e88fe83aedc58879cef258f145fc828ae04c39425e1c0e1359a4e2ee26d4d64f7abea3b72cd7e79ceb2ba4c6e4dc045e5a266bd0c351255
7
- data.tar.gz: 8dd0f193ddc437e1ab18983e34713743928ec239e4baa025f93aed3bc4b3e6bc85ac0e36630859a561fd1f901fef77cec49685e254c303d1502e2f53ca694e39
6
+ metadata.gz: 9a79ca48edd3e8b2caf20ec031be2fbb7f208cf256422a81177a774d2b7e8032d1fcfc193a169b5626e517d536289f456f16827db3e41cba5b4d179a311cb541
7
+ data.tar.gz: 0e92e81e2f39f437bee1efac62983ccbade8883a2b3f8c1f0ae4b6167f1edaa0d9ddbbf0c31e55be9659232e13c30b331cea22304ca0b59c5fb7a690dc8ab12b
@@ -1,9 +1,11 @@
1
1
  module Spree
2
2
  module Imports
3
- # @deprecated Use {Spree::Imports::ProcessJob}; removed in 6.1.
3
+ # @deprecated Use {Spree::Imports::ProcessJob}; removed in 6.3.
4
4
  class CreateRowsJob < Spree::Imports::BaseJob
5
5
  def perform(import_id)
6
- Spree::Deprecation.warn('Spree::Imports::CreateRowsJob is deprecated and will be removed in Spree 6.1. Use Spree::Imports::ProcessJob instead.')
6
+ Spree::Deprecation.warn(
7
+ 'Spree::Imports::CreateRowsJob is deprecated and will be removed in Spree 6.3. Use Spree::Imports::ProcessJob instead.'
8
+ )
7
9
  Spree::Imports::ProcessJob.perform_now(import_id)
8
10
  end
9
11
  end
@@ -1,10 +1,12 @@
1
1
  module Spree
2
2
  module Imports
3
3
  # @deprecated Use {Spree::Imports::ProcessJob} with skip_row_creation:
4
- # true; removed in 6.1.
4
+ # true; removed in 6.3.
5
5
  class ProcessRowsJob < Spree::Imports::BaseJob
6
6
  def perform(import_id)
7
- Spree::Deprecation.warn('Spree::Imports::ProcessRowsJob is deprecated and will be removed in Spree 6.1. Use Spree::Imports::ProcessJob instead.')
7
+ Spree::Deprecation.warn(
8
+ 'Spree::Imports::ProcessRowsJob is deprecated and will be removed in Spree 6.3. Use Spree::Imports::ProcessJob instead.'
9
+ )
8
10
  Spree::Imports::ProcessJob.perform_now(import_id, skip_row_creation: true)
9
11
  end
10
12
  end
@@ -0,0 +1,93 @@
1
+ module Spree
2
+ module Payments
3
+ # Runs Spree::Payments::HandleModificationWebhook for an outcome the
4
+ # webhook endpoint accepted: the provider got its 200 already and will not
5
+ # send it again, so a failure is retried here.
6
+ #
7
+ # An outcome can name a record Spree has not written yet: it arrived
8
+ # before the request that writes it finished, or that request's answer
9
+ # never reached Spree and a retry of it writes the record later. The job
10
+ # waits for the record as long as a retried request still gets the
11
+ # provider's first answer.
12
+ class HandleModificationWebhookJob < Spree::BaseJob
13
+ queue_as Spree.queues.payment_webhooks
14
+
15
+ retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3
16
+ retry_on ActiveRecord::LockWaitTimeout, wait: 5.seconds, attempts: 3
17
+ discard_on ActiveRecord::RecordNotFound
18
+
19
+ class OutcomeFailed < StandardError; end
20
+ # The wait ended with no record: an action taken outside Spree, or a
21
+ # request whose answer never reached Spree and that nobody retried.
22
+ class RecordNeverWritten < StandardError; end
23
+
24
+ retry_on OutcomeFailed, wait: :polynomially_longer, attempts: 5
25
+
26
+ CAPTURE_ACTIONS = %w[capture_succeeded capture_failed].freeze
27
+ # How long a retried request still gets the provider's first answer:
28
+ # Adyen keeps an idempotency key for at least 7 days.
29
+ RECORD_WAIT = 7.days
30
+ # Longer than any gateway call takes with its own retries, so after it
31
+ # no request for this outcome can still be running.
32
+ ANSWER_WINDOW = 5.minutes
33
+
34
+ # @param reference [String] the provider reference the outcome names its record by
35
+ # @param received_at [String] when the endpoint accepted the outcome, ISO 8601
36
+ # @param payment_id [Integer, nil] the payment a capture outcome's capture was asked for
37
+ def perform(payment_method_id:, action:, reference:, received_at:, payment_id: nil, metadata: {})
38
+ payment_method = Spree::PaymentMethod.find(payment_method_id)
39
+ Spree::Current.store = payment_method.store
40
+ received_at = Time.zone.parse(received_at)
41
+
42
+ record = payment_method.modification_record(action.to_sym, reference) ||
43
+ unanswered_capture(payment_method, action, reference, payment_id, metadata, received_at)
44
+ return wait_for_record(payment_method, action, reference, received_at) if record.nil?
45
+
46
+ result = Spree.payments_handle_modification_webhook_workflow.call(
47
+ payment_method: payment_method,
48
+ action: action.to_sym,
49
+ record: record,
50
+ metadata: metadata
51
+ )
52
+
53
+ raise OutcomeFailed, "#{action} #{reference}: #{result.error}" if result&.failure?
54
+ end
55
+
56
+ private
57
+
58
+ # A capture whose answer never reached Spree leaves its payment
59
+ # processing, with no capture event waiting. Once no request can still be
60
+ # running, the event is written as the request would have, so the
61
+ # outcome settles it.
62
+ def unanswered_capture(payment_method, action, reference, payment_id, metadata, received_at)
63
+ return unless CAPTURE_ACTIONS.include?(action.to_s) && payment_id
64
+ return if Time.current - received_at < ANSWER_WINDOW
65
+
66
+ payment = Spree::Payment.where(payment_method_id: payment_method.id).find_by(id: payment_id)
67
+ return if payment.nil?
68
+
69
+ payment.with_lock do
70
+ next unless payment.processing? && payment.capture_events.where(status: 'requested').none?
71
+
72
+ amount = metadata['amount'].presence&.to_d || payment.amount
73
+ payment.capture_events.create!(amount: amount, status: 'requested', transaction_id: reference)
74
+ end
75
+ end
76
+
77
+ # Looks again quickly at first, when the record is most likely only
78
+ # moments away, then every few hours.
79
+ def wait_for_record(payment_method, action, reference, received_at)
80
+ if Time.current - received_at < RECORD_WAIT
81
+ retry_job(wait: [5.seconds * (4**(executions - 1).clamp(0, 8)), 6.hours].min)
82
+ else
83
+ Rails.error.report(
84
+ RecordNeverWritten.new("#{action} names no record: #{reference}"),
85
+ handled: true,
86
+ context: { payment_method_id: payment_method.id, action: action, reference: reference },
87
+ source: 'spree.payments.modification_webhook'
88
+ )
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -16,7 +16,8 @@ module Spree
16
16
 
17
17
  retry_on SettlementFailed, wait: :polynomially_longer, attempts: 5
18
18
 
19
- def perform(payment_method_id:, action:, payment_session_id:)
19
+ # metadata defaults to {} so jobs enqueued before it was passed still run.
20
+ def perform(payment_method_id:, action:, payment_session_id:, metadata: {})
20
21
  payment_method = Spree::PaymentMethod.find(payment_method_id)
21
22
  Spree::Current.store = payment_method.store
22
23
  payment_session = Spree::PaymentSession.find(payment_session_id)
@@ -24,7 +25,8 @@ module Spree
24
25
  result = Spree.payments_handle_webhook_workflow.call(
25
26
  payment_method: payment_method,
26
27
  action: action.to_sym,
27
- payment_session: payment_session
28
+ payment_session: payment_session,
29
+ metadata: metadata
28
30
  )
29
31
 
30
32
  raise SettlementFailed, "Payment session #{payment_session.id}: #{result.error}" if result&.failure?
@@ -2,10 +2,13 @@ module Spree
2
2
  module Products
3
3
  # @deprecated Renamed to AutoMatchCollectionsJob in 6.0 (behavior moved to
4
4
  # collections). Subclasses it so jobs enqueued under the old class name still
5
- # deserialize and run; removed in 6.1.
5
+ # deserialize and run; removed in 6.3.
6
6
  class AutoMatchTaxonsJob < AutoMatchCollectionsJob
7
7
  def perform(product_id)
8
- Spree::Deprecation.warn('Spree::Products::AutoMatchTaxonsJob is deprecated and will be removed in Spree 6.1. Use Spree::Products::AutoMatchCollectionsJob instead.')
8
+ Spree::Deprecation.warn(
9
+ 'Spree::Products::AutoMatchTaxonsJob is deprecated and will be removed in Spree 6.3. ' \
10
+ 'Use Spree::Products::AutoMatchCollectionsJob instead.'
11
+ )
9
12
  super
10
13
  end
11
14
  end
@@ -3,6 +3,14 @@ module Spree
3
3
  class IndexJob < Spree::BaseJob
4
4
  queue_as Spree.queues.search
5
5
 
6
+ # A bulk write (CSV import, sample data) enqueues thousands of these at
7
+ # once; run in parallel they flood the search service with requests and
8
+ # it answers 429 Too Many Requests. Run one search job per store at a
9
+ # time; the rest wait as blocked executions, so no update is lost. Shared
10
+ # with RemoveJob. The duration only has to outlive one job; expiry lifts
11
+ # the cap, it doesn't drop jobs. Solid Queue only (no-op elsewhere).
12
+ limits_concurrency to: 1, key: ->(*, store_id) { store_id }, group: 'spree_search', duration: 5.minutes if respond_to?(:limits_concurrency)
13
+
6
14
  # Search providers are external services (Meilisearch, etc.); a transient 5xx or
7
15
  # network blip should not drop the index update.
8
16
  retry_on StandardError, wait: :polynomially_longer, attempts: 5
@@ -3,6 +3,9 @@ module Spree
3
3
  class RemoveJob < Spree::BaseJob
4
4
  queue_as Spree.queues.search
5
5
 
6
+ # Shares IndexJob's per-store limit, see there.
7
+ limits_concurrency to: 1, key: ->(*, store_id) { store_id }, group: 'spree_search', duration: 5.minutes if respond_to?(:limits_concurrency)
8
+
6
9
  # Search providers are external services; broad retry covers network blips and 5xx.
7
10
  retry_on StandardError, wait: :polynomially_longer, attempts: 5
8
11
  # Must come after `retry_on StandardError` so DeserializationError lands in discard
@@ -3,10 +3,13 @@ module Spree
3
3
  module StockItems
4
4
  # @deprecated Renamed to Spree::StockLocations::StockLevels::CreateJob in 6.0.
5
5
  # Subclasses it so jobs enqueued under the old class name before the deploy
6
- # still deserialize and run; removed in 6.1.
6
+ # still deserialize and run; removed in 6.3.
7
7
  class CreateJob < StockLevels::CreateJob
8
8
  def perform(*args)
9
- Spree::Deprecation.warn('Spree::StockLocations::StockItems::CreateJob is deprecated and will be removed in Spree 6.1. Use Spree::StockLocations::StockLevels::CreateJob instead.')
9
+ Spree::Deprecation.warn(
10
+ 'Spree::StockLocations::StockItems::CreateJob is deprecated and will be removed in Spree 6.3. ' \
11
+ 'Use Spree::StockLocations::StockLevels::CreateJob instead.'
12
+ )
10
13
  super
11
14
  end
12
15
  end
@@ -29,7 +29,7 @@ module Spree
29
29
  @_store_locale_active = true
30
30
  begin
31
31
  Spree::Locales::SetFallbackLocaleForStore.new.call(store: store) if store
32
- I18n.with_locale(locale, &block)
32
+ Spree::Current.with_content_locale(store&.default_market&.default_locale) { I18n.with_locale(locale, &block) }
33
33
  ensure
34
34
  @_store_locale_active = previously_active
35
35
  Mobility.store_based_fallbacks = previous_fallbacks
@@ -0,0 +1,40 @@
1
+ module Spree
2
+ module MaintenanceTasks
3
+ module Upgrade
4
+ # Capture events and refunds gained a status in a 6.0 patch release (a
5
+ # gateway may now answer that it is still waiting on its provider), added
6
+ # empty by the migration. Every row written before then is money that
7
+ # moved, so it is marked completed here. Walks payments, the one record
8
+ # both tables hang from, so the run has a single cursor.
9
+ class BackfillSettlementStatuses < Spree::MaintenanceTask
10
+ supports_dry_run
11
+ collection_batch_size 1_000
12
+
13
+ def collection
14
+ capture_event_payment_ids = Spree::PaymentCaptureEvent.where(status: nil).select(:payment_id)
15
+ refund_payment_ids = Spree::Refund.where(status: nil).select(:payment_id)
16
+
17
+ Spree::Payment.unscoped.
18
+ where(id: capture_event_payment_ids).
19
+ or(Spree::Payment.unscoped.where(id: refund_payment_ids)).
20
+ order(:id)
21
+ end
22
+
23
+ def process(payment)
24
+ capture_events = Spree::PaymentCaptureEvent.where(payment_id: payment.id, status: nil)
25
+ refunds = Spree::Refund.where(payment_id: payment.id, status: nil)
26
+
27
+ if dry_run?
28
+ tally(:capture_events_would_complete, capture_events.count)
29
+ tally(:refunds_would_complete, refunds.count)
30
+ return
31
+ end
32
+
33
+ now = Time.current
34
+ tally(:capture_events_completed, capture_events.update_all(status: 'completed', updated_at: now))
35
+ tally(:refunds_completed, refunds.update_all(status: 'completed', updated_at: now))
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -178,7 +178,7 @@ module Spree
178
178
  # Prepended rather than defined outright, so `super` reaches the
179
179
  # generated reader.
180
180
  #
181
- # Removed in 6.1, once the backfill is a release behind.
181
+ # Removed in 6.3, once the backfill is a release behind.
182
182
  def define_transitional_actor_reader(name)
183
183
  transitional_actor_readers.module_eval do
184
184
  define_method(name) do
@@ -188,7 +188,7 @@ module Spree
188
188
  Spree::Deprecation.warn(
189
189
  "#{self.class.name}##{name} resolved through #{Spree.admin_user_class} because " \
190
190
  "#{name}_type is blank. Run `rake spree:upgrade:backfill_actor_types`; the fallback " \
191
- 'is removed in Spree 6.1.'
191
+ 'is removed in Spree 6.3.'
192
192
  )
193
193
 
194
194
  # Fill the type across the whole lazily-preloaded group, not just
@@ -198,7 +198,7 @@ module Spree
198
198
  # Two-state scope: see Spree::Base.ransack_flag? for why the cast is
199
199
  # opted out of here and done inside the scope instead.
200
200
  def self.ransackable_scopes_skip_sanitize_args
201
- %i[anonymized]
201
+ super | %w[anonymized]
202
202
  end
203
203
 
204
204
  # Whether an erasure has been carried out. A scope rather than a
@@ -295,14 +295,14 @@ module Spree
295
295
  # @deprecated Carts are {Spree::Cart} since 6.0, so an incomplete order is
296
296
  # a backoffice draft rather than the customer's cart. Use
297
297
  # +carts.where(store: store)+ for carts, or +orders.drafts+ for drafts.
298
- # Removed in Spree 6.1.
298
+ # Removed in Spree 6.3.
299
299
  # @param [Spree::Store] store
300
300
  # @param [Hash] options
301
301
  # @option options [Array<Symbol>] :includes
302
302
  # @return [Spree::Order]
303
303
  def last_incomplete_spree_order(store, options = {})
304
304
  Spree::Deprecation.warn(
305
- 'Spree::CustomerMethods#last_incomplete_spree_order is deprecated and will be removed in Spree 6.1. ' \
305
+ 'Spree::CustomerMethods#last_incomplete_spree_order is deprecated and will be removed in Spree 6.3. ' \
306
306
  'Carts are Spree::Cart since 6.0 and this returns draft orders; use #carts for the customer\'s carts.'
307
307
  )
308
308
 
@@ -393,9 +393,11 @@ module Spree
393
393
  # every column carrying personal data rather than three on this row —
394
394
  # the address book, the address snapshots on past orders, gateway
395
395
  # profiles, OAuth identities and live sessions all outlived this method.
396
- # Removed in Spree 6.1.
396
+ # Removed in Spree 6.3.
397
397
  def scramble_email_and_names
398
- Spree::Deprecation.warn('Spree::CustomerMethods#scramble_email_and_names is deprecated and will be removed in Spree 6.1. Use Spree::Customers::Anonymize instead.')
398
+ Spree::Deprecation.warn(
399
+ 'Spree::CustomerMethods#scramble_email_and_names is deprecated and will be removed in Spree 6.3. Use Spree::Customers::Anonymize instead.'
400
+ )
399
401
 
400
402
  Spree.customer_anonymize_workflow.call(customer: self, store: Spree::Current.store).success?
401
403
  end
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  # Deprecation shim for the 6.0 user_id -> customer_id / belongs_to :user -> :customer
3
3
  # rename. Included by customer-facing models so `.user` / `.user_id` keep working
4
- # for one release. Remove in Spree 6.1.
4
+ # until Spree 6.3.
5
5
  module DeprecatedCustomerAlias
6
6
  extend ActiveSupport::Concern
7
7
 
@@ -10,12 +10,20 @@ module Spree
10
10
  end
11
11
 
12
12
  def user
13
- Spree::Deprecation.warn("#{self.class}#user is deprecated and will be removed in Spree 6.1. Use #customer instead.") if defined?(Spree::Deprecation)
13
+ if defined?(Spree::Deprecation)
14
+ Spree::Deprecation.warn(
15
+ "#{self.class}#user is deprecated and will be removed in Spree 6.3. Use #customer instead."
16
+ )
17
+ end
14
18
  customer
15
19
  end
16
20
 
17
21
  def user=(value)
18
- Spree::Deprecation.warn("#{self.class}#user= is deprecated and will be removed in Spree 6.1. Use #customer= instead.") if defined?(Spree::Deprecation)
22
+ if defined?(Spree::Deprecation)
23
+ Spree::Deprecation.warn(
24
+ "#{self.class}#user= is deprecated and will be removed in Spree 6.3. Use #customer= instead."
25
+ )
26
+ end
19
27
  self.customer = value
20
28
  end
21
29
  end
@@ -11,7 +11,7 @@ module Spree
11
11
  #
12
12
  # Rows created before 6.0 keep their stored number, so gateway references
13
13
  # and packing slips already in the wild still resolve. New rows never write
14
- # the column — it is frozen legacy data awaiting the 6.1 drop.
14
+ # the column — it is frozen legacy data awaiting the 6.3 drop.
15
15
  module DerivedNumber
16
16
  extend ActiveSupport::Concern
17
17
 
@@ -22,19 +22,21 @@ module Spree
22
22
  [namespace, key]
23
23
  end
24
24
 
25
- # Deprecated 6.0 names, removed in 6.1.
25
+ # Deprecated 6.0 names, removed in 6.3.
26
26
  def ensure_metafield_definition_exists!(key_with_namespace, store: Spree::Current.store)
27
- Spree::Deprecation.warn('ensure_metafield_definition_exists! is deprecated and will be removed in Spree 6.1. Use ensure_custom_field_definition_exists! instead.')
27
+ Spree::Deprecation.warn(
28
+ 'ensure_metafield_definition_exists! is deprecated and will be removed in Spree 6.3. Use ensure_custom_field_definition_exists! instead.'
29
+ )
28
30
  ensure_custom_field_definition_exists!(key_with_namespace, store: store)
29
31
  end
30
32
 
31
33
  def with_metafield_key(key_with_namespace)
32
- Spree::Deprecation.warn('.with_metafield_key is deprecated and will be removed in Spree 6.1. Use .with_custom_field_key instead.')
34
+ Spree::Deprecation.warn('.with_metafield_key is deprecated and will be removed in Spree 6.3. Use .with_custom_field_key instead.')
33
35
  with_custom_field_key(key_with_namespace)
34
36
  end
35
37
 
36
38
  def with_metafield_key_value(key_with_namespace, value)
37
- Spree::Deprecation.warn('.with_metafield_key_value is deprecated and will be removed in Spree 6.1. Use .with_custom_field_key_value instead.')
39
+ Spree::Deprecation.warn('.with_metafield_key_value is deprecated and will be removed in Spree 6.3. Use .with_custom_field_key_value instead.')
38
40
  with_custom_field_key_value(key_with_namespace, value)
39
41
  end
40
42
  end
@@ -46,7 +48,7 @@ module Spree
46
48
  has_many :custom_fields, -> { includes(:custom_field_definition) }, as: :resource, inverse_of: :resource, class_name: 'Spree::CustomField', dependent: :destroy
47
49
  has_many :storefront_custom_fields, -> { includes(:custom_field_definition).storefront_visible }, as: :resource, class_name: 'Spree::CustomField'
48
50
 
49
- # Deprecated 6.0 association names, removed in 6.1. `private_metafields`
51
+ # Deprecated 6.0 association names, removed in 6.3. `private_metafields`
50
52
  # has no replacement — read `custom_fields` and filter, or query
51
53
  # Spree::CustomField.admin_only directly.
52
54
  has_many :metafields, -> { includes(:custom_field_definition) }, as: :resource, class_name: 'Spree::CustomField', deprecated: true
@@ -170,26 +172,26 @@ module Spree
170
172
  custom_fields.with_key(namespace, key).exists?
171
173
  end
172
174
 
173
- # Deprecated 6.0 names, removed in 6.1.
175
+ # Deprecated 6.0 names, removed in 6.3.
174
176
  def set_metafield(definition_or_key, value)
175
- Spree::Deprecation.warn('#set_metafield is deprecated and will be removed in Spree 6.1. Use #set_custom_field instead.')
177
+ Spree::Deprecation.warn('#set_metafield is deprecated and will be removed in Spree 6.3. Use #set_custom_field instead.')
176
178
  set_custom_field(definition_or_key, value)
177
179
  end
178
180
 
179
181
  def get_metafield(key_with_namespace)
180
- Spree::Deprecation.warn('#get_metafield is deprecated and will be removed in Spree 6.1. Use #get_custom_field instead.')
182
+ Spree::Deprecation.warn('#get_metafield is deprecated and will be removed in Spree 6.3. Use #get_custom_field instead.')
181
183
  get_custom_field(key_with_namespace)
182
184
  end
183
185
 
184
186
  def has_metafield?(key_with_namespace)
185
- Spree::Deprecation.warn('#has_metafield? is deprecated and will be removed in Spree 6.1. Use #has_custom_field? instead.')
187
+ Spree::Deprecation.warn('#has_metafield? is deprecated and will be removed in Spree 6.3. Use #has_custom_field? instead.')
186
188
  has_custom_field?(key_with_namespace)
187
189
  end
188
190
 
189
191
  # Legacy payloads key the definition as `metafield_definition_id`, which
190
192
  # the new writer rejects — translate rather than silently dropping them.
191
193
  def metafields_attributes=(attributes)
192
- Spree::Deprecation.warn('#metafields_attributes= is deprecated and will be removed in Spree 6.1. Use #custom_fields_attributes= instead.')
194
+ Spree::Deprecation.warn('#metafields_attributes= is deprecated and will be removed in Spree 6.3. Use #custom_fields_attributes= instead.')
193
195
 
194
196
  attributes = attributes.values if attributes.is_a?(Hash)
195
197
  translated = attributes.map do |attrs|
@@ -1,5 +1,5 @@
1
1
  module Spree
2
- # @deprecated Use {Spree::Current.integrations}; removed in Spree 6.1.
2
+ # @deprecated Use {Spree::Current.integrations}; removed in Spree 6.3.
3
3
  #
4
4
  # Nothing in Spree calls these — the per-request integration set lives on
5
5
  # {Spree::Current} — but the concern sits on Spree::Base, so every model has
@@ -7,7 +7,8 @@ module Spree
7
7
  module IntegrationsConcern
8
8
  def store_integrations
9
9
  Spree::Deprecation.warn(
10
- 'Spree::IntegrationsConcern#store_integrations is deprecated and will be removed in Spree 6.1. ' 'Use Spree::Current.integrations instead.'
10
+ 'Spree::IntegrationsConcern#store_integrations is deprecated and will be removed in Spree 6.3. ' \
11
+ 'Use Spree::Current.integrations instead.'
11
12
  )
12
13
 
13
14
  Spree::Current.integrations
@@ -15,7 +16,8 @@ module Spree
15
16
 
16
17
  def store_integration(name)
17
18
  Spree::Deprecation.warn(
18
- 'Spree::IntegrationsConcern#store_integration is deprecated and will be removed in Spree 6.1. ' 'Use Spree::Current.integrations.find { |integration| integration.type.to_s.demodulize.underscore == name } instead.'
19
+ 'Spree::IntegrationsConcern#store_integration is deprecated and will be removed in Spree 6.3. ' \
20
+ 'Use Spree::Current.integrations.find { |integration| integration.type.to_s.demodulize.underscore == name } instead.'
19
21
  )
20
22
 
21
23
  Spree::Current.integrations.find { |integration| integration.type.to_s.demodulize.underscore == name }
@@ -16,7 +16,7 @@ module Spree
16
16
  end
17
17
  end
18
18
 
19
- # @deprecated The column is +label+ since 6.0; removed in 6.1.
19
+ # @deprecated The column is +label+ since 6.0; removed in 6.3.
20
20
  #
21
21
  # Unlike the attribute aliases the other 6.0 renames use, this is a plain
22
22
  # method — Mobility owns +label+, so it cannot be an alias_attribute. It
@@ -24,13 +24,13 @@ module Spree
24
24
  # and +find_by(presentation:)+ name a column that no longer exists and
25
25
  # raise. Query by +label+.
26
26
  def presentation(*args, **kwargs)
27
- Spree::Deprecation.warn("#{self.class.name}#presentation is deprecated and will be removed in Spree 6.1. Use #label instead.")
27
+ Spree::Deprecation.warn("#{self.class.name}#presentation is deprecated and will be removed in Spree 6.3. Use #label instead.")
28
28
  label(*args, **kwargs)
29
29
  end
30
30
 
31
- # @deprecated See {#presentation}; removed in 6.1.
31
+ # @deprecated See {#presentation}; removed in 6.3.
32
32
  def presentation=(value)
33
- Spree::Deprecation.warn("#{self.class.name}#presentation= is deprecated and will be removed in Spree 6.1. Use #label= instead.")
33
+ Spree::Deprecation.warn("#{self.class.name}#presentation= is deprecated and will be removed in Spree 6.3. Use #label= instead.")
34
34
  self.label = value
35
35
  end
36
36
  end
@@ -11,7 +11,7 @@ module Spree
11
11
  serialize :metadata, coder: HashSerializer
12
12
  end
13
13
 
14
- # Deprecated alias for the renamed `metadata` column. Removed in Spree 6.1.
14
+ # Deprecated alias for the renamed `metadata` column. Removed in Spree 6.3.
15
15
  #
16
16
  # Only the reader and writer are bridged. The column is gone, so the attribute
17
17
  # methods Active Record generated alongside it — `private_metadata?`,
@@ -19,12 +19,12 @@ module Spree
19
19
  # `private_metadata_before_type_cast` and the rest of the dirty-tracking family
20
20
  # — no longer exist and raise NoMethodError. Call the `metadata` equivalents.
21
21
  def private_metadata
22
- Spree::Deprecation.warn('private_metadata is deprecated and will be removed in Spree 6.1. Use metadata instead.')
22
+ Spree::Deprecation.warn('private_metadata is deprecated and will be removed in Spree 6.3. Use metadata instead.')
23
23
  metadata
24
24
  end
25
25
 
26
26
  def private_metadata=(value)
27
- Spree::Deprecation.warn('private_metadata= is deprecated and will be removed in Spree 6.1. Use metadata= instead.')
27
+ Spree::Deprecation.warn('private_metadata= is deprecated and will be removed in Spree 6.3. Use metadata= instead.')
28
28
  self.metadata = value
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  # Constant alias for the legacy Spree::PresentationTranslatable, renamed to
3
3
  # Spree::LabelTranslatable in 6.0 along with the column it wrapped.
4
- # Remove in 6.1.
4
+ # Remove in 6.3.
5
5
  PresentationTranslatable = LabelTranslatable
6
6
  end
@@ -193,7 +193,10 @@ module Spree
193
193
  # a red XL. Every axis is therefore counted against the same variant row
194
194
  # rather than asked of the product separately — which is also what keeps
195
195
  # a filter honest once several sellers list variants on one product.
196
- def self.with_option_value_ids(*ids)
196
+ #
197
+ # +variants+ narrows which variants may answer: the storefront passes
198
+ # +Variant.for_option_filters+, while the admin keeps every variant.
199
+ def self.with_option_value_ids(*ids, variants: nil)
197
200
  ids = ids.flatten.compact
198
201
  return none if ids.empty?
199
202
 
@@ -203,7 +206,7 @@ module Spree
203
206
  grouped = OptionValue.where(id: actual_ids).group_by(&:option_type_id)
204
207
  return none if grouped.empty?
205
208
 
206
- matching_product_ids = Variant.where(deleted_at: nil).
209
+ matching_product_ids = (variants || Variant).where(deleted_at: nil).
207
210
  joins(option_value_variants: :option_value).
208
211
  where(OptionValue.table_name => { id: actual_ids }).
209
212
  group(Variant.arel_table[:id]).
@@ -7,7 +7,7 @@ module Spree
7
7
  # of checkout addresses to the customer's defaults, and the ship→bill cloning
8
8
  # predicate. The shipping address is canonical: use_shipping copies it
9
9
  # onto the billing address; the reverse use_billing direction is a
10
- # deprecated 6.1-removal bridge. Clone callbacks are wired per model.
10
+ # deprecated 6.3-removal bridge. Clone callbacks are wired per model.
11
11
  module Addresses
12
12
  extend ActiveSupport::Concern
13
13
 
@@ -85,13 +85,16 @@ module Spree
85
85
  end
86
86
 
87
87
  # @deprecated The shipping address is canonical — use +use_shipping+ to
88
- # copy it onto the billing address. Removed in 6.1.
88
+ # copy it onto the billing address. Removed in 6.3.
89
89
  def use_billing=(value)
90
- Spree::Deprecation.warn('use_billing is deprecated and will be removed in Spree 6.1. The shipping address comes first — use use_shipping to copy it onto the billing address.')
90
+ Spree::Deprecation.warn(
91
+ 'use_billing is deprecated and will be removed in Spree 6.3. ' \
92
+ 'The shipping address comes first — use use_shipping to copy it onto the billing address.'
93
+ )
91
94
  @use_billing = value
92
95
  end
93
96
 
94
- # @deprecated See {#use_billing=}; removed in 6.1.
97
+ # @deprecated See {#use_billing=}; removed in 6.3.
95
98
  # @return [Boolean]
96
99
  def use_billing?
97
100
  use_billing.in?([true, 'true', '1'])
@@ -194,7 +197,7 @@ module Spree
194
197
  # customer's default ship address.
195
198
  #
196
199
  # @deprecated The shipping address is canonical (see {#use_billing=});
197
- # removed in 6.1 together with the use_billing bridge.
200
+ # removed in 6.3 together with the use_billing bridge.
198
201
  # @return [true]
199
202
  def clone_billing_address
200
203
  self.ship_address = bill_address if bill_address
@@ -4,7 +4,7 @@ module Spree
4
4
  # {Spree::Cart} and {Spree::Order}. Before 6.0 a cart was an incomplete
5
5
  # order, so extensions written against 5.x (payment gateways, checkout
6
6
  # plugins) call the legacy names on carts too. Every legacy name warns and
7
- # forwards to its replacement. Removed in 6.1.
7
+ # forwards to its replacement. Removed in 6.3.
8
8
  #
9
9
  # Renamed columns are also registered with +alias_attribute+, so the legacy
10
10
  # name keeps working in +where+ / +find_by+ (those paths do not warn).
@@ -80,7 +80,7 @@ module Spree
80
80
  private
81
81
 
82
82
  def warn_deprecated_name(legacy_name, current_name)
83
- Spree::Deprecation.warn("#{self.class.name}##{legacy_name} is deprecated and will be removed in Spree 6.1. Use ##{current_name} instead.")
83
+ Spree::Deprecation.warn("#{self.class.name}##{legacy_name} is deprecated and will be removed in Spree 6.3. Use ##{current_name} instead.")
84
84
  end
85
85
  end
86
86
  end
@@ -62,6 +62,14 @@ module Spree
62
62
  payments.select(&:checkout?)
63
63
  end
64
64
 
65
+ # What is still owed once every live payment is counted, settled or not —
66
+ # the amount a new payment should be for. Never negative.
67
+ #
68
+ # @return [BigDecimal]
69
+ def amount_left_to_pay
70
+ [outstanding_balance - valid_payments.reject { |payment| payment.status == 'completed' }.sum(BigDecimal('0'), &:amount), BigDecimal('0')].max
71
+ end
72
+
65
73
  private
66
74
 
67
75
  # On a list the association batches across the page, so the loaded rows
@@ -85,6 +93,9 @@ module Spree
85
93
 
86
94
  unprocessed_payments.each do |payment|
87
95
  break if settled_payment_total >= total
96
+ # An order can carry several live payments; once those processed
97
+ # so far cover it, net of refunds, the rest are left uncharged.
98
+ break if is_a?(Spree::Order) && payment.amount_owed_by_order(including_in_flight: true)&.zero?
88
99
 
89
100
  result = Spree.payment_process_workflow.call(payment: payment, action: action)
90
101
  raise Spree::Core::GatewayError, result.error.value.to_s if result.failure?