Sha256: 99996a3abf744ee4ec9dc20963b6fe37e743b39708cb085690dad22d4cf576de

Contents?: true

Size: 1.05 KB

Versions: 32

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

namespace :order_capturing do
  desc "Looks for orders with inventory that is fully shipped/short-shipped, and captures money for it"
  task capture_payments: :environment do
    Spree::Deprecation.warn("rake order_capturing:capture_payments has been deprecated and will be removed with Solidus 3.0.")

    failures = []
    orders = Spree::Order.complete.where(payment_state: 'balance_due').where('completed_at > ?', Spree::Config[:order_capturing_time_window].days.ago)

    orders.find_each do |order|
      if order.inventory_units.all? { |iu| iu.canceled? || iu.shipped? }
        if Spree::OrderCapturing.failure_handler
          begin
            Spree::OrderCapturing.new(order).capture_payments
          rescue StandardError => e
            failures << { message: "Order #{order.number} unable to capture. #{e.class}: #{e.message}" }
          end
        else
          Spree::OrderCapturing.new(order).capture_payments
        end
      end
    end

    Spree::OrderCapturing.failure_handler.call(failures) if failures.any?
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
solidus_core-2.11.17 lib/tasks/order_capturing.rake
solidus_core-2.11.16 lib/tasks/order_capturing.rake
solidus_core-2.11.15 lib/tasks/order_capturing.rake
solidus_core-2.11.14 lib/tasks/order_capturing.rake
solidus_core-2.11.13 lib/tasks/order_capturing.rake
solidus_core-2.11.12 lib/tasks/order_capturing.rake
solidus_core-2.11.11 lib/tasks/order_capturing.rake
solidus_core-2.10.5 lib/tasks/order_capturing.rake
solidus_core-2.11.10 lib/tasks/order_capturing.rake
solidus_core-2.11.9 lib/tasks/order_capturing.rake
solidus_core-2.11.8 lib/tasks/order_capturing.rake
solidus_core-2.11.7 lib/tasks/order_capturing.rake
solidus_core-2.11.6 lib/tasks/order_capturing.rake
solidus_core-2.11.5 lib/tasks/order_capturing.rake
solidus_core-2.11.4 lib/tasks/order_capturing.rake
solidus_core-2.11.3 lib/tasks/order_capturing.rake
solidus_core-2.11.2 lib/tasks/order_capturing.rake
solidus_core-2.11.1 lib/tasks/order_capturing.rake
solidus_core-2.10.3 lib/tasks/order_capturing.rake
solidus_core-2.11.0 lib/tasks/order_capturing.rake