diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/generators/solidus_subscriptions/install/templates/initializer.rb | 7 | ||||
-rw-r--r-- | lib/solidus_subscriptions/configuration.rb | 2 | ||||
-rw-r--r-- | lib/solidus_subscriptions/processor.rb | 6 |
3 files changed, 14 insertions, 1 deletions
diff --git a/lib/generators/solidus_subscriptions/install/templates/initializer.rb b/lib/generators/solidus_subscriptions/install/templates/initializer.rb index 150f439..a346412 100644 --- a/lib/generators/solidus_subscriptions/install/templates/initializer.rb +++ b/lib/generators/solidus_subscriptions/install/templates/initializer.rb @@ -82,4 +82,11 @@ SolidusSubscriptions.configure do |config| # Your Churn Buster API key. # config.churn_buster_api_key = 'YOUR_CHURN_BUSTER_API_KEY' + + # =================================== Clear past installments ==================================== + # + # This setting prevents the overlap of old failed installments (e.g. for an expired credit card) + # with new subscription cycles by clearing any past failed installment when a new one is created + + # config.clear_past_installments = true end diff --git a/lib/solidus_subscriptions/configuration.rb b/lib/solidus_subscriptions/configuration.rb index 9cf1408..13254be 100644 --- a/lib/solidus_subscriptions/configuration.rb +++ b/lib/solidus_subscriptions/configuration.rb @@ -4,7 +4,7 @@ module SolidusSubscriptions class Configuration attr_accessor( :maximum_total_skips, :maximum_reprocessing_attempts, :churn_buster_account_id, - :churn_buster_api_key, + :churn_buster_api_key, :clear_past_installments, ) attr_writer( diff --git a/lib/solidus_subscriptions/processor.rb b/lib/solidus_subscriptions/processor.rb index 817d957..4946b5a 100644 --- a/lib/solidus_subscriptions/processor.rb +++ b/lib/solidus_subscriptions/processor.rb @@ -98,6 +98,12 @@ module SolidusSubscriptions sub.advance_actionable_date sub.cancel! if sub.pending_cancellation? sub.deactivate! if sub.can_be_deactivated? + if SolidusSubscriptions.configuration.clear_past_installments + sub.installments.unfulfilled.each do |installment| + installment.actionable_date = nil + installment.save! + end + end sub.installments.create! end end |