diff --git a/README.md b/README.md index bddde30..2baa03e 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,17 @@ client.get_stock_status(params_for_stock_status) c.login = "customer_login" #configured in 3PL Central -> Customer -> Customer Users c.password = "customer_password" # same as login c.default_facility_id = 1 #this might be removed in a later version, and we'll just look for the "Facility ID" on the order or item level. - c.user_login_id = 4 #We had to contact our account manager with 3PL Central to get this information. + # c.user_login_id = 4 #We had to contact our account manager with 3PL Central to get this information. + c.customer_id = 1 + + # three_pl_id is for reading, three_pl_key is for writing + c.three_pl_id = "three_pl_id" + + # Pass configuration values to Savon + # See values in Savon documentation + c.savon_config = { + log: false + } end ``` @@ -59,35 +69,43 @@ client.get_stock_status(params_for_stock_status) ThreePLCentral::Order.create({ trans_info: { - reference_num: "100001", + reference_num: "100001", # required expected_date: "2014-11-12", earliest_ship_date: "2014-11-12", ship_cancel_date: "2014-11-12"}, ship_to: { name: "Test Test", - company_name: "Test Co.", + company_name: "Test Co.", # required address:{ - address1: "Toronto", + address1: "Toronto", # required address2:"Ste. 2", - city:"1234 Fake St.", - state:"ON", - zip:"M4B 1B3", - country:"Canada"}, + city:"1234 Fake St.", # required + state:"ON", # required + zip:"M4B 1B3", # required + country:"Canada" # required + }, phone_number1: "999-999-9999", email_address1: "test@test.com", - shipping_instructions: { - carrier: "FedEx", - mode: "Ground", - shipping_notes: "I need it ASAP!"} }, + shipping_instructions: { + carrier: "FedEx", # required + mode: "Ground", # required + billing_code: "Prepaid" # required + shipping_notes: "I need it ASAP!"}, notes: "More notes!", - order_line_items: [ - { - sku:"90RND-010101", - qty:"10", - fulfillment_sale_price:9.99, - fulfillment_discount_percentage:10, - fulfillment_discount_amount:0.99} + order_line_items: [ # required at least one + # NOTE: This is an array of hashes, each hash only contain one key: + # `order_line_item` + { order_line_item: + { + SKU:"90RND-010101", # It must be all uppercase, required + qty:"10", # required + fulfillment_sale_price:9.99, + fulfillment_discount_percentage:10, + fulfillment_discount_amount:0.99 + } + # ... more objects(items) here + } ], fulfillment_info:{ fulfill_inv_shipping_and_handling:9.12, diff --git a/lib/3pl_central/base.rb b/lib/3pl_central/base.rb index 23db7e0..053e1ce 100644 --- a/lib/3pl_central/base.rb +++ b/lib/3pl_central/base.rb @@ -6,7 +6,8 @@ def create_creds "ThreePLKey" => ThreePLCentral.configuration.three_pl_key, login: ThreePLCentral.configuration.login, password: ThreePLCentral.configuration.password, - facility_id: facility_id || ThreePLCentral.configuration.default_facility_id + Facility_ID: facility_id || ThreePLCentral.configuration.default_facility_id, + Customer_ID: ThreePLCentral.configuration.customer_id }} end @@ -21,6 +22,6 @@ def self.read_creds def self.parser @parser ||= Nori.new(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym }) end - + end end diff --git a/lib/3pl_central/client.rb b/lib/3pl_central/client.rb index d909e97..3bc1023 100644 --- a/lib/3pl_central/client.rb +++ b/lib/3pl_central/client.rb @@ -1,11 +1,14 @@ module ThreePLCentral class Client + # TODO remove duplication, specifying config values in one place def initialize(params) ThreePLCentral.configure do |c| c.three_pl_key = params[:three_pl_key] c.login = params[:login] c.password = params[:password] c.three_pl_id = params[:three_pl_id] + c.customer_id = params[:customer_id] + c.savon_config = params[:savon_config] end end @@ -30,4 +33,4 @@ def run_method(class_name, method_name, *args) full_class.constantize.send(method_name.to_sym, *args) end end -end \ No newline at end of file +end diff --git a/lib/3pl_central/configuration.rb b/lib/3pl_central/configuration.rb index 03ee26e..0893055 100644 --- a/lib/3pl_central/configuration.rb +++ b/lib/3pl_central/configuration.rb @@ -7,7 +7,16 @@ class << self end def self.client - @client ||= Savon.client(wsdl:WSDL_URL, ssl_version: :TLSv1, ssl_verify_mode: :none, log_level: :debug, log: true, pretty_print_xml: true, no_message_tag:true, convert_request_keys_to: :camelcase) + @client ||= Savon.client(savon_config) + end + + def self.savon_config + @savon_config ||= {wsdl:WSDL_URL, + ssl_version: :TLSv1, ssl_verify_mode: :none, + log_level: :debug, log: true, pretty_print_xml: true, + no_message_tag:true, convert_request_keys_to: :camelcase} + .with_indifferent_access + .merge(configuration.savon_config) end def self.configure @@ -16,14 +25,18 @@ def self.configure end class Configuration - attr_accessor :three_pl_key, :login, :password, :default_facility_id, :three_pl_id + # TODO remove duplication, specifying config values in one place + attr_accessor :three_pl_key, :login, :password, :default_facility_id, + :three_pl_id, :customer_id, :savon_config def initialize @three_pl_key = '' @login = '' @password = '' @default_facility_id = '' - @three_pl_id = '' + @three_pl_id = '' + @customer_id = '' + @savon_config = {} end end end diff --git a/lib/3pl_central/order.rb b/lib/3pl_central/order.rb index 764f57e..a3fa8ed 100644 --- a/lib/3pl_central/order.rb +++ b/lib/3pl_central/order.rb @@ -24,7 +24,9 @@ def find(params) xml_hash["limitCount"] = 10 xml_hash["focr"] = params response = ThreePLCentral::Services.find_orders(xml_hash) - parser.parse(response.body[:find_orders])["orders"]["order"].arrayify + parser.parse(response.body[:find_orders]) + .with_indifferent_access["orders"]["order"] + .arrayify end def create(params)