Module: ODDB::Html::State::PayPal::Checkout

Includes:
LoginMethods, Download
Included in:
Global
Defined in:
lib/oddb/html/state/paypal/checkout.rb

Instance Attribute Summary

Attributes included from LoginMethods

#desired_input

Instance Method Summary collapse

Methods included from Download

#collect

Methods included from Util::Download

compressed_download, #compressed_download

Methods included from LoginMethods

#login_

Instance Method Details

#ajax_autofillObject



25
26
27
28
29
30
31
32
33
# File 'lib/oddb/html/state/paypal/checkout.rb', line 25

def ajax_autofill
  email = @session.user_input(:email)
  prefs = {}
  keys = checkout_keys()
  keys.delete(:email)
  prefs.update ODDB::Util::Yus.get_preferences(email, keys)
  prefs.store(:email, email) unless prefs.empty?
  AjaxCheckout.new(@session, prefs)
end

#checkoutObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/oddb/html/state/paypal/checkout.rb', line 34

def checkout
  ## its possible that we know this user already -> log them in.
  missing_keys = [:email, :pass] - @session.input_keys
  if(@session.logged_in?)
    @user = @session.user
  elsif(missing_keys.empty?)
    begin
      @user ||= @session.
      reconsider_permissions(@user)
      @session.(@user)
    rescue Yus::UnknownEntityError 
      # ignore: in this case we simply create a new user in 'create_user'
    rescue Yus::AuthenticationError
      @errors.store(:pass, create_error(:e_authentication_error, :pass, nil))
    end
  end
  input = user_input(checkout_keys(), checkout_mandatory())
  if(error?)
    self
  else
    create_user(input)
    @model.yus_name = @user.name
    @model.save
    State::PayPal::Redirect.new(@session, @model)
  end
rescue SBSM::ProcessingError => err
  @errors.store(err.key, err)
  self
end

#checkout_keysObject



70
71
72
# File 'lib/oddb/html/state/paypal/checkout.rb', line 70

def checkout_keys
  checkout_mandatory()
end

#checkout_mandatoryObject



63
64
65
66
67
68
69
# File 'lib/oddb/html/state/paypal/checkout.rb', line 63

def checkout_mandatory
  keys = [ :salutation, :name_last, :name_first, ]
  unless(@session.logged_in?)
    keys.push(:email, :pass, :confirm_pass)
  end
  keys
end

#create_user(input) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/oddb/html/state/paypal/checkout.rb', line 73

def create_user(input)
  hash = input.dup 
  ## don't store passwords in cookie vars...
  hash.delete(:confirm_pass)
  pass = hash.delete(:pass)
  ## but store the rest of the input there
  hash.each { |key, val| @session.set_cookie_input(key, val) }
  email = hash.delete(:email)
  unless(@user.is_a?(Util::KnownUser))
    @user = ODDB::Util::Yus.create_user(email, pass)
  end
  hash.delete_if { |key, value| value.to_s.empty? }
  @user.set_preferences(hash) unless(hash.empty?)
  reconsider_permissions(@user)
  @session.(@user)
rescue Yus::DuplicateNameError => e
  raise create_error(:e_duplicate_email, :email, input[:email])
rescue RuntimeError, Yus::YusError => e
  raise create_error(e.message, :email, input[:email])
end