Class: Davidsons::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/davidsons/order.rb

Constant Summary collapse

TEST_URL =
'https://dealernetwork.davidsonsinc.com/testapi/orderservice.asmx?WSDL'
API_URL =
'https://dealernetwork.davidsonsinc.com/api/orderservice.asmx?WSDL'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Order

Returns a new instance of Order.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/davidsons/order.rb', line 12

def initialize(options = {})
  requires!(options, :token, :dealer_number)

  @options = options

  settings = {
    wsdl:          @options[:test] ? TEST_URL : API_URL,
    env_namespace: 'soap',
    proxy:         Davidsons.config.proxy_url
  }

  if @options[:test]
    settings[:log]              = true
    settings[:log_level]        = :debug
    settings[:pretty_print_xml] = true
  end

  @client = Savon.client(settings)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/davidsons/order.rb', line 10

def client
  @client
end

Instance Method Details

#create_order(items, partner_name, partner_phone, purchase_order_number, details = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/davidsons/order.rb', line 32

def create_order(items, partner_name, partner_phone, purchase_order_number, details = {})
  request = @client.call(:create_order, attributes: { xmlns: Davidsons.config.xmlns }, message: { ':request': {
    'Token'                => @options[:token],
    'DealerCustomerNumber' => @options[:dealer_number],
    'ConsumerName'         => partner_name,
    'ConsumerPhone'        => partner_phone,
    'ReferenceNumber'      => purchase_order_number,
    'Items'                => self.format_items(items),
    'UseExpeditedShipping' => 'false'
  }})

  order_info = request.body[:create_order_response][:create_order_result]

  if order_info[:response_code] == "0"
    { success: true, order_number: order_info[:order_number] }
  else
    { success: false, error_code: order_info[:response_code], error_message: order_info[:response_text] }
  end
end

#get_order_tracking(order_number) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/davidsons/order.rb', line 52

def get_order_tracking(order_number)
  request = @client.call(:get_order_tracking, attributes: { xmlns: Davidsons.config.xmlns }, message: { ':request': {
    'Token'   => @options[:token],
    'OrderNo' => order_number
  }})

  tracking_info = request.body[:get_order_tracking_response][:get_order_tracking_result]

  if tracking_info[:response_code] == "0"
    { success: true, tracking_number: tracking_info[:tracking_number] }
  else
    { success: false, error_code: tracking_info[:response_code], error_message: tracking_info[:response_text] }
  end
end