Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.74 KB | None | 0 0
  1. var request = require('request');
  2. var fftopiaSDK = module.exports = function(rhu, username, password, debug, handler) {
  3. this.username = username;
  4. this.password = password;
  5. this.uri = 'https://' + rhu + '.veracore.com/pmomsws/oms.asmx';
  6. this.responseHandler = handler || function() {};
  7. this.debug = debug;
  8. };
  9.  
  10. fftopiaSDK.prototype.getOrder = function(orderId, callback) {
  11. var re = this.debug ? 'GetOrderInfo' : '';
  12. request({
  13. method: 'POST',
  14. headers: {
  15. 'SOAPAction': 'http://omscom/GetOrderInfo',
  16. 'Content-Type': 'text/xml; charset=utf-8'
  17. },
  18. uri: this.uri,
  19. body: '<?xml version="1.0" encoding="utf-8"?>\
  20. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\
  21. <soap:Header>\
  22. <DebugHeader xmlns="http://omscom/">\
  23. <Debug>' + this.debug + '</Debug>\
  24. <Request/>\
  25. </DebugHeader>\
  26. <AuthenticationHeader xmlns="http://omscom/">\
  27. <Username>' + this.username + '</Username>\
  28. <Password>' + this.password + '</Password>\
  29. </AuthenticationHeader>\
  30. </soap:Header>\
  31. <soap:Body>\
  32. <GetOrderInfo xmlns="http://omscom/">\
  33. <orderId>' + orderId + '</orderId>\
  34. </GetOrderInfo>\
  35. </soap:Body>\
  36. </soap:Envelope>'
  37. }, callback);
  38. };
  39.  
  40.  
  41. fftopiaSDK.prototype.addOrder = function(cMap, callback) {
  42. var priceClass = cMap.priceClass ? cMap.priceClass : 'Default';
  43. var top = '<?xml version="1.0" encoding="utf-8"?>\
  44. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\
  45. <soap:Header>\
  46. <DebugHeader xmlns="http://omscom/">\
  47. <Debug>' + this.debug + '</Debug>\
  48. <Request/>\
  49. </DebugHeader>\
  50. <AuthenticationHeader xmlns="http://omscom/">\
  51. <Username>' + this.username + '</Username>\
  52. <Password>' + this.password + '</Password>\
  53. </AuthenticationHeader>\
  54. </soap:Header>\
  55. <soap:Body>\
  56. <AddOrder xmlns="http://omscom/">\
  57. <order>\
  58. <Header>\
  59. <ID>' + cMap.orderId + '</ID>\
  60. <EntryDate>' + new Date()
  61. .toISOString() + '</EntryDate>\
  62. <OrderEntryView>\
  63. <Description></Description>\
  64. </OrderEntryView>\
  65. <ReferenceNumber>' + cMap.referenceNumber + '</ReferenceNumber>\
  66. <PONumber>' + cMap.poNumber + '</PONumber>\
  67. <Comments>' + cMap.comments + '</Comments>\
  68. <IpAddress></IpAddress>\
  69. <ApprovalComments>' + cMap.approvalComments + '</ApprovalComments>\
  70. <InsertDate>' + new Date()
  71. .toISOString() + '</InsertDate>\
  72. <UTCEntryDate>' + new Date()
  73. .toISOString() + '</UTCEntryDate>\
  74. </Header>\
  75. <Money>\
  76. <PriceClass>\
  77. <Description>' + priceClass + '</Description>\
  78. </PriceClass>\
  79. <ShippingHandlingCharge>' + cMap.shippingHandlingCharge + '</ShippingHandlingCharge>\
  80. <RushHandlingCharge>' + cMap.rushHandlingCharge + '</RushHandlingCharge>\
  81. </Money>\
  82. <OrderVariables></OrderVariables>\
  83. <OrderedBy>\
  84. <Prefix>' + cMap.orderByPrefix + '</Prefix>\
  85. <FirstName>' + cMap.orderByFirstName + '</FirstName>\
  86. <MiddleInitial>' + cMap.orderByMiddleInitial + '</MiddleInitial>\
  87. <LastName>' + cMap.orderByLastName + '</LastName>\
  88. <Suffix>' + cMap.orderBySuffix + '</Suffix>\
  89. <CompanyName>' + cMap.orderByCompanyName + '</CompanyName>\
  90. <Title>' + cMap.orderByTitle + '</Title>\
  91. <Address1>' + cMap.orderByAddress1 + '</Address1>\
  92. <Address2>' + cMap.orderByAddress2 + '</Address2>\
  93. <Address3>' + cMap.orderByAddress3 + '</Address3>\
  94. <City>' + cMap.orderByCity + '</City>\
  95. <State>' + cMap.orderByState + '</State>\
  96. <PostalCode>' + cMap.orderByPostalCode + '</PostalCode>\
  97. <Country>' + cMap.orderByCountry + '</Country>\
  98. <Phone>' + cMap.orderByPhone + '</Phone>\
  99. <Fax>' + cMap.orderByFax + '</Fax>\
  100. <Email>' + cMap.orderByEmail + '</Email>\
  101. <UID>' + cMap.orderByUID + '</UID>\
  102. <TaxExempt>' + cMap.orderByTaxExempt + '</TaxExempt>\
  103. <TaxExemptID>' + cMap.orderByTaxExemptID + '</TaxExemptID>\
  104. <TaxExemptApproved>' + cMap.orderByTaxExemptApproved + '</TaxExemptApproved>\
  105. <Commercial>' + cMap.orderByCommercial + '</Commercial>\
  106. </OrderedBy>\
  107. <ShipTo>\
  108. <OrderShipTo>\
  109. <Prefix>' + cMap.shipToPrefix + '</Prefix>\
  110. <FirstName>' + cMap.shipToFirstName + '</FirstName>\
  111. <MiddleInitial>' + cMap.shipToMiddleInitial + '</MiddleInitial>\
  112. <LastName>' + cMap.shipToLastName + '</LastName>\
  113. <Suffix>' + cMap.shipToSuffix + '</Suffix>\
  114. <CompanyName>' + cMap.shipToCompanyName + '</CompanyName>\
  115. <Title>' + cMap.shipToTitle + '</Title>\
  116. <Address1>' + cMap.shipToAddress1 + '</Address1>\
  117. <Address2>' + cMap.shipToAddress2 + '</Address2>\
  118. <Address3>' + cMap.shipToAddress3 + '</Address3>\
  119. <City>' + cMap.shipToCity + '</City>\
  120. <State>' + cMap.shipToState + '</State>\
  121. <PostalCode>' + cMap.shipToPostalCode + '</PostalCode>\
  122. <Country>' + cMap.shipToCountry + '</Country>\
  123. <Phone>' + cMap.shipToPhone + '</Phone>\
  124. <Fax>' + cMap.shipToFax + '</Fax>\
  125. <Email>' + cMap.shipToEmail + '</Email>\
  126. <UID>' + cMap.shipToUID + '</UID>\
  127. <TaxExempt>' + cMap.shipToTaxExempt + '</TaxExempt>\
  128. <TaxExemptID>' + cMap.shipToTaxExemptID + '</TaxExemptID>\
  129. <TaxExemptApproved>' + cMap.shipToTaxExemptApproved + '</TaxExemptApproved>\
  130. <Commercial>' + cMap.shipToCommercial + '</Commercial>\
  131. <Flag>' + cMap.shipToFlag + '</Flag>\
  132. <Key>' + cMap.shipToKey + '</Key>\
  133. <NeededBy>' + cMap.shipToNeededBy + '</NeededBy>\
  134. <ReleaseDate>' + cMap.shipToReleaseDate + '</ReleaseDate>\
  135. <Rush>' + cMap.shipToRush + '</Rush>\
  136. <RushHandling>' + cMap.shipToRushHandling + '</RushHandling>\
  137. <Comments>' + cMap.shipToComments + '</Comments>\
  138. <FreightCarrier>\
  139. <Name>' + cMap.shipToFreightCarrier + '</Name>\
  140. </FreightCarrier>\
  141. <FreightCode>' + cMap.shipToFreightCode + '</FreightCode>\
  142. <FreightCodeDescription>' + cMap.shipToFreightCodeDescription + '</FreightCodeDescription>\
  143. <SpecialHandling>\
  144. <Description>' + cMap.shipToSpecialHandling + '</Description>\
  145. </SpecialHandling>\
  146. </OrderShipTo>\
  147. </ShipTo>\
  148. <BillTo>\
  149. <TaxExempt>' + cMap.billToTaxExempt + '</TaxExempt>\
  150. <TaxExemptID>' + cMap.billToTaxExemptID + '</TaxExemptID>\
  151. <TaxExemptApproved>' + cMap.billToTaxExemptApproved + '</TaxExemptApproved>\
  152. <Commercial>' + cMap.billToCommercial + '</Commercial>\
  153. </BillTo>\
  154. <Offers>';
  155.  
  156. var offers = '';
  157.  
  158. for (var cnt = 0; cnt < cMap.offers.length; cnt++) {
  159. offers += '<OfferOrdered>\
  160. <Offer>\
  161. <Header>\
  162. <ID>' + cMap.offers[cnt].offerId + '</ID>\
  163. </Header>\
  164. </Offer>\
  165. <Quantity>' + cMap.offers[cnt].quantity + '</Quantity>\
  166. <OrderShipToKey>\
  167. <Key>' + cMap.offers[cnt].shipToKey + '</Key>\
  168. </OrderShipToKey>\
  169. <PriceType>' + cMap.offers[cnt].priceType + '</PriceType>\
  170. <UnitPrice>' + cMap.offers[cnt].unitPrice + '</UnitPrice>\
  171. <ShippingHandling>' + cMap.offers[cnt].shippingHandling + '</ShippingHandling>\
  172. <Discounts>' + cMap.offers[cnt].discounts + '</Discounts>\
  173. </OfferOrdered>';
  174. }
  175.  
  176. var bottom = '</Offers></order></AddOrder></soap:Body></soap:Envelope>';
  177.  
  178. var body = top + offers + bottom;
  179. request({
  180. method: 'POST',
  181. headers: {
  182. 'SOAPAction': 'http://omscom/AddOrder',
  183. 'Content-Type': 'text/xml; charset=utf-8'
  184. },
  185. uri: this.uri,
  186. body
  187. }, callback);
  188. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement