Module: ODDB::Util::Ipn

Defined in:
lib/oddb/util/ipn.rb

Class Method Summary collapse

Class Method Details

.process(notification) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/oddb/util/ipn.rb', line 12

def Ipn.process(notification)
  id = notification.params["invoice"]
  invoice = Business::Invoice.find_by_id(id) or raise "unknown invoice '#{id}'"
  invoice.status = notification.status.to_s.downcase
  if(notification.complete?)
    Ipn.process_invoice(invoice)
  else
    invoice.ipn = notification
  end
  invoice.save
  invoice
end

.process_invoice(invoice) ⇒ Object



24
25
26
27
28
# File 'lib/oddb/util/ipn.rb', line 24

def Ipn.process_invoice(invoice)
  invoice.items.each { |item| Ipn.process_item invoice, item }
  Ydim.inject(invoice, :payment_received => true)
  Mail.notify_invoice(invoice)
end

.process_item(invoice, item) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oddb/util/ipn.rb', line 29

def Ipn.process_item(invoice, item)
  case item.type
  when :poweruser
    yus_name = invoice.yus_name
    item.expiry_time = Time.now + (60 * 60 * 24 * item.quantity)
    Util::Yus.set_preference(yus_name, 'poweruser_duration', item.quantity)
    Util::Yus.grant(yus_name, 'login', "#{ODDB.config.auth_domain}.PowerUser")
    Util::Yus.grant(yus_name, 'view', ODDB.config.auth_domain, item.expiry_time)
  when :export
    yus_name = invoice.yus_name
    item.expiry_time = Time.now + (60 * 60 * 24)
    Util::Yus.grant(yus_name, 'login', "#{ODDB.config.auth_domain}.PowerUser")
    Util::Yus.grant(yus_name, 'download',
                    "#{ODDB.config.auth_domain}.#{item.text}",
                    item.expiry_time)
  end
end