Class: IngramMicro::SalesOrder

Inherits:
Transmission show all
Defined in:
lib/ingram_micro/transmissions/sales_order.rb

Constant Summary collapse

TRANSMISSION_FILENAME =
'sales-order-submission'

Constants inherited from Transmission

Transmission::XSD

Instance Attribute Summary collapse

Attributes inherited from Transmission

#errors, #transaction_name

Instance Method Summary collapse

Methods inherited from Transmission

#add_transaction_info, #order_builder, #schema_valid?, #send_request, #submit_request

Constructor Details

#initialize(options = {}) ⇒ SalesOrder

Returns a new instance of SalesOrder.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 8

def initialize(options={})
  super(options)
  @transaction_name = 'sales-order-submission'
  @customer = options[:customer]
  @sales_order_shipment_information = options[:sales_order_shipment_information]
  @credit_card_information = options[:credit_card_information]
  @sales_order_header = options[:sales_order_header]
  @detail = options[:detail]
  @business_name = options[:business_name]
  @customer_id = options[:customer_id]
  @carrier_name = options[:carrier_name]
  @purchase_order_information = options[:purchase_order_information]

  validate_options(options)
end

Instance Attribute Details

#business_nameObject

Returns the value of attribute business_name.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def business_name
  @business_name
end

#carrier_nameObject

Returns the value of attribute carrier_name.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def carrier_name
  @carrier_name
end

#credit_card_informationObject

Returns the value of attribute credit_card_information.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def credit_card_information
  @credit_card_information
end

#customerObject

Returns the value of attribute customer.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def customer
  @customer
end

#customer_idObject

Returns the value of attribute customer_id.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def customer_id
  @customer_id
end

#detailObject

Returns the value of attribute detail.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def detail
  @detail
end

#purchase_order_informationObject

Returns the value of attribute purchase_order_information.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def purchase_order_information
  @purchase_order_information
end

#sales_order_headerObject

Returns the value of attribute sales_order_header.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def sales_order_header
  @sales_order_header
end

#sales_order_shipment_informationObject

Returns the value of attribute sales_order_shipment_information.



4
5
6
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 4

def sales_order_shipment_information
  @sales_order_shipment_information
end

Instance Method Details

#add_message_header(builder) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 34

def add_message_header(builder)
  message_header = IngramMicro::MessageHeaderPW.new({
    partner_name: IngramMicro.configuration.partner_name,
    transaction_name: transaction_name})
  builder.send('message-header') do
    message_header.build(builder)
  end
  message_header.valid?
end

#add_sales_order_submission(builder) ⇒ Object



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

def add_sales_order_submission(builder)
  sos_options = {
    detail: detail,
    business_name: @business_name,
    customer_id: @customer_id,
    carrier_name: @carrier_name,
    customer: customer,
    sales_order_shipment_information: sales_order_shipment_information,
    sales_order_header: sales_order_header,
    credit_card_information: credit_card_information,
    purchase_order_information: purchase_order_information
  }
  sos = IngramMicro::SalesOrderSubmission.new(sos_options)
  builder.send('sales-order-submission') do
    sos.build(builder)
  end
  sos.valid?
end

#validate_options(options) ⇒ Object



63
64
65
66
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 63

def validate_options(options)
  raise "use sales_order_shipment_information (IngramMicro::SalesOrderShipmentInformation" if options[:shipment_information]
  raise "use sales_order_header (IngramMicro::SalesOrderHeader" if options[:order_header]
end

#xml_builderObject



24
25
26
27
28
29
30
31
32
# File 'lib/ingram_micro/transmissions/sales_order.rb', line 24

def xml_builder
  @builder ||= Nokogiri::XML::Builder.new do |builder|
    builder.message do
      add_message_header(builder)
      add_sales_order_submission(builder)
      add_transaction_info(builder)
    end
  end
end