-
-
Save pgr0ss/99ffd38dad5fe106f3fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Subscription < ActiveRecord::Base | |
before_save :_check_internal_consistency | |
def _check_internal_consistency | |
if billing_period_start_date && billing_period_start_date > billing_period_end_date | |
raise "Subscription internal state is inconsistent -- billing_period_start_date vs billing_period_end_date: #{inspect}" | |
end | |
case status | |
when Status::Active | |
if billing_period_start_date && _correct_next_billing_date != next_billing_date | |
raise "Subscription internal state is inconsistent -- next_billing_date incorrect: #{inspect}" | |
end | |
when Status::PastDue | |
if failure_count > MAX_RETRY_COUNT && _correct_next_billing_date != next_billing_date | |
raise "Subscription internal state is inconsistent -- next_billing_date for past due subscription over max retry count: #{inspect}" | |
end | |
end | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment