Module: ODDB::Html::State::PayPal::Checkout
Instance Attribute Summary
Attributes included from LoginMethods
Instance Method Summary collapse
- #ajax_autofill ⇒ Object
- #checkout ⇒ Object
- #checkout_keys ⇒ Object
- #checkout_mandatory ⇒ Object
- #collect ⇒ Object
- #create_user(input) ⇒ Object
Methods included from LoginMethods
Instance Method Details
#ajax_autofill ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/oddb/html/state/paypal/checkout.rb', line 23 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 |
#checkout ⇒ Object
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 57 58 59 60 |
# File 'lib/oddb/html/state/paypal/checkout.rb', line 32 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.login (@user) @session.force_login(@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_keys ⇒ Object
68 69 70 |
# File 'lib/oddb/html/state/paypal/checkout.rb', line 68 def checkout_keys checkout_mandatory() end |
#checkout_mandatory ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/oddb/html/state/paypal/checkout.rb', line 61 def checkout_mandatory keys = [ :salutation, :name_last, :name_first, ] unless(@session.logged_in?) keys.push(:email, :pass, :confirm_pass) end keys end |
#collect ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/oddb/html/state/paypal/checkout.rb', line 71 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)) (user) end if invoice item = invoice.items.first case item.type when :export if @session.allowed?('download', "#{ODDB.config.auth_domain}.#{item.text}") \ || invoice.status == 'completed' extend State::Drugs::Events state = _download item.text 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 state end end |
#create_user(input) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/oddb/html/state/paypal/checkout.rb', line 106 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.(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?) (@user) @session.force_login(@user) rescue Yus::DuplicateNameError => e raise create_error(:e_duplicate_email, :email, input[:email]) rescue RuntimeError, Yus::YusError => e raise create_error(e., :email, input[:email]) end |