Class: Fosdick::Documents::Shipment
- Inherits:
-
Object
- Object
- Fosdick::Documents::Shipment
- Defined in:
- lib/fosdick/documents/shipment.rb
Instance Method Summary collapse
-
#initialize(shipment, config) ⇒ Shipment
constructor
A new instance of Shipment.
- #to_xml ⇒ Object
Constructor Details
#initialize(shipment, config) ⇒ Shipment
Returns a new instance of Shipment.
4 5 6 7 |
# File 'lib/fosdick/documents/shipment.rb', line 4 def initialize(shipment, config) @shipment = shipment @config = config end |
Instance Method Details
#to_xml ⇒ Object
9 10 11 12 13 14 15 16 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fosdick/documents/shipment.rb', line 9 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.UnitycartOrderPost('xml:lang' => 'en-US') { xml.ClientCode(@config['client_code']) xml.Test('Y') if test? xml.TransactionID(SecureRandom.hex(15)) xml.Order { xml.ShippingMethod(@shipment['shipping_method']) xml.Subtotal(0) xml.Total(0) xml.ExternalID("#{@shipment['id']}") xml.AdCode(@shipment['adcode'] || @config['adcode']) xml.Prepaid('Y') xml.PaymentType(5) xml.ShipFirstname truncate_name xml.ShipLastname(@shipment['shipping_address']['lastname']) xml.ShipAddress1(@shipment['shipping_address']['address1']) xml.ShipAddress2(@shipment['shipping_address']['address2']) xml.ShipCity(truncate_city) if (@shipment['shipping_address']['country'] != 'US') xml.ShipStateOther(ship_state) else xml.ShipState(ship_state) end xml.ShipZip(@shipment['shipping_address']['zipcode']) xml.ShipCountry(@shipment['shipping_address']['country']) xml.ShipPhone(@shipment['shipping_address']['phone']) xml.Email(@shipment['email']) xml.Code(@shipment['shipping_method_code']) (1..5).each do |i| next unless @shipment.key? "custom#{i}" xml.send("Custom#{i}", @shipment["custom#{i}"]) end xml.Items { @shipment['items'].each_with_index do |item, index| xml.Item { xml.Inv item['product_id'] xml.Qty item['quantity'] xml.PricePer 0 } end } } } end builder.to_xml end |