diff --git a/lib/api.js b/lib/api.js index f020672..241896f 100644 --- a/lib/api.js +++ b/lib/api.js @@ -12,12 +12,18 @@ var module.exports = { request: function (https, api, req, data, responseObject, callback) { - request( - templates.apiSignature({ - https: https, - api: api, - xml: templates[req](data) - }), + var xml = templates[req](data); + // Remove whitespace between XML elements + xml = xml.replace(/>\s*<'); + + var protocol = https ? 'https://' : 'http://'; + var url = protocol + 'secure.shippingapis.com/ShippingAPI.dll'; + + request({ + url: url, + method: 'GET', + qs: { API: api, XML: xml } + }, function (error, response, body) { if (!error && response.statusCode === 200) { parser.parseString(body, function (error, json) { diff --git a/lib/apis/domesticShippingLabel.js b/lib/apis/domesticShippingLabel.js new file mode 100644 index 0000000..1555a6f --- /dev/null +++ b/lib/apis/domesticShippingLabel.js @@ -0,0 +1,12 @@ +'use strict'; + +var api = require('../api'); + +module.exports = { + deliveryConfirmation: function (data, callback) { + api.request(true, 'DeliveryConfirmationV4', 'deliveryConfirmationV4', data, 'deliveryConfirmationV4.0Response', callback); + }, + deliveryConfirmCeritfy: function (data, callback) { + api.request(true, 'DelivConfirmCertifyV4', 'delivConfirmCertifyV4', data, 'delivConfirmCertifyV4.0Response', callback); + } +}; diff --git a/lib/templates/delivConfirmCertifyV4.hbs b/lib/templates/delivConfirmCertifyV4.hbs new file mode 100644 index 0000000..b929bd9 --- /dev/null +++ b/lib/templates/delivConfirmCertifyV4.hbs @@ -0,0 +1,65 @@ + +  {{#if option}}{{/if}} +  {{#if revision}}{{revision}}{{/if}} +   +   {{imageParameter}}   +   +  {{fromName}} +  {{fromFirm}} +  {{fromAddress1}} +  {{fromAddress2}} +  {{fromCity}} +  {{fromState}} +  {{fromZip5}} +  {{fromZip4}} +  {{toName}} +  {{toFirm}} +  {{toAddress1}} +  {{toAddress2}} +  {{toCity}} +  {{toState}} +  {{toZip5}} +  {{toZip4}} +  {{toPOBoxFlag}} +  {{weightInOunces}} +  {{serviceType}} +  {{insuredAmount}} +  {{imageType}} +  {{labelDate}} +  {{allowNonCleansedDestAddr}} +  {{container}} +  {{size}} +  {{width}} +  {{length}} +  {{height}} +  {{girth}} +  {{returnCommitments}} + + {{#each shippingContents}} +     +      {{description}} +      {{quantity}} +      {{value}} +      {{netPounds}} +      {{netOunces}} +      {{hSTariffNumber}} +      {{countryOfOrigin}} +     + {{/each}} + + {{fromPhone}} + {{senderMID}} + {{toPhone}} + {{customsContentType}} + {{contentComments}} + {{restrictionType}} + {{restrictionComments}} + {{aESITN}} + {{importersReference}} + {{importersContact}} + {{exportersReference}} + {{exportersContact}} + {{invoiceNumber}} + {{licenseNumber}} + {{certificateNumber}} + \ No newline at end of file diff --git a/lib/templates/deliveryConfirmationV4.hbs b/lib/templates/deliveryConfirmationV4.hbs new file mode 100644 index 0000000..0ee42b1 --- /dev/null +++ b/lib/templates/deliveryConfirmationV4.hbs @@ -0,0 +1,92 @@ + + +   + {{revision}} + {{#if imageParameters}} +   + {{#each imageParameters.options}} + {{value}} + {{/each}} + {{#each labelSequence}} +     +       {{packageNumber}} +       {{totalPackages}} +     + {{/each}} +   + {{/if}} +  {{fromName}} +  {{fromFirm}} +  {{fromAddress1}} +  {{fromAddress2}} +  {{fromCity}} +  {{fromState}} +  {{fromZip5}} + {{fromZip4}} +  {{toName}} +  {{toFirm}} +  {{toAddress1}} +  {{toAddress2}} +  {{toCity}} +  {{toState}} +  {{toZip5}} +  {{toZip4}} + {{#if toPOBoxFlag}}{{toPOBoxFlag}}{{/if}} +  {{weightInOunces}} +  {{serviceType}} +  {{#if insuredAmount}}{{insuredAmount}}{{/if}} + {{waiverOfSignature}} +  {{separateReceiptPage}} +  {{#if poZipCode}}{{poZipCode}}{{/if}} +  {{imageType}} +  {{#if labelDate}}{{labelDate}}{{/if}} +  {{#if customerRefNo}}{{customerRefNo}}{{/if}} +  {{addressServiceRequested}} +  {{#if senderName}}{{senderName}}{{/if}} +  {{#if senderEmail}}{{senderEmail}}{{/if}} +  {{#if recipientName}}{{recipientName}}{{/if}} +  {{#if recipientEmail}}{{recipientEmail}}{{/if}} + {{#if allowNonCleansedDestAddr}} + {{allowNonCleansedDestAddr}} + {{/if}} + {{#if holdForManifest}}{{holdForManifest}}{{/if}} +  {{#if container}}{{container}}{{/if}} +  {{#if size}}{{size}}{{/if}} + {{#if width}}{{width}}{{/if}} + {{#if length}}{{length}}{{/if}} + {{#if height}}{{height}}{{/if}} + {{#if girth}}{{girth}}{{/if}} + {{#if machinable}}{{machinable}}{{/if}} + {{#if commercialPrice}}{{commercialPrice}}{{/if}} + {{#if extraServices}} + + {{#each extraServices}} + {{value}} + {{/each}} + + {{/if}} + {{#if returnCommitments}}{{returnCommitments}}{{/if}} + {{#if groundOnly}}{{groundOnly}}{{/if}} + {{#if content}} +   +    {{content.type}} +    {{content.description}} +   + {{/if}} + {{#if meterData}} + + {{meterData.meterVendorID}} + {{meterData.meterSerialNumber}} + {{meterData.meterModelID}} + {{meterData.rateCategory}} + {{meterData.indiciumCreationRecordDate}} + {{meterData.IBI}} + + {{/if}} + {{#if customsContentType}} + {{customsContentType}} + {{/if}} + {{#if contentComments}} + {{contentComments}} + {{/if}} + diff --git a/lib/usps-web-tools-sdk.js b/lib/usps-web-tools-sdk.js index 9098d60..467c1bf 100644 --- a/lib/usps-web-tools-sdk.js +++ b/lib/usps-web-tools-sdk.js @@ -7,6 +7,7 @@ module.exports = { configure: configure.configure, customFormLabel: require('./apis/customFormLabel'), domesticMailServiceStandards: require('./apis/domesticMailServiceStandards'), + domesticShippingLabel: require('./apis/domesticShippingLabel'), options: configure.options, rateCalculator: require('./apis/rateCalculator'), sdcServiceStandards: require('./apis/sdcServiceStandards'),