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.
- checksums.yaml +4 -4
- data/app/jobs/spree/imports/create_rows_job.rb +4 -2
- data/app/jobs/spree/imports/process_rows_job.rb +4 -2
- 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/jobs/spree/products/auto_match_taxons_job.rb +5 -2
- data/app/jobs/spree/search_provider/index_job.rb +8 -0
- data/app/jobs/spree/search_provider/remove_job.rb +3 -0
- data/app/jobs/spree/stock_locations/stock_items/create_job.rb +5 -2
- data/app/mailers/spree/base_mailer.rb +1 -1
- data/app/maintenance_tasks/spree/maintenance_tasks/upgrade/backfill_settlement_statuses.rb +40 -0
- data/app/models/concerns/spree/acted_by.rb +2 -2
- data/app/models/concerns/spree/customer_methods.rb +7 -5
- data/app/models/concerns/spree/deprecated_customer_alias.rb +11 -3
- data/app/models/concerns/spree/derived_number.rb +1 -1
- data/app/models/concerns/spree/has_custom_fields.rb +12 -10
- data/app/models/concerns/spree/integrations_concern.rb +5 -3
- data/app/models/concerns/spree/label_translatable.rb +4 -4
- data/app/models/concerns/spree/metadata.rb +3 -3
- data/app/models/concerns/spree/presentation_translatable.rb +1 -1
- data/app/models/concerns/spree/product_scopes.rb +5 -2
- data/app/models/concerns/spree/purchase/addresses.rb +8 -5
- data/app/models/concerns/spree/purchase/deprecated_aliases.rb +2 -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 +4 -32
- data/app/models/concerns/spree/user_address.rb +5 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +29 -14
- data/app/models/spree/asset.rb +3 -3
- data/app/models/spree/base.rb +4 -4
- data/app/models/spree/calculator/shipping/flat_rate.rb +6 -4
- data/app/models/spree/cart.rb +2 -2
- data/app/models/spree/category.rb +61 -38
- data/app/models/spree/classification.rb +2 -2
- data/app/models/spree/collection_rule.rb +5 -1
- data/app/models/spree/current.rb +19 -0
- data/app/models/spree/custom_field.rb +6 -6
- data/app/models/spree/custom_field_definition.rb +10 -7
- data/app/models/spree/delivery_method.rb +21 -15
- data/app/models/spree/delivery_rate.rb +1 -1
- data/app/models/spree/digital.rb +1 -1
- data/app/models/spree/digital_asset.rb +2 -2
- data/app/models/spree/digital_link.rb +4 -4
- data/app/models/spree/export.rb +32 -3
- data/app/models/spree/exports/products.rb +9 -1
- data/app/models/spree/fulfillment/custom_events.rb +18 -10
- data/app/models/spree/fulfillment.rb +53 -29
- data/app/models/spree/fulfillment_group.rb +2 -2
- data/app/models/spree/fulfillment_item.rb +3 -3
- data/app/models/spree/fulfilment_changer.rb +1 -1
- data/app/models/spree/gateway/bogus.rb +41 -2
- data/app/models/spree/gift_card.rb +26 -14
- data/app/models/spree/import.rb +23 -15
- data/app/models/spree/import_row.rb +6 -6
- data/app/models/spree/inventory_unit.rb +1 -1
- data/app/models/spree/invitation.rb +8 -4
- data/app/models/spree/line_item.rb +10 -8
- data/app/models/spree/media.rb +3 -3
- data/app/models/spree/metafield.rb +1 -1
- data/app/models/spree/metafield_definition.rb +1 -1
- data/app/models/spree/metafields.rb +2 -2
- data/app/models/spree/option_type.rb +27 -0
- data/app/models/spree/option_value.rb +3 -3
- data/app/models/spree/order.rb +97 -49
- data/app/models/spree/order_group.rb +2 -2
- data/app/models/spree/order_inventory.rb +2 -2
- data/app/models/spree/order_merger.rb +2 -2
- data/app/models/spree/order_updater.rb +34 -20
- 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 +194 -15
- 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 +65 -11
- 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 +20 -8
- data/app/models/spree/price_list.rb +12 -6
- data/app/models/spree/price_rules/zone_rule.rb +1 -1
- data/app/models/spree/product.rb +30 -28
- data/app/models/spree/product_category.rb +3 -3
- data/app/models/spree/promotion/rules/category.rb +27 -10
- data/app/models/spree/promotion/rules/country.rb +1 -1
- data/app/models/spree/promotion/rules/taxon.rb +4 -2
- data/app/models/spree/promotion/rules/user.rb +1 -1
- data/app/models/spree/promotion_action.rb +1 -1
- data/app/models/spree/promotion_rule_category.rb +5 -5
- data/app/models/spree/promotion_rule_taxon.rb +2 -2
- data/app/models/spree/prototype.rb +4 -1
- 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/return_authorization_reason.rb +3 -3
- data/app/models/spree/return_reason.rb +1 -1
- data/app/models/spree/search_provider/base.rb +12 -2
- data/app/models/spree/search_provider/database.rb +8 -5
- data/app/models/spree/search_provider.rb +7 -5
- data/app/models/spree/shipment.rb +4 -1
- data/app/models/spree/shipping_method.rb +4 -1
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/stock/coordinator.rb +2 -2
- data/app/models/spree/stock/estimator.rb +7 -5
- data/app/models/spree/stock/package.rb +10 -8
- data/app/models/spree/stock_item.rb +1 -1
- data/app/models/spree/stock_level/custom_events.rb +1 -1
- data/app/models/spree/stock_level.rb +1 -1
- data/app/models/spree/stock_location.rb +12 -8
- data/app/models/spree/stock_movement.rb +6 -6
- data/app/models/spree/stock_reservation.rb +5 -5
- data/app/models/spree/store.rb +64 -16
- data/app/models/spree/store_credit.rb +3 -3
- data/app/models/spree/store_credit_category.rb +5 -5
- data/app/models/spree/store_credit_type.rb +2 -2
- data/app/models/spree/subscriber.rb +7 -7
- data/app/models/spree/tax_rate.rb +5 -5
- data/app/models/spree/taxon.rb +3 -3
- data/app/models/spree/taxon_rule.rb +2 -2
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/variant.rb +45 -10
- data/app/models/spree/variant_media.rb +1 -1
- data/app/models/spree/wished_item.rb +1 -1
- data/app/models/spree/wishlist.rb +2 -2
- data/app/models/spree/wishlist_item/custom_events.rb +2 -2
- data/app/models/spree/zone.rb +1 -1
- data/app/models/spree/zone_member.rb +1 -1
- 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/associate.rb +6 -2
- data/app/services/spree/carts/create.rb +1 -1
- data/app/services/spree/carts/destroy.rb +1 -1
- data/app/services/spree/carts/remove_item.rb +1 -1
- data/app/services/spree/carts/remove_line_item.rb +2 -2
- data/app/services/spree/carts/remove_out_of_stock_items.rb +3 -1
- data/app/services/spree/carts/set_quantity.rb +2 -2
- data/app/services/spree/carts/split_by_seller.rb +4 -13
- data/app/services/spree/carts/update.rb +17 -0
- data/app/services/spree/checkout/add_store_credit.rb +3 -3
- data/app/services/spree/checkout/remove_store_credit.rb +2 -2
- data/app/services/spree/imports/row_processors/product_variant.rb +19 -0
- data/app/services/spree/orders/approve.rb +3 -3
- data/app/services/spree/orders/create_from_cart.rb +2 -0
- data/app/services/spree/orders/create_user_account.rb +2 -2
- data/app/services/spree/orders/update_statuses.rb +4 -2
- data/app/services/spree/products/auto_match_taxons.rb +5 -2
- data/app/services/spree/shipments/update.rb +2 -2
- data/app/services/spree/stock_locations/stock_items/create.rb +5 -2
- data/app/services/spree/stock_reservations/extend.rb +3 -1
- data/app/services/spree/stock_reservations/reserve.rb +3 -1
- data/app/services/spree/store_credits/apply.rb +1 -1
- data/app/services/spree/taxons/add_products.rb +4 -2
- data/app/services/spree/taxons/regenerate_products.rb +5 -2
- data/app/services/spree/taxons/remove_products.rb +4 -2
- 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/add_item.rb +1 -1
- data/app/workflows/spree/carts/complete.rb +1 -19
- data/app/workflows/spree/carts/recalculate.rb +1 -1
- data/app/workflows/spree/carts/recalculate_totals.rb +3 -3
- data/app/workflows/spree/fulfillments/update.rb +1 -1
- data/app/workflows/spree/orders/cancel.rb +22 -1
- data/app/workflows/spree/orders/complete.rb +7 -1
- data/app/workflows/spree/payments/capture.rb +101 -7
- 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/app/workflows/spree/seller_transfers/create.rb +1 -1
- data/config/locales/be.yml +2 -2
- data/config/locales/bg.yml +4 -4
- data/config/locales/en.yml +12 -0
- data/config/locales/ru.yml +3 -3
- data/db/migrate/20260710000001_rename_taxons_to_categories.rb +1 -1
- data/db/migrate/20260728000004_rename_shipping_to_fulfillment_and_delivery.rb +1 -1
- data/db/migrate/20260806000001_add_store_id_to_spree_tax_rates_and_categories.rb +1 -1
- data/db/migrate/20260807130001_add_country_state_codes_to_consumers.rb +1 -1
- data/db/migrate/20260809000001_rename_metafields_to_custom_fields.rb +1 -1
- data/db/migrate/20260809150001_promote_shipping_categories_to_delivery_profiles.rb +1 -1
- data/db/migrate/20260811000001_add_delivery_tracking_to_fulfillments.rb +1 -1
- data/db/migrate/20260824000001_add_store_to_spree_media.rb +1 -1
- data/db/migrate/20260828100001_unify_import_and_export_tenancy.rb +1 -1
- data/db/migrate/20261016000001_remove_default_from_spree_tax_rates_included_in_price.rb +1 -1
- 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/agent_tools/default_catalog.rb +2 -2
- data/lib/spree/agent_tools/legacy_tools.rb +1 -1
- data/lib/spree/core/dependencies.rb +11 -10
- data/lib/spree/core/engine.rb +4 -0
- data/lib/spree/core/number_generator.rb +4 -3
- data/lib/spree/core/preferences/preferable.rb +1 -1
- data/lib/spree/core/preferences/preferable_class_methods.rb +5 -1
- data/lib/spree/core/pricing/resolver.rb +2 -2
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +37 -10
- data/lib/spree/i18n.rb +6 -2
- data/lib/spree/localized_number.rb +1 -1
- data/lib/spree/removed_apis.rb +274 -0
- data/lib/spree/reporting/adapters/live.rb +69 -8
- data/lib/spree/reporting/default_vocabulary.rb +11 -5
- data/lib/spree/reporting/query.rb +4 -1
- data/lib/spree/reporting/registry.rb +50 -3
- data/lib/spree/testing_support/factories/digital_asset_factory.rb +1 -1
- 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/testing_support/factories/stock_level_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxon_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +1 -1
- data/lib/spree/testing_support/factories/wishlist_item_factory.rb +1 -1
- data/lib/spree/testing_support/i18n.rb +7 -2
- data/lib/spree/testing_support/order_walkthrough.rb +5 -2
- data/lib/spree/upgrades/5_6_to_6_0/manifest.yml +71 -14
- data/lib/tasks/carts_migration.rake +1 -1
- data/lib/tasks/categories_and_collections.rake +1 -1
- data/lib/tasks/deliveries_migration.rake +1 -1
- data/lib/tasks/delivery_method_rules_migration.rake +1 -1
- data/lib/tasks/delivery_migration.rake +1 -1
- data/lib/tasks/delivery_profiles_migration.rake +2 -2
- data/lib/tasks/fold_store_credit_categories.rake +1 -1
- data/lib/tasks/migrate_country_state_codes.rake +1 -1
- data/lib/tasks/migrate_returns.rake +4 -4
- data/lib/tasks/migrate_rich_text_to_columns.rake +1 -1
- data/lib/tasks/store_settings.rake +1 -1
- data/lib/tasks/typed_stock_movements_migration.rake +1 -1
- metadata +26 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Spree
|
|
2
|
-
# @deprecated Removed in Spree 6.
|
|
2
|
+
# @deprecated Removed in Spree 6.3. Every method is a thin shim over the
|
|
3
3
|
# flows that own the work:
|
|
4
4
|
#
|
|
5
5
|
# * money — {Spree::Carts::RecalculateTotals} /
|
|
@@ -21,14 +21,14 @@ module Spree
|
|
|
21
21
|
|
|
22
22
|
# @deprecated Use {Spree::Carts::RecalculateTotals} /
|
|
23
23
|
# {Spree::Orders::RecalculateTotals} (or +#recalculate_totals!+);
|
|
24
|
-
# removed in 6.
|
|
24
|
+
# removed in 6.3.
|
|
25
25
|
def update
|
|
26
26
|
deprecate_totals(__method__)
|
|
27
27
|
recalculate_totals
|
|
28
28
|
update_statuses if order.completed?
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
31
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3. The
|
|
32
32
|
# totals workflow rebuilds the typed adjustment rows as part of its
|
|
33
33
|
# money pass.
|
|
34
34
|
def recalculate_adjustments
|
|
@@ -36,62 +36,65 @@ module Spree
|
|
|
36
36
|
recalculate_totals
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
39
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
40
40
|
def update_totals
|
|
41
41
|
deprecate_totals(__method__)
|
|
42
42
|
recalculate_totals
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
45
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
46
46
|
def update_payment_total
|
|
47
47
|
deprecate_totals(__method__)
|
|
48
48
|
recalculate_totals
|
|
49
49
|
order.payment_total
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
52
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
53
53
|
def update_item_total
|
|
54
54
|
deprecate_totals(__method__)
|
|
55
55
|
recalculate_totals
|
|
56
56
|
order.item_total
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
59
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
60
60
|
def update_order_total
|
|
61
61
|
deprecate_totals(__method__)
|
|
62
62
|
recalculate_totals
|
|
63
63
|
order.total
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
66
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
67
67
|
def update_adjustment_total
|
|
68
68
|
deprecate_totals(__method__)
|
|
69
69
|
recalculate_totals
|
|
70
70
|
order.adjustment_total
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
73
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
74
74
|
def update_item_count
|
|
75
75
|
deprecate_totals(__method__)
|
|
76
76
|
recalculate_totals
|
|
77
77
|
order.total_quantity
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
80
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
81
81
|
def persist_totals
|
|
82
82
|
deprecate_totals(__method__)
|
|
83
83
|
recalculate_totals
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.
|
|
86
|
+
# @deprecated Use {Spree::Carts::RecalculateTotals}; removed in 6.3.
|
|
87
87
|
def update_shipment_total
|
|
88
|
-
Spree::Deprecation.warn(
|
|
88
|
+
Spree::Deprecation.warn(
|
|
89
|
+
'Spree::OrderUpdater#update_shipment_total is deprecated and will be removed in Spree 6.3. ' \
|
|
90
|
+
'Use Spree::Carts::RecalculateTotals / Spree::Orders::RecalculateTotals (or #recalculate_totals!) instead.'
|
|
91
|
+
)
|
|
89
92
|
recalculate_totals
|
|
90
93
|
order.delivery_total
|
|
91
94
|
end
|
|
92
95
|
|
|
93
96
|
# @deprecated Use {Spree::Orders::UpdateStatuses} (or
|
|
94
|
-
# +#update_statuses!+); removed in 6.
|
|
97
|
+
# +#update_statuses!+); removed in 6.3. UpdateStatuses writes the 6.0
|
|
95
98
|
# vocabulary (none/authorized/partially_paid/paid/partially_refunded/
|
|
96
99
|
# refunded/overcharged/voided), not the legacy balance_due/credit_owed/
|
|
97
100
|
# failed/void names.
|
|
@@ -102,7 +105,7 @@ module Spree
|
|
|
102
105
|
end
|
|
103
106
|
|
|
104
107
|
# @deprecated Use {Spree::Orders::UpdateStatuses} (or
|
|
105
|
-
# +#update_statuses!+); removed in 6.
|
|
108
|
+
# +#update_statuses!+); removed in 6.3.
|
|
106
109
|
def update_shipment_state
|
|
107
110
|
deprecate_statuses(__method__)
|
|
108
111
|
update_statuses
|
|
@@ -111,9 +114,12 @@ module Spree
|
|
|
111
114
|
|
|
112
115
|
# @deprecated Use {Spree::Orders::UpdateStatuses} for the state roll-up
|
|
113
116
|
# and {Spree::Carts::Recalculate} for the delivery proposal rebuild;
|
|
114
|
-
# removed in 6.
|
|
117
|
+
# removed in 6.3.
|
|
115
118
|
def update_shipments
|
|
116
|
-
Spree::Deprecation.warn(
|
|
119
|
+
Spree::Deprecation.warn(
|
|
120
|
+
'Spree::OrderUpdater#update_shipments is deprecated and will be removed in Spree 6.3. ' \
|
|
121
|
+
'Use Spree::Orders::UpdateStatuses (fulfillment states) and Spree::Carts::Recalculate (delivery proposals) instead.'
|
|
122
|
+
)
|
|
117
123
|
|
|
118
124
|
audience = order.completed? ? DeliveryMethod::BACKOFFICE : DeliveryMethod::STOREFRONT
|
|
119
125
|
|
|
@@ -128,10 +134,12 @@ module Spree
|
|
|
128
134
|
end
|
|
129
135
|
end
|
|
130
136
|
|
|
131
|
-
# @deprecated Order update hooks are removed in 6.
|
|
137
|
+
# @deprecated Order update hooks are removed in 6.3 — subscribe to the
|
|
132
138
|
# +order.updated+ event instead.
|
|
133
139
|
def run_hooks
|
|
134
|
-
Spree::Deprecation.warn(
|
|
140
|
+
Spree::Deprecation.warn(
|
|
141
|
+
'Spree::OrderUpdater#run_hooks is deprecated and will be removed in Spree 6.3. Subscribe to the order.updated event instead.'
|
|
142
|
+
)
|
|
135
143
|
update_hooks.each { |hook| order.send hook }
|
|
136
144
|
end
|
|
137
145
|
|
|
@@ -162,11 +170,17 @@ module Spree
|
|
|
162
170
|
end
|
|
163
171
|
|
|
164
172
|
def deprecate_totals(method_name)
|
|
165
|
-
Spree::Deprecation.warn(
|
|
173
|
+
Spree::Deprecation.warn(
|
|
174
|
+
"Spree::OrderUpdater##{method_name} is deprecated and will be removed in Spree 6.3. " \
|
|
175
|
+
'Use Spree::Carts::RecalculateTotals / Spree::Orders::RecalculateTotals (or #recalculate_totals!) instead.'
|
|
176
|
+
)
|
|
166
177
|
end
|
|
167
178
|
|
|
168
179
|
def deprecate_statuses(method_name)
|
|
169
|
-
Spree::Deprecation.warn(
|
|
180
|
+
Spree::Deprecation.warn(
|
|
181
|
+
"Spree::OrderUpdater##{method_name} is deprecated and will be removed in Spree 6.3. " \
|
|
182
|
+
'Use Spree::Orders::UpdateStatuses (or #update_statuses!) instead.'
|
|
183
|
+
)
|
|
170
184
|
end
|
|
171
185
|
end
|
|
172
186
|
end
|
|
@@ -48,7 +48,8 @@ module Spree
|
|
|
48
48
|
def order_settled_in_full?
|
|
49
49
|
return false unless order.total.to_d.positive?
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
completed = order.payments.completed
|
|
52
|
+
settled = completed.sum(:amount) - Spree::Refund.completed_or_unset.where(payment_id: completed.select(:id)).sum(:amount)
|
|
52
53
|
settled >= order.total.to_d
|
|
53
54
|
end
|
|
54
55
|
|
|
@@ -67,14 +67,16 @@ module Spree
|
|
|
67
67
|
# @param captured [Boolean, nil] whether the gateway reports the funds
|
|
68
68
|
# as captured. Callers who know the gateway state pass it; nil falls
|
|
69
69
|
# back to when the payment method charges.
|
|
70
|
-
|
|
70
|
+
# @param capture_reference [String, nil] the provider's id for the
|
|
71
|
+
# capture, recorded so a late capture failure can find it
|
|
72
|
+
def confirm!(captured: nil, capture_reference: nil)
|
|
71
73
|
captured = payment_method&.capture_at_checkout? if captured.nil?
|
|
72
74
|
|
|
73
75
|
started_processing! if checkout?
|
|
74
76
|
|
|
75
77
|
if captured && can_complete?
|
|
76
78
|
complete!
|
|
77
|
-
capture_events.create!(amount: amount)
|
|
79
|
+
capture_events.create!(amount: amount, status: 'completed', transaction_id: capture_reference)
|
|
78
80
|
elsif can_pend?
|
|
79
81
|
pend!
|
|
80
82
|
end
|
|
@@ -85,12 +87,26 @@ module Spree
|
|
|
85
87
|
# payment_method.cancel routes refunds through Refunds::Create. An
|
|
86
88
|
# adapter that can void the payment outright does so either way.
|
|
87
89
|
#
|
|
90
|
+
# A captured charge the gateway did not void keeps its completed status:
|
|
91
|
+
# the money was either refunded, which the refund records, or kept.
|
|
92
|
+
#
|
|
93
|
+
# A provider that answers +requested?+ settles later by webhook: an
|
|
94
|
+
# uncaptured payment waits on its void, and a completed one stays
|
|
95
|
+
# completed while the refund the gateway requested carries the outcome.
|
|
96
|
+
# So a gateway answers +requested?+ for a completed payment only after
|
|
97
|
+
# recording that refund (through Refunds::Create), or the outcome finds
|
|
98
|
+
# nothing to settle.
|
|
99
|
+
#
|
|
88
100
|
# @param refund [Boolean] whether money already captured may be returned
|
|
89
101
|
def cancel!(refund: true)
|
|
102
|
+
voids = payment_method.cancel_voids?(self)
|
|
90
103
|
response = instrument_gateway_call(:cancel, payment_method) do
|
|
91
104
|
payment_method.cancel(response_code, self, refund: refund)
|
|
92
105
|
end
|
|
93
|
-
handle_response(response, :void)
|
|
106
|
+
return handle_response(response, voids ? :void : :keep) unless response.success? && response.requested?
|
|
107
|
+
return true if completed?
|
|
108
|
+
|
|
109
|
+
request_void!
|
|
94
110
|
end
|
|
95
111
|
|
|
96
112
|
def gateway_options
|
|
@@ -122,6 +138,7 @@ module Spree
|
|
|
122
138
|
when :complete then complete!
|
|
123
139
|
when :pend then pend!
|
|
124
140
|
when :void then void!
|
|
141
|
+
when :keep then nil
|
|
125
142
|
else raise ArgumentError, "Unknown payment success state: #{success_state.inspect}"
|
|
126
143
|
end
|
|
127
144
|
else
|
data/app/models/spree/payment.rb
CHANGED
|
@@ -19,7 +19,8 @@ module Spree
|
|
|
19
19
|
include Spree::Payment::CustomEvents
|
|
20
20
|
|
|
21
21
|
publishes_lifecycle_events
|
|
22
|
-
publishes_events :captured, :completed, :paid, :refunded, :voided
|
|
22
|
+
publishes_events :captured, :completed, :paid, :refunded, :voided,
|
|
23
|
+
:capture_requested, :capture_failed, :void_requested, :void_failed
|
|
23
24
|
|
|
24
25
|
NON_RISKY_AVS_CODES = ['B', 'D', 'H', 'J', 'M', 'Q', 'T', 'V', 'X', 'Y'].freeze
|
|
25
26
|
RISKY_AVS_CODES = ['A', 'C', 'E', 'F', 'G', 'I', 'K', 'L', 'N', 'O', 'P', 'R', 'S', 'U', 'W', 'Z'].freeze
|
|
@@ -31,6 +32,9 @@ module Spree
|
|
|
31
32
|
# method is consulted. Extend them to support gateways with other flows.
|
|
32
33
|
VOIDABLE_STATUSES = %w[pending processing completed checkout].freeze
|
|
33
34
|
CAPTURABLE_STATUSES = %w[checkout pending].freeze
|
|
35
|
+
# A payment settlement must leave alone: captured, or waiting on its
|
|
36
|
+
# provider's answer to a capture or void.
|
|
37
|
+
SETTLED_OR_WAITING_STATUSES = %w[completed requested].freeze
|
|
34
38
|
|
|
35
39
|
with_options inverse_of: :payments do
|
|
36
40
|
belongs_to :order, class_name: 'Spree::Order', touch: true, optional: true
|
|
@@ -89,7 +93,7 @@ module Spree
|
|
|
89
93
|
default_scope { order(:created_at) }
|
|
90
94
|
|
|
91
95
|
scope :from_credit_card, -> { where(source_type: 'Spree::CreditCard') }
|
|
92
|
-
# @deprecated use the status scopes / +where(status:)+ — removed in 6.
|
|
96
|
+
# @deprecated use the status scopes / +where(status:)+ — removed in 6.3
|
|
93
97
|
scope :with_state, ->(s) { where(status: s.to_s) }
|
|
94
98
|
# "offset" is reserved by activerecord
|
|
95
99
|
scope :offset_payment, -> { where("source_type = 'Spree::Payment' AND amount < 0 AND status = 'completed'") }
|
|
@@ -105,7 +109,7 @@ module Spree
|
|
|
105
109
|
scope :not_store_credits, -> { where(arel_table[:source_type].not_eq(Spree::StoreCredit.to_s).or(arel_table[:source_type].eq(nil))) }
|
|
106
110
|
|
|
107
111
|
self.whitelisted_ransackable_associations = %w[payment_method order source]
|
|
108
|
-
ransack_alias :state, :status # @deprecated filter alias — removed in 6.
|
|
112
|
+
ransack_alias :state, :status # @deprecated filter alias — removed in 6.5
|
|
109
113
|
# `number` is deliberately absent: it is derived (its column is NULL on
|
|
110
114
|
# 6.0 rows), so a filter on it silently matches nothing. The 6.1 payment
|
|
111
115
|
# `reference` becomes the searchable identifier
|
|
@@ -125,7 +129,11 @@ module Spree
|
|
|
125
129
|
# `invalid` status deliberately generates no predicate or scope: `invalid?`
|
|
126
130
|
# is ActiveModel's, use +has_invalid_status?+.
|
|
127
131
|
include Spree::HasStatus
|
|
128
|
-
|
|
132
|
+
# `requested` waits on the provider's webhook after it accepted a capture
|
|
133
|
+
# or void (a gateway answering `requested?`). It is in none of the
|
|
134
|
+
# claimable, voidable or capturable lists: nothing may start on the
|
|
135
|
+
# payment until the provider answers.
|
|
136
|
+
has_status :checkout, :processing, :pending, :requested, :completed, :failed, :void, :invalid,
|
|
129
137
|
default: :checkout
|
|
130
138
|
|
|
131
139
|
# Status writes, called from the payments workflows and Processing. The
|
|
@@ -205,6 +213,19 @@ module Spree
|
|
|
205
213
|
true
|
|
206
214
|
end
|
|
207
215
|
|
|
216
|
+
# The provider accepted a void and answers by webhook, which voids the
|
|
217
|
+
# payment then. A payment already void, or already waiting, is left as it
|
|
218
|
+
# is: a second request's late answer must not reopen it.
|
|
219
|
+
def request_void!
|
|
220
|
+
updates = { status: 'requested', updated_at: Time.current }
|
|
221
|
+
return false unless self.class.where(id: id).where.not(status: %w[void requested]).update_all(updates) == 1
|
|
222
|
+
|
|
223
|
+
assign_attributes(updates.except(:updated_at))
|
|
224
|
+
clear_attribute_changes(%i[status])
|
|
225
|
+
publish_event('payment.void_requested')
|
|
226
|
+
true
|
|
227
|
+
end
|
|
228
|
+
|
|
208
229
|
def failure!
|
|
209
230
|
update!(status: 'failed')
|
|
210
231
|
end
|
|
@@ -238,15 +259,28 @@ module Spree
|
|
|
238
259
|
(!payment_method.respond_to?(:can_capture?) || payment_method.can_capture?(self))
|
|
239
260
|
end
|
|
240
261
|
|
|
241
|
-
#
|
|
262
|
+
# What the provider is still answering for a `requested` payment: a capture
|
|
263
|
+
# leaves a capture event waiting, a void leaves none.
|
|
264
|
+
#
|
|
265
|
+
# @return [String, nil] 'capture', 'void', or nil when nothing is requested
|
|
266
|
+
def requested_action
|
|
267
|
+
return unless requested?
|
|
268
|
+
|
|
269
|
+
# Read off the loaded rows when a list preloaded them, so serializing one
|
|
270
|
+
# costs no query per payment.
|
|
271
|
+
waiting = capture_events.loaded? ? capture_events.any?(&:requested?) : capture_events.requested.exists?
|
|
272
|
+
waiting ? 'capture' : 'void'
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# @deprecated read +status+ — removed in 6.3
|
|
242
276
|
def state
|
|
243
|
-
Spree::Deprecation.warn('Spree::Payment#state is deprecated and will be removed in Spree 6.
|
|
277
|
+
Spree::Deprecation.warn('Spree::Payment#state is deprecated and will be removed in Spree 6.3. Use #status instead.')
|
|
244
278
|
status
|
|
245
279
|
end
|
|
246
280
|
|
|
247
|
-
# @deprecated write +status+ — removed in 6.
|
|
281
|
+
# @deprecated write +status+ — removed in 6.3
|
|
248
282
|
def state=(value)
|
|
249
|
-
Spree::Deprecation.warn('Spree::Payment#state= is deprecated and will be removed in Spree 6.
|
|
283
|
+
Spree::Deprecation.warn('Spree::Payment#state= is deprecated and will be removed in Spree 6.3. Use #status= instead.')
|
|
250
284
|
self.status = value
|
|
251
285
|
end
|
|
252
286
|
|
|
@@ -286,12 +320,58 @@ module Spree
|
|
|
286
320
|
create_eligible_credit_event
|
|
287
321
|
end
|
|
288
322
|
|
|
323
|
+
# Statuses a payment can be resized from: nobody has claimed it for the
|
|
324
|
+
# gateway yet, and it has not settled.
|
|
325
|
+
RESIZABLE_STATUSES = %w[checkout pending failed].freeze
|
|
326
|
+
|
|
327
|
+
# Shrinks this payment to +new_amount+ while nobody has claimed it. One
|
|
328
|
+
# conditional UPDATE, so a payment another run is charging (processing)
|
|
329
|
+
# or one that settled since the caller read it keeps the amount the
|
|
330
|
+
# gateway sees. An unsaved payment is resized in memory and saved with
|
|
331
|
+
# its claim. Store credit gets an eligibility event for the new amount,
|
|
332
|
+
# as {#update_store_credit_amount!} records one.
|
|
333
|
+
#
|
|
334
|
+
# @param new_amount [BigDecimal]
|
|
335
|
+
# @return [Boolean] false when the payment was claimed or completed meanwhile
|
|
336
|
+
def resize_if_unclaimed!(new_amount)
|
|
337
|
+
if new_record?
|
|
338
|
+
self.amount = new_amount
|
|
339
|
+
return true
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
resized = self.class.unscoped.where(id: id, status: RESIZABLE_STATUSES).
|
|
343
|
+
update_all(amount: new_amount, updated_at: Time.current)
|
|
344
|
+
return false if resized.zero?
|
|
345
|
+
|
|
346
|
+
self.amount = new_amount
|
|
347
|
+
clear_attribute_changes(%i[amount])
|
|
348
|
+
create_eligible_credit_event if store_credit?
|
|
349
|
+
true
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
# Voids this payment while nobody has claimed it. One conditional UPDATE,
|
|
353
|
+
# so a payment another run is charging (processing) is not overwritten
|
|
354
|
+
# and its capture can still be recorded. The caller publishes
|
|
355
|
+
# payment.voided, outside any lock it holds.
|
|
356
|
+
#
|
|
357
|
+
# @return [Boolean] false when the payment was claimed or settled meanwhile
|
|
358
|
+
def void_if_unclaimed!
|
|
359
|
+
voided = self.class.unscoped.where(id: id, status: RESIZABLE_STATUSES).
|
|
360
|
+
update_all(status: 'void', updated_at: Time.current)
|
|
361
|
+
return false if voided.zero?
|
|
362
|
+
|
|
363
|
+
self.status = 'void'
|
|
364
|
+
clear_attribute_changes(%i[status])
|
|
365
|
+
true
|
|
366
|
+
end
|
|
367
|
+
|
|
289
368
|
def offsets_total
|
|
290
369
|
offsets.sum(:amount)
|
|
291
370
|
end
|
|
292
371
|
|
|
372
|
+
# A requested refund keeps its amount reserved until the provider answers.
|
|
293
373
|
def credit_allowed
|
|
294
|
-
amount - (offsets_total.abs + refunds.sum(:amount))
|
|
374
|
+
amount - (offsets_total.abs + refunds.not_failed.sum(:amount))
|
|
295
375
|
end
|
|
296
376
|
|
|
297
377
|
def can_credit?
|
|
@@ -366,29 +446,95 @@ module Spree
|
|
|
366
446
|
end
|
|
367
447
|
|
|
368
448
|
def captured_amount
|
|
369
|
-
capture_events.sum(:amount)
|
|
449
|
+
capture_events.completed_or_unset.sum(:amount)
|
|
370
450
|
end
|
|
371
451
|
|
|
372
452
|
def uncaptured_amount
|
|
373
453
|
amount - captured_amount
|
|
374
454
|
end
|
|
375
455
|
|
|
456
|
+
# What the order still owes besides this payment: its total less what its
|
|
457
|
+
# other payments captured and, with +including_in_flight+, what they hold
|
|
458
|
+
# authorized. An order can carry several live payments, so this is the
|
|
459
|
+
# most any one of them may take. Read from the payment rows rather than
|
|
460
|
+
# the order's cached totals, which trail the payments settling.
|
|
461
|
+
#
|
|
462
|
+
# @param including_in_flight [Boolean] also count other pending and
|
|
463
|
+
# processing payments
|
|
464
|
+
# @param including_processing [Boolean] also count other processing
|
|
465
|
+
# payments — the ones being charged at the gateway right now
|
|
466
|
+
# @return [BigDecimal, nil] nil for a payment not made against an order
|
|
467
|
+
def amount_owed_by_order(including_in_flight:, including_processing: false)
|
|
468
|
+
return if order_id.nil?
|
|
469
|
+
|
|
470
|
+
fresh_order = Spree::Order.find(order_id)
|
|
471
|
+
return BigDecimal('0') if fresh_order.canceled?
|
|
472
|
+
|
|
473
|
+
others = fresh_order.payments.where.not(id: id)
|
|
474
|
+
by_status, awaiting = sibling_amounts(others)
|
|
475
|
+
captured = others.where(status: 'completed')
|
|
476
|
+
owed = fresh_order.total - by_status.fetch('completed', 0) - awaiting +
|
|
477
|
+
Spree::Refund.where(payment_id: captured.select(:id)).sum(:amount) - fresh_order.returned_items_refund_total
|
|
478
|
+
if including_in_flight
|
|
479
|
+
owed -= by_status.fetch('pending', 0) + by_status.fetch('processing', 0)
|
|
480
|
+
elsif including_processing
|
|
481
|
+
owed -= by_status.fetch('processing', 0)
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
[owed, BigDecimal('0')].max
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
# Sizes a remainder split off a partial capture to what its order still
|
|
488
|
+
# owes beyond its other live payments: voids it when nothing is, so the
|
|
489
|
+
# hold on the customer's money is released, and shrinks it when less is.
|
|
490
|
+
#
|
|
491
|
+
# Read and resized under the order's lock, which a capture holds while it
|
|
492
|
+
# moves a sibling from processing to requested and a dispatch holds while
|
|
493
|
+
# it claims a payment: the owed figure cannot count a sibling twice, and a
|
|
494
|
+
# remainder another run claimed meanwhile keeps the amount it was claimed at.
|
|
495
|
+
#
|
|
496
|
+
# @return [Boolean] whether the remainder still needs authorizing
|
|
497
|
+
def trim_remainder_to_amount_owed!
|
|
498
|
+
voided = false
|
|
499
|
+
outcome = with_order_lock do
|
|
500
|
+
owed = amount_owed_by_order(including_in_flight: true)
|
|
501
|
+
if owed&.zero?
|
|
502
|
+
voided = void_if_unclaimed!
|
|
503
|
+
next :released
|
|
504
|
+
end
|
|
505
|
+
next :authorize if owed.nil? || owed >= amount || resize_if_unclaimed!(owed)
|
|
506
|
+
|
|
507
|
+
:claimed
|
|
508
|
+
end
|
|
509
|
+
publish_event('payment.voided') if voided
|
|
510
|
+
outcome == :authorize
|
|
511
|
+
end
|
|
512
|
+
|
|
376
513
|
# Row work only — moves the uncaptured remainder onto a new pending
|
|
377
514
|
# payment and shrinks this one to what was captured. The caller authorizes
|
|
378
515
|
# the returned remainder at the gateway afterwards, outside any lock.
|
|
379
516
|
#
|
|
380
|
-
# @return [Spree::Payment, nil] the remainder payment, or nil when fully
|
|
517
|
+
# @return [Spree::Payment, nil] the remainder payment, or nil when fully
|
|
518
|
+
# captured or when the order can take no more
|
|
381
519
|
def split_uncaptured_amount
|
|
382
520
|
return if uncaptured_amount <= 0
|
|
383
521
|
|
|
384
|
-
remainder = owner.payments.
|
|
522
|
+
remainder = owner.payments.new(
|
|
385
523
|
amount: uncaptured_amount,
|
|
386
524
|
payment_method: payment_method,
|
|
387
525
|
source: source,
|
|
388
526
|
status: 'pending',
|
|
389
527
|
capture_on_dispatch: true
|
|
390
528
|
)
|
|
391
|
-
|
|
529
|
+
# The order may now take less than the authorization left over, when its
|
|
530
|
+
# total came down after the payment was authorized.
|
|
531
|
+
remainder.amount = [remainder.amount, remainder.max_amount].min unless grouped?
|
|
532
|
+
if remainder.amount.positive?
|
|
533
|
+
remainder.save!
|
|
534
|
+
carry_splits_to(remainder)
|
|
535
|
+
else
|
|
536
|
+
remainder = nil
|
|
537
|
+
end
|
|
392
538
|
# Bang: a silent failure here would leave this payment at its full amount
|
|
393
539
|
# beside a remainder that also exists, so the group would hold more money
|
|
394
540
|
# than the customer was ever charged.
|
|
@@ -464,9 +610,9 @@ module Spree
|
|
|
464
610
|
INVALID_STATUSES.include?(status)
|
|
465
611
|
end
|
|
466
612
|
|
|
467
|
-
# @deprecated use {#has_invalid_status?} — removed in 6.
|
|
613
|
+
# @deprecated use {#has_invalid_status?} — removed in 6.3
|
|
468
614
|
def has_invalid_state?
|
|
469
|
-
Spree::Deprecation.warn('Spree::Payment#has_invalid_state? is deprecated and will be removed in Spree 6.
|
|
615
|
+
Spree::Deprecation.warn('Spree::Payment#has_invalid_state? is deprecated and will be removed in Spree 6.3. Use #has_invalid_status? instead.')
|
|
470
616
|
has_invalid_status?
|
|
471
617
|
end
|
|
472
618
|
|
|
@@ -544,6 +690,34 @@ module Spree
|
|
|
544
690
|
self.amount = owner.total - owner.payment_total
|
|
545
691
|
end
|
|
546
692
|
|
|
693
|
+
# One statement for every sum, so a sibling moving between statuses
|
|
694
|
+
# between two reads is counted once: not dropped from both the completed
|
|
695
|
+
# and the in-flight sums, nor counted both as in flight (processing) and
|
|
696
|
+
# as awaiting its provider (requested).
|
|
697
|
+
#
|
|
698
|
+
# @return [Array(Hash{String => BigDecimal}, BigDecimal)] the amounts by
|
|
699
|
+
# status, and the captures sent to a provider that confirms them by
|
|
700
|
+
# webhook, which count as collected already
|
|
701
|
+
def sibling_amounts(others)
|
|
702
|
+
events = Spree::PaymentCaptureEvent.arel_table
|
|
703
|
+
awaiting_sql = events.project(events[:amount].sum).
|
|
704
|
+
where(events[:payment_id].eq(Spree::Payment.arel_table[:id]).and(events[:status].eq('requested')))
|
|
705
|
+
rows = others.where(status: %w[completed pending processing requested]).
|
|
706
|
+
pluck(:status, :amount, Arel::Nodes::Grouping.new(awaiting_sql))
|
|
707
|
+
|
|
708
|
+
by_status = Hash.new(BigDecimal('0'))
|
|
709
|
+
awaiting = BigDecimal('0')
|
|
710
|
+
rows.each do |status, amount, requested|
|
|
711
|
+
by_status[status] += amount unless status == 'requested'
|
|
712
|
+
awaiting += BigDecimal(requested.to_s) if requested
|
|
713
|
+
end
|
|
714
|
+
[by_status, awaiting]
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
def with_order_lock(&)
|
|
718
|
+
order_id ? Spree::Order.find(order_id).with_lock(&) : yield
|
|
719
|
+
end
|
|
720
|
+
|
|
547
721
|
def amount_must_be_less_than_or_equal_to_max_amount
|
|
548
722
|
errors.add(:amount, :greater_than_max_amount, max_amount: max_amount) if amount > max_amount
|
|
549
723
|
end
|
|
@@ -603,9 +777,14 @@ module Spree
|
|
|
603
777
|
action_authorization_code: response_code)
|
|
604
778
|
end
|
|
605
779
|
|
|
780
|
+
# A buyer who picks another way to pay at checkout replaces the attempt
|
|
781
|
+
# they started, so a cart keeps one live payment. An order is paid from
|
|
782
|
+
# the back office, where each payment recorded is money the merchant
|
|
783
|
+
# means to collect alongside the others.
|
|
606
784
|
def invalidate_old_payments
|
|
607
785
|
# invalid payment or store_credit payment shouldn't invalidate other payment types
|
|
608
786
|
return if has_invalid_status? || store_credit?
|
|
787
|
+
return unless owner.is_a?(Spree::Cart)
|
|
609
788
|
|
|
610
789
|
owner.payments.with_state('checkout').where.not(id: id).each do |payment|
|
|
611
790
|
payment.invalidate! unless payment.store_credit?
|
|
@@ -86,6 +86,12 @@ module Spree
|
|
|
86
86
|
handle_action(action, :credit, auth_code)
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
+
# Cancelling gives the credit back, so the payment is void even when it
|
|
90
|
+
# was captured.
|
|
91
|
+
def cancel_voids?(_payment)
|
|
92
|
+
true
|
|
93
|
+
end
|
|
94
|
+
|
|
89
95
|
# Credit goes back to the customer's balance rather than a card, so this
|
|
90
96
|
# is a release rather than a refund and `refund:` does not apply.
|
|
91
97
|
def cancel(auth_code, _payment = nil, refund: true)
|