class SBF::Client::Donation

Public Class Methods

generate_special_donation_type(entity) click to toggle source
# File lib/stbaldricks/entities/donation.rb, line 213
def self.generate_special_donation_type(entity)
  return if entity.nil?

  # Calculate the country and state
  country, state = get_country_and_state_for_special_donation_type(entity)

  # state only applicable for United States, others only use international value
  unless country.empty?
    if country.to_sym == SBF::Client::Country.list[SBF::Client::Country::UNITED_STATES]
      state_value = state.to_s.upcase.to_sym
      if !state_value.empty? && SBF::Client::Donation::SpecialDonationType.const_defined?(state_value)
        return SBF::Client::Donation::SpecialDonationType.const_get(state_value)
      end

      return SBF::Client::Donation::SpecialDonationType::NO_STATE
    else
      international_value = "INT_#{country}".upcase.to_sym
      if SBF::Client::Donation::SpecialDonationType.const_defined?(international_value)
        return SBF::Client::Donation::SpecialDonationType.const_get(international_value)
      end

      return SBF::Client::Donation::SpecialDonationType::INTERNATIONAL
    end
  end

  SBF::Client::Donation::SpecialDonationType::GENERAL_EVENT
end

Private Class Methods

get_country_and_state_for_special_donation_type(entity) click to toggle source
# File lib/stbaldricks/entities/donation.rb, line 241
def self.get_country_and_state_for_special_donation_type(entity)
  case entity
  when SBF::Client::Search::Participant, SBF::Client::Search::Fundraiser, SBF::Client::Search::Team, SBF::Client::Search::Event
    if entity.event_id == 1
      # Look up the person since it is a Search::Participant and doesn't have sub-objects
      response = SBF::Client::Person.get(entity.profile_id)
      person = response.data
      raise SBF::Client::Error, 'Invalid Entity' if response.error? || person.nil?

      # Get country and state from the person
      country = person.addresses.primary.country
      state = (country.to_sym == SBF::Client::Country.list[SBF::Client::Country::UNITED_STATES] ? person.addresses.primary.state : '')

    else
      country = (defined?(entity.country).nil? ? nil : entity.country)
      state = (defined?(entity.state).nil? ? nil : entity.state)

    end

    [country, state]

  when SBF::Client::Participant
    get_event_country_and_state_for_special_donation_type(entity.event, entity.person)

  when SBF::Client::Fundraiser
    [entity.venue.location.address.country, entity.venue.location.address.state]

  when SBF::Client::Team
    get_event_country_and_state_for_special_donation_type(entity.event)

  when SBF::Client::Event
    get_event_country_and_state_for_special_donation_type(entity)

  end
end
get_event_country_and_state_for_special_donation_type(event, person = nil) click to toggle source
# File lib/stbaldricks/entities/donation.rb, line 278
def self.get_event_country_and_state_for_special_donation_type(event, person = nil)
  if event.virtual?
    raise SBF::Client::Error, 'Invalid Entity' if person.nil?

    # Get country and state from the person
    country = person.addresses.primary.country
    state = (country.to_sym == SBF::Client::Country.list[SBF::Client::Country::UNITED_STATES] ? person.addresses.primary.state : '')

  else
    country = (defined?(event.venue.location.address.country).nil? ? nil : event.venue.location.address.country)
    state = (defined?(event.venue.location.address.state).nil? ? nil : event.venue.location.address.state)

  end

  [country, state]
end