Module: CoreMerchant::Concerns::SubscriptionStateMachine

Extended by:
ActiveSupport::Concern
Included in:
Subscription
Defined in:
lib/core_merchant/concerns/subscription_state_machine.rb

Overview

Adds state machine logic to a subscription. This module defines the possible states and transitions for a subscription. Possible transitions:

  • ‘pending` -> `active`, `trial`, `processing_renewal`

  • ‘trial` -> `processing_renewal`, `active`, `canceled`, `pending_cancellation`, `expired`

  • ‘active` -> `pending_cancellation`, `canceled`, `expired`, `processing_renewal`

  • ‘past_due` -> `processing_renewal`

  • ‘pending_cancellation` -> `canceled`, `expired`

  • ‘processing_renewal` -> `processing_payment`, `active`, `expired`, `past_due`

  • ‘processing_payment` -> `active`, `expired`, `canceled`, `past_due`

  • ‘canceled` -> `pending`, `processing_renewal`

  • ‘expired` -> `pending`, `processing_renewal`

Constant Summary collapse

POSSIBLE_TRANSITIONS =

List of possible transitions in the form of { to_state: [from_states] }

{
  pending: %i[canceled expired],
  trial: [:pending],
  active: %i[pending trial processing_renewal processing_payment],
  past_due: %i[active processing_renewal processing_payment],
  pending_cancellation: %i[active trial],
  processing_renewal: %i[pending trial active past_due canceled expired],
  processing_payment: [:processing_renewal],
  canceled: %i[trial active pending_cancellation processing_payment],
  expired: %i[trial active pending_cancellation processing_renewal processing_payment]
}.freeze