My original intent was to use native PHP functionality to submit jobs to the SOAP server. Due to (my IIS) server configuration and a general lack of ambition to troubleshoot the issues I have encountered, I have decided to use Curl.
Here is the code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$endpoint_url = "https://services.printable.com/trans/1.0/PackingSlip.asmx?wsdl";
$soap_action_url = "http://www.printable.com/WebService/PackingSlip/CreatePackingSlipByLineItem";
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pac="http://www.printable.com/WebService/PackingSlip">
<soapenv:Header/>
<soapenv:Body>
<pac:CreatePackingSlipByLineItem>
<pac:pRequest>
<PartnerCredentials>
<Token>TOKEN_STRING</Token>
</PartnerCredentials>
<PackingSlipNode>
<PackingSlipNumber>PACKINGSLIPNUMBER_STRING</PackingSlipNumber>
<ShipDate>SHIPDATE_DATE</ShipDate>
<CarrierName>CARRIERNAME_STRING</CarrierName>
<TrackingNumber>TRACKINGNUMBER_STRING</TrackingNumber>
<ShipCost>SHIPCOST_FLOAT</ShipCost>
<SkipAdjustInventory>BOOL</SkipAdjustInventory>
<ShipToAddress>
<Attention>ATTENTION_STRING</Attention>
<Name>NAME_STRING</Name>
<Address1>ADDR1_STRING</Address1>
<Address2>ADDR2_STRING</Address2>
<Address3>ADDR3_STRING</Address3>
<Address4>ADDR4_STRING</Address4>
<City>CITY_STRING</City>
<State>STATE_STRING</State>
<PostalCode>ZIP_STRING</PostalCode>
<Country>COUNTRY_STRING</Country>
</ShipToAddress>
</PackingSlipNode>
<LineItems>
<LineItem>
<ID type="Printable">LINE_ITEM_ID_STRING</ID>
<Quantity>QTY_INT</Quantity>
</LineItem>
</LineItems>
</pac:pRequest>
</pac:CreatePackingSlipByLineItem>
</soapenv:Body>
</soapenv:Envelope>';
$send_payload_response = send_payload($endpoint_url, $soap_action_url, $xml);
var_dump($send_payload_response);
exit;
/********************************************
* Sends an XML payload to the SOAP server of your choice
*
* @param string $endpoint_url
* @param string $soap_action_url
* @param string $xml
* @param array $headers
*/
function send_payload($endpoint_url, $soap_action_url, $xml, $headers = array()) {
$default_headers = array(
'Content-Type: text/xml; charset="utf-8"',
'Content-Length: ' . strlen($xml),
'SOAPAction: "' . $soap_action_url . '"'
);
if(count($headers) == 0)
$headers = $default_headers;
if( ! function_exists('curl_version'))
die("cURL is not installed. Please relay this error to your friendly neighborhood webmaster.");
$c = curl_init();
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($c, CURLOPT_URL, $endpoint_url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_setopt($c, CURLOPT_HEADER, 1);
curl_setopt($c, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($c, CURLOPT_POST, TRUE);
curl_setopt($c, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($c);
// debug
// echo "<pre>" . htmlentities($xml) . "<hr>" . var_dump($response); exit;
return $response;
}