Class: RubyOmx::UDOARequest

Inherits:
Request show all
Defined in:
lib/ruby_omx/request/udoa_request.rb

Instance Attribute Summary collapse

Attributes inherited from Request

#raw_xml

Instance Method Summary collapse

Methods inherited from Response

format, parse_xml

Methods inherited from Node

#accessors, #as_hash

Constructor Details

#initialize(attrs = {}) ⇒ UDOARequest

Returns a new instance of UDOARequest.



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
# File 'lib/ruby_omx/request/udoa_request.rb', line 17

def initialize(attrs={})
  return super unless attrs.any?

required_fields = [:queue_flag, :verify_flag, :keycode, :order_date, :order_id, :bill_to, :line_items, :method_code]
raise MissingRequestOptions if required_fields.any? { |option| attrs[option].nil? }
  super
  self.version = attrs[:version] ||= '2.00'
  self.payment_type = attrs[:payment_type] ||= '6'  #6 for open invoice
  self.origin_type = attrs[:origin_type] ||= '2'    # 2 = phone order, 3 = internet order      
  self.udi_parameters << UDIParameter.new({:key=>'Keycode', :value=>attrs[:keycode]})
  self.udi_parameters << UDIParameter.new({:key=>'VerifyFlag', :value=>attrs[:verify_flag] ||= 'True' }) # Determines whether a successful order should be saved, or only verified/calculated. When set to "True", OrderMotion will behave as if the order was placed, but not return an Order Number in the response.
  self.udi_parameters << UDIParameter.new({:key=>'QueueFlag', :value=>attrs[:queue_flag] ||= 'False' })  # Determines whether any orders with errors will be stored in the OrderMotion "Outside Order Queue",  to be corrected by an OrderMotion user before resubmission. If set to "True", almost all orders will be   accepted by OrderMotion, but additional order information will only be returned in the response if the order   is successfully placed. Otherwise, any order with any error (eg invalid ZIP code) will be rejected.
  self.udi_parameters << UDIParameter.new({:key=>'Vendor', :value=>attrs[:vendor] }) if attrs[:vendor].present? 
  self.bill_to = Address.new(attrs[:bill_to])
  self.ship_to = Address.new(attrs[:ship_to])
  
  # Instantiate LineItem variables for each
  i = 0
  self.line_items = attrs[:line_items].collect { |h|
    i+=1
    h[:line_number] = h[:line_number] ||= i  # Provide line numbers if they are omitted
    LineItem.new(h)
  }
    
  self.custom_fields = attrs[:custom_fields].collect { |h| CustomField.new(h) } if attrs[:custom_fields].present?
  self.flags = attrs[:flags].collect { |h| Flag.new(h) } if attrs[:flags].present?
end

Instance Attribute Details

#keycodeObject

Returns the value of attribute keycode.



45
46
47
# File 'lib/ruby_omx/request/udoa_request.rb', line 45

def keycode
  @keycode
end

#queue_flagObject

Returns the value of attribute queue_flag.



45
46
47
# File 'lib/ruby_omx/request/udoa_request.rb', line 45

def queue_flag
  @queue_flag
end

#vendorObject

Returns the value of attribute vendor.



45
46
47
# File 'lib/ruby_omx/request/udoa_request.rb', line 45

def vendor
  @vendor
end

#verify_flagObject

Returns the value of attribute verify_flag.



45
46
47
# File 'lib/ruby_omx/request/udoa_request.rb', line 45

def verify_flag
  @verify_flag
end