Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*</mg, '><');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in my testing, this was required to get it to work right.


var protocol = https ? 'https://' : 'http://';
var url = protocol + 'secure.shippingapis.com/ShippingAPI.dll';

request({
url: url,
method: 'GET',
qs: { API: api, XML: xml }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wouldn't work without URI encoding all the stuff, so it seemed cleaner to use the builtin request functionality rather than a template.

},
function (error, response, body) {
if (!error && response.statusCode === 200) {
parser.parseString(body, function (error, json) {
Expand Down
12 changes: 12 additions & 0 deletions lib/apis/domesticShippingLabel.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
65 changes: 65 additions & 0 deletions lib/templates/delivConfirmCertifyV4.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<DelivConfirmCertifyV4.0Request USERID="{{userID}}">
  {{#if option}}<Option>{{option}}</Option>{{/if}}
  {{#if revision}}<Revision>{{revision}}</Revision>{{/if}}
  <ImageParameters>
   <ImageParameter>{{imageParameter}}</ImageParameter>  
  </ImageParameters>
  <FromName>{{fromName}}</FromName>
  <FromFirm>{{fromFirm}}</FromFirm>
  <FromAddress1>{{fromAddress1}}</FromAddress1>
  <FromAddress2>{{fromAddress2}}</FromAddress2>
  <FromCity>{{fromCity}}</FromCity>
  <FromState>{{fromState}}</FromState>
  <FromZip5>{{fromZip5}}</FromZip5>
  <FromZip4>{{fromZip4}}</FromZip4>
  <ToName>{{toName}}</ToName>
  <ToFirm>{{toFirm}}</ToFirm>
  <ToAddress1>{{toAddress1}}</ToAddress1>
  <ToAddress2>{{toAddress2}}</ToAddress2>
  <ToCity>{{toCity}}</ToCity>
  <ToState>{{toState}}</ToState>
  <ToZip5>{{toZip5}}</ToZip5>
  <ToZip4>{{toZip4}}</ToZip4>
  <ToPOBoxFlag>{{toPOBoxFlag}}</ToPOBoxFlag>
  <WeightInOunces>{{weightInOunces}}</WeightInOunces>
  <ServiceType>{{serviceType}}</ServiceType>
  <InsuredAmount>{{insuredAmount}}</InsuredAmount>
  <ImageType>{{imageType}}</ImageType>
  <LabelDate>{{labelDate}}</LabelDate>
  <AllowNonCleansedDestAddr>{{allowNonCleansedDestAddr}}</AllowNonCleansedDestAddr>
  <Container>{{container}}</Container>
  <Size>{{size}}</Size>
  <Width>{{width}}</Width>
  <Length>{{length}}</Length>
  <Height>{{height}}</Height>
  <Girth>{{girth}}</Girth>
  <ReturnCommitments>{{returnCommitments}}</ReturnCommitments>
<ShippingContents>
{{#each shippingContents}}
    <ItemDetail>
      <Description>{{description}}</Description>
      <Quantity>{{quantity}}</Quantity>
      <Value>{{value}}</Value>
      <NetPounds>{{netPounds}}</NetPounds>
      <NetOunces>{{netOunces}}</NetOunces>
      <HSTariffNumber>{{hSTariffNumber}}</HSTariffNumber>
      <CountryOfOrigin>{{countryOfOrigin}}</CountryOfOrigin>
    </ItemDetail>
{{/each}}
</ShippingContents>
<FromPhone>{{fromPhone}}</FromPhone>
<SenderMID>{{senderMID}}</SenderMID>
<ToPhone>{{toPhone}}</ToPhone>
<CustomsContentType>{{customsContentType}}</CustomsContentType>
<ContentComments>{{contentComments}}</ContentComments>
<RestrictionType>{{restrictionType}}</RestrictionType>
<RestrictionComments>{{restrictionComments}}</RestrictionComments>
<AESITN>{{aESITN}}</AESITN>
<ImportersReference>{{importersReference}}</ImportersReference>
<ImportersContact>{{importersContact}}</ImportersContact>
<ExportersReference>{{exportersReference}}</ExportersReference>
<ExportersContact>{{exportersContact}}</ExportersContact>
<InvoiceNumber>{{invoiceNumber}}</InvoiceNumber>
<LicenseNumber>{{licenseNumber}}</LicenseNumber>
<CertificateNumber>{{certificateNumber}}</CertificateNumber>
</DelivConfirmCertifyV4.0Request>
92 changes: 92 additions & 0 deletions lib/templates/deliveryConfirmationV4.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF‐8"?>
<DeliveryConfirmationV4.0Request USERID="{{userID}}">
  <Option>{{option}}</Option>
<Revision>{{revision}}</Revision>
{{#if imageParameters}}
  <ImageParameters>
{{#each imageParameters.options}}
<ImageParameter>{{value}}</ImageParameter>
{{/each}}
{{#each labelSequence}}
     <LabelSequence>
       <PackageNumber>{{packageNumber}}</PackageNumber>
       <TotalPackages>{{totalPackages}}</TotalPackages>
     </LabelSequence>
{{/each}}
  </ImageParameters>
{{/if}}
  <FromName>{{fromName}}</FromName>
  <FromFirm>{{fromFirm}}</FromFirm>
  <FromAddress1>{{fromAddress1}}</FromAddress1>
  <FromAddress2>{{fromAddress2}}</FromAddress2>
  <FromCity>{{fromCity}}</FromCity>
  <FromState>{{fromState}}</FromState>
  <FromZip5>{{fromZip5}}</FromZip5>
<FromZip4>{{fromZip4}}</FromZip4>
  <ToName>{{toName}}</ToName>
  <ToFirm>{{toFirm}}</ToFirm>
  <ToAddress1>{{toAddress1}}</ToAddress1>
  <ToAddress2>{{toAddress2}}</ToAddress2>
  <ToCity>{{toCity}}</ToCity>
  <ToState>{{toState}}</ToState>
  <ToZip5>{{toZip5}}</ToZip5>
  <ToZip4>{{toZip4}}</ToZip4>
{{#if toPOBoxFlag}}<ToPOBoxFlag>{{toPOBoxFlag}}</ToPOBoxFlag>{{/if}}
  <WeightInOunces>{{weightInOunces}}</WeightInOunces>
  <ServiceType>{{serviceType}}</ServiceType>
  {{#if insuredAmount}}<InsuredAmount>{{insuredAmount}}</InsuredAmount>{{/if}}
<WaiverOfSignature>{{waiverOfSignature}}</WaiverOfSignature>
  <SeparateReceiptPage>{{separateReceiptPage}}</SeparateReceiptPage>
  {{#if poZipCode}}<POZipCode>{{poZipCode}}</POZipCode>{{/if}}
  <ImageType>{{imageType}}</ImageType>
  {{#if labelDate}}<LabelDate>{{labelDate}}</LabelDate>{{/if}}
  {{#if customerRefNo}}<CustomerRefNo>{{customerRefNo}}</CustomerRefNo>{{/if}}
  <AddressServiceRequested>{{addressServiceRequested}}</AddressServiceRequested>
  {{#if senderName}}<SenderName>{{senderName}}</SenderName>{{/if}}
  {{#if senderEmail}}<SenderEMail>{{senderEmail}}</SenderEMail>{{/if}}
  {{#if recipientName}}<RecipientName>{{recipientName}}</RecipientName>{{/if}}
  {{#if recipientEmail}}<RecipientEMail>{{recipientEmail}}</RecipientEMail>{{/if}}
{{#if allowNonCleansedDestAddr}}
<AllowNonCleansedDestAddr>{{allowNonCleansedDestAddr}}</AllowNonCleansedDestAddr>
{{/if}}
{{#if holdForManifest}}<HoldForManifest>{{holdForManifest}}</HoldForManifest>{{/if}}
  {{#if container}}<Container>{{container}}</Container>{{/if}}
  {{#if size}}<Size>{{size}}</Size>{{/if}}
{{#if width}}<Width>{{width}}</Width>{{/if}}
{{#if length}}<Length>{{length}}</Length>{{/if}}
{{#if height}}<Height>{{height}}</Height>{{/if}}
{{#if girth}}<Girth>{{girth}}</Girth>{{/if}}
{{#if machinable}}<Machinable>{{machinable}}</Machinable>{{/if}}
{{#if commercialPrice}}<CommercialPrice>{{commercialPrice}}</CommercialPrice>{{/if}}
{{#if extraServices}}
<ExtraServices>
{{#each extraServices}}
<ExtraService>{{value}}</ExtraService>
{{/each}}
</ExtraServices>
{{/if}}
{{#if returnCommitments}}<ReturnCommitments>{{returnCommitments}}</ReturnCommitments>{{/if}}
{{#if groundOnly}}<GroundOnly>{{groundOnly}}</GroundOnly>{{/if}}
{{#if content}}
  <Content>
    <ContentType>{{content.type}}</ContentType>
    <ContentDescription>{{content.description}}</ContentDescription>
  </Content>
{{/if}}
{{#if meterData}}
<MeterData>
<MeterVendorID>{{meterData.meterVendorID}}</MeterVendorID>
<MeterSerialNumber>{{meterData.meterSerialNumber}}</MeterSerialNumber>
<MeterModelID>{{meterData.meterModelID}}</MeterModelID>
<RateCategory>{{meterData.rateCategory}}</RateCategory>
<IndiciumCreationRecordDate>{{meterData.indiciumCreationRecordDate}}</IndiciumCreationRecordDate>
<IBI>{{meterData.IBI}}</IBI>
</MeterData>
{{/if}}
{{#if customsContentType}}
<CustomsContentType>{{customsContentType}}</CustomsContentType>
{{/if}}
{{#if contentComments}}
<ContentComments>{{contentComments}}</ContentComments>
{{/if}}
</DeliveryConfirmationV4.0Request>
1 change: 1 addition & 0 deletions lib/usps-web-tools-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down