Class: OrderPayment

Inherits:
Object
  • Object
show all
Defined in:
lib/order_payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_nameObject

Returns the value of attribute default_name.



6
7
8
# File 'lib/order_payment.rb', line 6

def default_name
  @default_name
end

#last_reviewObject

Returns the value of attribute last_review.



8
9
10
# File 'lib/order_payment.rb', line 8

def last_review
  @last_review
end

#noteObject

Returns the value of attribute note.



7
8
9
# File 'lib/order_payment.rb', line 7

def note
  @note
end

#pageObject

Returns the value of attribute page.



9
10
11
# File 'lib/order_payment.rb', line 9

def page
  @page
end

Instance Method Details

#confirmObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/order_payment.rb', line 45

def confirm
  puts

  unless Ask.confirm "Place order?"
    puts "Stopped by user"
    return
  end

  Request.post("https://order.dominos.jp/eng/regi/insert", @insert_params,
               expect: :redirect, to: %r{\Ahttps://order\.dominos\.jp/eng/regi/complete/\?},
               failure: "Order couldn't be placed for some reason :(")

  puts
  puts "Success!"
  puts "Be sure to check the Domino's Pizza website in your browser "\
       "to track your order status via the Pizza Tracker, and win a Mystery Deal coupon"
end

#displayObject



41
42
43
# File 'lib/order_payment.rb', line 41

def display
  puts last_review
end

#inputObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/order_payment.rb', line 11

def input
  Request.get("https://order.dominos.jp/eng/regi/",
              expect: :ok, failure: "Couldn't get payment page")

  puts
  puts
  puts "#{"Payment information".colorize(:blue)} (you will be able to review your order later)"

  @credit_card = Preferences.instance.credit_card || CreditCard.new
  @credit_card.input(default_name)

  self.note = Preferences.instance.note ||
              Ask.input("Any special requests? (not food preparation requests)")
end

#validateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/order_payment.rb', line 26

def validate
  params = default_params.merge("bikoText" => note).merge(@credit_card.params)
  response = Request.post("https://order.dominos.jp/eng/regi/confirm", params,
                          expect: :ok, failure: "Couldn't submit payment information")
  doc = Nokogiri::HTML(response.body)

  token_input = doc.css("input[name='org.apache.struts.taglib.html.TOKEN']").first
  raise "Couldn't get token for order validation" unless token_input && token_input["value"]

  @insert_params = doc.css("input").map { |input| [input["name"], input["value"]] }.to_h

  self.last_review = OrderLastReview.new(doc)
  self.page = response.body
end