Class: Spree::MaintenanceTasks::Upgrade::CaptureMethods

Inherits:
Spree::MaintenanceTask show all
Defined in:
app/maintenance_tasks/spree/maintenance_tasks/upgrade/capture_methods.rb

Overview

5.6 → 6.0 conversion of the per-payment-method auto_capture boolean onto the capture_method vocabulary (docs/plans/6.0-store-scoped-configuration.md).

A method that captured on authorization charges at checkout. One that did not only recorded "not at checkout" — the old column could not say whether dispatch or staff was meant to take the money, and the store's own setting is what decided. Leaving those rows empty is what makes them keep inheriting it, so only the true case is written here, and the collection is the true case alone: any other scope would never reach zero remaining.

Constant Summary

Constants inherited from Spree::MaintenanceTask

Spree::MaintenanceTask::DEFAULT_BATCH_SIZE, Spree::MaintenanceTask::MAX_RUN_TIME, Spree::MaintenanceTask::RAKE_LOAD_LOCK

Instance Attribute Summary

Attributes inherited from Spree::MaintenanceTask

#run

Instance Method Summary collapse

Methods inherited from Spree::MaintenanceTask

api_type_for, collection_batch_size, #count, #dry_run?, find_by_api_type, find_registered, #invoke_rake_task, no_collection, #no_collection?, #rake_file_defining, registered_classes, supports_dry_run, #tallies, #tally

Methods included from ApiTyped

#api_type, api_type_for, #api_typed_family, class_name_for, find, registered_class

Instance Method Details

#after_complete ⇒ Object

Rows the conversion deliberately leaves alone, reported once so an operator can see they were considered rather than missed.



31
32
33
34
35
36
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/capture_methods.rb', line 31

def after_complete
  return if dry_run?

  inheriting = Spree::PaymentMethod.unscoped.where(capture_method: nil, auto_capture: false).count
  tally(:left_inheriting_store_setting, inheriting) if inheriting.positive?
end

#collection ⇒ Object



18
19
20
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/capture_methods.rb', line 18

def collection
  Spree::PaymentMethod.unscoped.where(capture_method: nil, auto_capture: true).order(:id)
end

#process(payment_method) ⇒ Object



22
23
24
25
26
27
# File 'app/maintenance_tasks/spree/maintenance_tasks/upgrade/capture_methods.rb', line 22

def process(payment_method)
  return tally(:would_convert) if dry_run?

  payment_method.update_columns(capture_method: 'checkout', updated_at: Time.current)
  tally(:converted)
end