Class: SpreeCmCommissioner::TicketTransfers::EligibilityChecker

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/ticket_transfers/eligibility_checker.rb

Instance Method Summary collapse

Instance Method Details

#call(from_guest:, rule:, transfer_type:, price: nil) ⇒ Object



6
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/services/spree_cm_commissioner/ticket_transfers/eligibility_checker.rb', line 6

def call(from_guest:, rule:, transfer_type:, price: nil)
  return failure(nil, I18n.t('ticket_transfer.guest_not_found')) if from_guest.blank?

  # If no rule is found, allow the transfer (free transfer with no policy checks)
  return success(from_guest: from_guest) if rule.nil?

  if (error = check_cooldown(from_guest, rule)) # rubocop:disable Lint/AssignmentInCondition
    return failure(nil, error)
  end

  if (error = check_chain_length(from_guest, rule)) # rubocop:disable Lint/AssignmentInCondition
    return failure(nil, error)
  end

  if (error = check_event_cutoff(from_guest, rule)) # rubocop:disable Lint/AssignmentInCondition
    return failure(nil, error)
  end

  if (error = check_price_range(from_guest, rule, price, transfer_type)) # rubocop:disable Lint/AssignmentInCondition
    return failure(nil, error)
  end

  success(from_guest: from_guest)
end