Module: ODDB::Html::State::PayPal::Download

Includes:
Util::Download
Included in:
Checkout, Collect
Defined in:
lib/oddb/html/state/paypal/download.rb

Instance Method Summary collapse

Methods included from Util::Download

compressed_download, #compressed_download

Instance Method Details

#collectObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/oddb/html/state/paypal/download.rb', line 9

def collect
  if(@session.is_crawler?)
    trigger :home
  else
    invoice = Business::Invoice.find_by_id(@session.user_input(:invoice))
    state = PayPal::Collect.new(@session, invoice)
    # since the permissions of the current User may have changed, we
    # need to reconsider his viral modules
    if((user = @session.user).is_a?(Util::KnownUser))
      reconsider_permissions(user)
    end
    if invoice
      downloads = invoice.items.select do |itm| itm.type == :download end
      file, item = nil
      if file = @session.user_input(:file)
        uncompressed = if ODDB.config.download_uncompressed.include?(file)
                         file
                       else
                         File.basename file, File.extname(file)
                       end
        item = invoice.items.find do |itm| itm.text == uncompressed end
      end
      if item || downloads.size <= 1
        ## just pass through to the download/desired_state directly.
        item ||= invoice.items.first
        case item.type
        when :export, :download
          if @session.allowed?('download', "#{ODDB.config.auth_domain}.#{item.text}") \
            || (invoice.status == 'completed' && !item.expired?)
            extend State::Drugs::Events
            state = _download file || compressed_download(item)
          else
            ## wait for ipn
          end
        else
          if(@session.allowed?('view', ODDB.config.auth_domain))
            if(des = @session.desired_state)
              state = des
            else
              state.extend Drugs::Events
            end
          end
        end
      end
    end
    state
  end
end