7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/jobs/solidus_subscriptions/process_subscription_job.rb', line 7
def perform(subscription)
ActiveRecord::Base.transaction do
if SolidusSubscriptions.configuration.clear_past_installments
subscription.installments.unfulfilled.actionable.each do |installment|
installment.update!(actionable_date: nil)
end
end
if subscription.actionable?
subscription.successive_skip_count = 0
subscription.advance_actionable_date
subscription.installments.create!(actionable_date: Time.zone.now)
end
subscription.cancel! if subscription.pending_cancellation?
subscription.deactivate! if subscription.can_be_deactivated?
subscription.installments.actionable.find_each do |installment|
SolidusSubscriptions::ProcessInstallmentJob.perform_later(installment)
end
end
end
|