Magento Forum

   
Page 1 of 2
[SOLVED] Magento returning USPS shipping label with signature confirmation even when I don’t want it
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

Magento 1.7 with USPS web tools API in production mode
---------

Using the Create/Print Shipping Label buttons (in Sales->Orders or Sales->Shipments) always seems to generate a label with signature confirmation. All I want is delivery confirmation, I *don’t* want the customer to have to sign for the package. Even when I choose “Signature Confirmation -> Not Required” it still returns a shipping label with signature confirmation. Any idea what’s going on?

Here’s the debug log (edited out personal info):

2012-09-05T21:04:00+00:00 DEBUG (7): Array
(
    
[request] => <SignatureConfirmationV3.0Request USERID="[erased]"><Option>1</Option><ImageParameters/><FromName>[erased]</FromName><FromFirm>[erased]</FromFirm><FromAddress1></FromAddress1><FromAddress2>[erased]</FromAddress2><FromCity>[erased]</FromCity><FromState>[erased]</FromState><FromZip5>[erased]</FromZip5><FromZip4></FromZip4><ToName>[erased]</ToName><ToFirm/><ToAddress1></ToAddress1><ToAddress2>[erased]</ToAddress2><ToCity>[erased]</ToCity><ToState>[erased]</ToState><ToZip5>[erased]</ToZip5><ToZip4></ToZip4><WeightInOunces>1</WeightInOunces><ServiceType>First Class</ServiceType><WaiverOfSignature>True</WaiverOfSignature><ImageType>PDF</ImageType></SignatureConfirmationV3.0Request>
    
[result] => SimpleXMLElement Object
        
(
            
[SignatureConfirmationNumber] => 420770579121969010386103937453
            [SignatureConfirmationLabel] 
=> JVBERi0xLjINCjUgMCBvYmoNCjw8DQovVHlwZSAvWE9iamVjdA0KL1N1YnR5cGUg [etc]

And I attached the resulting shipping label, which shows “Signature Confirmation $2.10” even though I only charged the customer $1.25 for NO signature confirmation.

Image Attachments
usps.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

I just called USPS and they confirmed that the problem is with Magento, for some reason Magento is always requesting signature confirmation from USPS, even when I don’t want it to.

Where do I need to look to debug this? I’m kinda lost here.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

Update:

I discovered the following file:

/app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php
which seems to have all of the USPS config data. Starting at line 1605, there is a section about obtaining print shipping labels.

At line 1621, it appears that if there is ANY shipment in the US that is not express mail, then the file is requesting the SignatureConfirmationV3 API. Here’s that section, beginning at line 1618:

if ($recipientUSCountry && $service == 'EXPRESS'{
            $requestXml 
$this->_formUsExpressShipmentRequest($request);
            
$api 'ExpressMailLabel';
        
else if ($recipientUSCountry{
            $requestXml 
$this->_formUsSignatureConfirmationShipmentRequest($request$service);
            if (
$this->getConfigData('mode')) {
                $api 
'SignatureConfirmationV3';
            
else {
                $api 
'SignatureConfirmationCertifyV3';
            
}

I don’t want it to request signature confirmation, I just want regular old fashioned postage with a tracking number. Does anyone know what I need to change here to make it happen? I’ve been digging like crazy and this seems like maybe I’m in the right place now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

bump,

Any ideas about this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

bump

still trying to resolve this, can anyone help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

bump

if anyone is even reading this, i would appreciate it if you could just check in here.

Not sure if nobody knows the answer, or rather that nobody is reading this…

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

Still looking for a solution. Anyone have an idea where to look?

 
Magento Community Magento Community
Magento Community
Magento Community
 
austinhumes
Jr. Member
 
Total Posts:  5
Joined:  2010-11-26
 

I’ve come across this issue as well, I’m on version 1.7.0.2.  As you pointed out the code in your example, the _doShipmentRequest function in Usps.php is doing either Express shipments or Signature Confirm shipments (for US recipients).  There are existing functions such as _formUsExpressShipmentRequest and _formUsSignatureConfirmationShipmentRequest, which appear to create the xml api request that USPS needs, ie https://www.usps.com/webtools/htm/Signature-Confirmation-v2-1c.htm#_Toc131259582.

I’ve been playing around with modifying it to try to use Priority Mail, which is what I use to ship.  However I haven’t had any luck with it yet.  I’m not even sure which api user guide to go off of for Priority Mail (https://www.usps.com/business/webtools-technical-guides.htm).  The only mention of Priority shipping method is for International shipments.

Will keep looking into it and update with any breakthroughs.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 
austinhumes - 20 September 2012 09:41 PM

I’ve come across this issue as well, I’m on version 1.7.0.2.  As you pointed out the code in your example, the _doShipmentRequest function in Usps.php is doing either Express shipments or Signature Confirm shipments (for US recipients).  There are existing functions such as _formUsExpressShipmentRequest and _formUsSignatureConfirmationShipmentRequest, which appear to create the xml api request that USPS needs, ie https://www.usps.com/webtools/htm/Signature-Confirmation-v2-1c.htm#_Toc131259582.

I’ve been playing around with modifying it to try to use Priority Mail, which is what I use to ship.  However I haven’t had any luck with it yet.  I’m not even sure which api user guide to go off of for Priority Mail (https://www.usps.com/business/webtools-technical-guides.htm).  The only mention of Priority shipping method is for International shipments.

Will keep looking into it and update with any breakthroughs.

I was thinking, becuase there is an API called:

SignatureConfirmationV3

you would think there should be a similar API called:

DeliveryConfirmationV3

I tried swapping out all the references to SignatureConfirmation and changing them to DeliveryConfirmation but it didn’t seem to make a difference. So maybe that’s not the answer, I dunno.

 
Magento Community Magento Community
Magento Community
Magento Community
 
austinhumes
Jr. Member
 
Total Posts:  5
Joined:  2010-11-26
 

There is a DeliveryConfirmationV3 api: https://www.usps.com/webtools/htm/Delivery-Confirmation-v8-1c.htm.  The examples look pretty much exactly the same as the SignatureConfirmationV3 xml, ex:

<DeliveryConfirmationV3.0Request USERID="xxxx">
<
Option>1</Option>
<
ImageParameters />
<
FromName>John Smith</FromName>
<
FromFirm />
<
FromAddress1 />
<
FromAddress2>475 L'Enfant Plaza, SW</FromAddress2>
<FromCity>Washington</FromCity>
<FromState>DC</FromState>
<FromZip5>20260</FromZip5>
<FromZip4 />
<ToName>Joe Customer</ToName>
<ToFirm />
<ToAddress1>STE 201</ToAddress1>
<ToAddress2>6060 PRIMACY PKWY</ToAddress2>
<ToCity>MEMPHIS</ToCity>
<ToState>TN</ToState>
<ToZip5 />
<ToZip4 />
<WeightInOunces>2</WeightInOunces>
<ServiceType>Priority</ServiceType>
<POZipCode />
<ImageType>TIF</ImageType>
<LabelDate />
</DeliveryConfirmationV3.0Request>

vs.

<SignatureConfirmationV3.0Request USERID="xxxx">
<
Option>1</Option>
<
ImageParameters></ImageParameters>
<
FromName>John Smith</FromName>
<
FromFirm></FromFirm>
<
FromAddress1></FromAddress1>
<
FromAddress2>475 L'Enfant Plaza, SW</FromAddress2>
<FromCity>Washington</FromCity>
<FromState>DC</FromState>
<FromZip5>20260</FromZip5>
<FromZip4></FromZip4>
<ToName>Joe Customer</ToName>
<ToFirm></ToFirm>
<ToAddress1>STE 201</ToAddress1>
<ToAddress2>6060 PRIMACY PKWY</ToAddress2>
<ToCity>MEMPHIS</ToCity>
<ToState>TN</ToState>
<ToZip5></ToZip5>
<ToZip4></ToZip4>
<WeightInOunces>2</WeightInOunces>
<ServiceType>Priority</ServiceType>
<POZipCode></POZipCode>
<ImageType>TIF</ImageType>
<LabelDate></LabelDate>
</SignatureConfirmationV3.0Request>

I sent an email to USPS support to ask which API should be used for non-signature priority mail, hopefully will hear back soon.  I must have skipped over the Delivery Confirmation one since it looks promising, will read over it now and hopefully get a chance to test it later this evening.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

Fantastic. Please update if you figure out how to properly integrate the delivery confirmation API in lieu of the signature confirmation. Been struggling with this for a while and it’s a bit above my pay grade :\

 
Magento Community Magento Community
Magento Community
Magento Community
 
austinhumes
Jr. Member
 
Total Posts:  5
Joined:  2010-11-26
 

Alright, I think I got it.  Had to modify a few different things. 

First, I made a copy of the “_formUsSignatureConfirmationShipmentRequest” function and swapped out references of SignatureConfirmation to DeliveryConfirmation, as well as commented out WaiverOfSignature xml node, ex:

//A.Humes - Modifying Signature Confirmation function to use for Delivery Confirmation
    /**
     * Form XML for US Delivery Confirmation request
     * As integration guide it is important to follow appropriate sequence for tags e.g.: <FromLastName /> must be
     * after <FromFirstName />
     *
     * @param Varien_Object $request
     * @param string $serviceType
     * @return string
     */
    protected function _formUsDeliveryConfirmationShipmentRequest(Varien_Object $request$serviceType)
    
{
        
switch ($serviceType{
            
case 'PRIORITY':
                
$serviceType 'Priority';
                break;
            case 
'FIRST CLASS':
                
$serviceType 'First Class';
                break;
            case 
'PARCEL':
                
$serviceType 'Parcel Post';
                break;
            case 
'MEDIA':
                
$serviceType 'Media Mail';
                break;
            case 
'LIBRARY':
                
$serviceType 'Library Mail';
                break;
            default:
                throw new 
Exception(Mage::helper('usa')->__('Service type does not match'));
        
}
        $packageParams 
$request->getPackageParams();
        
$packageWeight $request->getPackageWeight();
        if (
$packageParams->getWeightUnits() != Zend_Measure_Weight::OUNCE{
            $packageWeight 
round(Mage::helper('usa')->convertMeasureWeight(
                
$request->getPackageWeight(),
                
$packageParams->getWeightUnits(),
                
Zend_Measure_Weight::OUNCE
            
));
        
}

        
list($fromZip5$fromZip4) = $this->_parseZip($request->getShipperAddressPostalCode());
        list(
$toZip5$toZip4) = $this->_parseZip($request->getRecipientAddressPostalCode(), true);

        
/*A.Humes
        if ($this->getConfigData('mode')) {
            $rootNode = 'SignatureConfirmationV3.0Request';
        } else {
            $rootNode = 'SigConfirmCertifyV3.0Request';
        }*/
    //A.Humes
    
$rootNode 'DeliveryConfirmationV3.0Request';
        
    
// the wrap node needs for remove xml declaration above
        
$xmlWrap = new SimpleXMLElement('<?xml version = "1.0" encoding = "UTF-8"?><wrap/>');
        
$xml $xmlWrap->addChild($rootNode);
        
$xml->addAttribute('USERID'$this->getConfigData('userid'));
        
$xml->addChild('Option'1);
        
$xml->addChild('ImageParameters');
        
$xml->addChild('FromName'$request->getShipperContactPersonName());
        
$xml->addChild('FromFirm'$request->getShipperContactCompanyName());
        
$xml->addChild('FromAddress1'$request->getShipperAddressStreet2());
        
$xml->addChild('FromAddress2'$request->getShipperAddressStreet1());
        
$xml->addChild('FromCity'$request->getShipperAddressCity());
        
$xml->addChild('FromState'$request->getShipperAddressStateOrProvinceCode());
        
$xml->addChild('FromZip5'$fromZip5);
        
$xml->addChild('FromZip4'$fromZip4);
        
$xml->addChild('ToName'$request->getRecipientContactPersonName());
        
$xml->addChild('ToFirm'$request->getRecipientContactCompanyName());
        
$xml->addChild('ToAddress1'$request->getRecipientAddressStreet2());
        
$xml->addChild('ToAddress2'$request->getRecipientAddressStreet1());
        
$xml->addChild('ToCity'$request->getRecipientAddressCity());
        
$xml->addChild('ToState'$request->getRecipientAddressStateOrProvinceCode());
        
$xml->addChild('ToZip5'$toZip5);
        
$xml->addChild('ToZip4'$toZip4);
        
$xml->addChild('WeightInOunces'$packageWeight);
        
$xml->addChild('ServiceType'$serviceType);
        
//$xml->addChild('WaiverOfSignature', $packageParams->getDeliveryConfirmation());
        
$xml->addChild('ImageType''PDF');

        
$xml $xmlWrap->{$rootNode}->asXML();
        return 
$xml;
    
}

Then in the _doShipmentRequest function, I modified the $requestXml, $api, $labelContent, and $trackingNumber variables, like this:

protected function _doShipmentRequest(Varien_Object $request)
    
{
        $this
->_prepareShipmentRequest($request);
        
$result = new Varien_Object();
        
$service $this->getCode('service_to_code'$request->getShippingMethod());
        
$recipientUSCountry $this->_isUSCountry($request->getRecipientAddressCountryCode());

        if (
$recipientUSCountry && $service == 'EXPRESS'{
            $requestXml 
$this->_formUsExpressShipmentRequest($request);
            
$api 'ExpressMailLabel';
        
else if ($recipientUSCountry{
           
/* A.Humes
        $requestXml = $this->_formUsSignatureConfirmationShipmentRequest($request, $service);
            if ($this->getConfigData('mode')) {
                $api = 'SignatureConfirmationV3';
            } else {
                $api = 'SignatureConfirmationCertifyV3';
            }
    */
    // A.Humes - Using our custom Delivery Confirmation function and $api value 
    
$requestXml $this->_formUsDeliveryConfirmationShipmentRequest($request$service);
    
$api 'DeliveryConfirmationV3';
        
else if ($service == 'FIRST CLASS'{
            $requestXml 
$this->_formIntlShipmentRequest($request);
            
$api 'FirstClassMailIntl';
        
else if ($service == 'PRIORITY'{
            $requestXml 
$this->_formIntlShipmentRequest($request);
            
$api 'PriorityMailIntl';
        
else {
            $requestXml 
$this->_formIntlShipmentRequest($request);
            
$api 'ExpressMailIntl';
        
}


        $debugData 
= array('request' => $requestXml);
        
$url $this->getConfigData('gateway_secure_url');
        if (!
$url{
            $url 
$this->_defaultGatewayUrl;
        
}
        $client 
= new Zend_Http_Client();
        
$client->setUri($url);
        
$client->setConfig(array('maxredirects'=>0'timeout'=>30));
        
$client->setParameterGet('API'$api);
        
$client->setParameterGet('XML'$requestXml);
        
$response $client->request()->getBody();

        
$response simplexml_load_string($response);
        if (
$response === false || $response->getName() == 'Error'{
            $debugData[
'result'= array(
                
'error' => $response->Description,
                
'code' => $response->Number,
                
'xml' => $response->asXML()
            );
            
$this->_debug($debugData);
            
$result->setErrors($debugData['result']['error']);
        
else {
            
if ($recipientUSCountry && $service == 'EXPRESS'{
                $labelContent 
base64_decode((string) $response->EMLabel);
                
$trackingNumber = (string) $response->EMConfirmationNumber;
            
else if ($recipientUSCountry{
                
// A.Humes
        //$labelContent = base64_decode((string) $response->SignatureConfirmationLabel);
                //$trackingNumber = (string) $response->SignatureConfirmationNumber;
        
$labelContent base64_decode((string) $response->DeliveryConfirmationLabel);
                
$trackingNumber = (string) $response->DeliveryConfirmationNumber;
            
else  {
                $labelContent 
base64_decode((string) $response->LabelImage);
                
$trackingNumber = (string) $response->BarcodeNumber;
            
}
            $result
->setShippingLabelContent($labelContent);
            
$result->setTrackingNumber($trackingNumber);
        
}

        $result
->setGatewayResponse($response);
        
$debugData['result'$response;
        
$this->_debug($debugData);
        return 
$result;
    
}

I went through the purchase process on the site, then when I went to print out a shipping label in the Admin, the label came up and shows “USPS Priority Mail” and “ZIP - e/USPS DELIVERY CONFIRM”, which is what I was looking for (previously it was “SIGNATURE CONFIRM").  I’m going to send out the package and make sure it works as expected before writing this one off, but for now I’m happy with the results.

Hope this helps you out.  Obviously make sure to save the original version of the file, and make sure your USPS account has DeliveryConfirmation api access.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 

Awesome!

Just to confirm, you made comments next to all the changes, correct? (In other words, if I just look for your comments, I’ll find everything you changed or added) ??

 
Magento Community Magento Community
Magento Community
Magento Community
 
austinhumes
Jr. Member
 
Total Posts:  5
Joined:  2010-11-26
 

Well, the first function is essentially a new one, but yes, I put comments in where the changes were.

 
Magento Community Magento Community
Magento Community
Magento Community
 
scud133
Member
 
Total Posts:  33
Joined:  2012-08-11
 
austinhumes - 22 September 2012 08:47 PM

Well, the first function is essentially a new one, but yes, I put comments in where the changes were.

I thought I made all those changes/additions but I’m still getting Sig Confirm labels.

First I just tried typing all your changes (so I could follow along better) and I still got Signature labels back. So now I just made a backup and went and copy/pasted your code over my old code, and I’m *still* getting Signature.

Did you make any special request for USPS web tools or anything? Or did you only modify usps.php as mentioned your post above?

 
Magento Community Magento Community
Magento Community
Magento Community
 
austinhumes
Jr. Member
 
Total Posts:  5
Joined:  2010-11-26
 
scud133 - 23 September 2012 06:16 AM

austinhumes - 22 September 2012 08:47 PM
Well, the first function is essentially a new one, but yes, I put comments in where the changes were.

I thought I made all those changes/additions but I’m still getting Sig Confirm labels.

First I just tried typing all your changes (so I could follow along better) and I still got Signature labels back. So now I just made a backup and went and copy/pasted your code over my old code, and I’m *still* getting Signature.

Did you make any special request for USPS web tools or anything? Or did you only modify usps.php as mentioned your post above?

Did you try printing a label on an existing order, or was it a new one?  I had to do a test transaction for a new order and go through the checkout process and select Priority Mail.  Then when I printed out the shipping label in the Admin it was correct.

The only thing for USPS web tools was making sure I had access to the DeliveryConfirmation API.

I’ve attached my edited version of the entire usps.php file.  As I mentioned earlier, I’m on Magento 1.7.0.2, so I’m not sure if there were any changes from prior versions that would affect anything.

File Attachments
Usps.php  (File Size: 75KB - Downloads: 142)
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2