summaryrefslogtreecommitdiff
path: root/app/jobs/solidus_subscriptions/process_installments_job.rb
blob: 6048ee640212eef64a8f119137b2510fe6c3eb4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# This job is responsible for creating a consolidated installment from a
# list of installments and processing it.

module SolidusSubscriptions
  class ProcessInstallmentsJob < ActiveJob::Base
     queue_as SolidusSubscriptions.configuration.processing_queue

     # Process a collection of installments
     #
     # @param installment_ids [Array<Integer>] The ids of the
     #   installments to be processed together and fulfilled by the same order
     #
     # @return [Spree::Order] The order which fulfills the list of installments
     def perform(installment_ids)
       return if installment_ids.empty?

       installments = SolidusSubscriptions::Installment.where(id: installment_ids).
         includes(subscription: [:line_items, :user])
       Checkout.new(installments).process
     end
  end
end