Back to Top
Home
Design Center
Design Creation Specifications
Design Center User Guide
Tools
Account Settings
FAQ
Integration
Builder Commerce Guide
Step by Step
Integration Guide
Integration FAQ
Order Admin
Search
Back
Code Sample
Modified on 2016/05/23 14:38
by
cjones
Categorized as
Uncategorized
==Code Sample Library== <div id="page-menu"> ===Quick Links=== * [Integration-Guide|Overview & Posting Orders] * [XML-Specifications | XML Specifications] * [Product-Specifications | Product Specifications and Details] * [Shipping | Shipping and the EZP Shipping Calculator] * [Event-Notifications | Event Notifications, Order Status, and Errors] * [Testing | Testing] * [Code-Sample | Code Sample Library] ** [#_posting-order-xml-asp|Posting Order XML with ASP] ** [#_sample-posting-xml-vbnet|Sample function for posting XML in VB.Net] ** [#_posting-order-xml-php|Posting Order XML with PHP] ** [#_parse-notifications-php|Receive and Parse Event Notifications with PHP] ** [#_posting-shipping-calculator-perl|Posting to the Shipping Calculator with Perl] ** [#_calculating-pano-prints-js|Calculating Panoramic Prints Prices with Javascript] </div><h2>[anchor|#posting-order-xml-aspx]Posting Order XML with ASP</h2>HTTP Post using Microsofts' XMLDOM object. If you're using ASP, you can easily post orders directly from your server and bypass the need for HTML forms. The following is a sample of how to do this in ASP using VBScript: <pre><esc>' –– Create the object Set xmlPost = server.CreateObject ("MSXML2.XMLHTTP") ' –– Open a "POST" connection to the EZPrints Server. xmlPost.Open "POST", "http://order.ezprints.com/PostXmlOrder.axd?PartnerNumber=XXX &PartnerReference=yyy" or "https://order.ezprints.com/PostXmlOrder.axd?PartnerNumber=XXX &PartnerReference=yyy" </esc></pre> PartnerNumber corresponds to the partnerID and PartnerReference is the orderid you use (the orderid you are passing to us). You get a GUID (ezpreferencenum) in response. All XML is received, then unmarshalled into our order system later. You will receive immediate feedback if the order posted was not successful. The EZP orderid is assigned to your order when the XML is unmarshalled. <pre><esc> ' –– send the xml xmlPost.send strXML ' –– Retrieve the response Response.Write xmlPost.ResponseText </esc></pre> The above code assumes that strXML is the string you built from your order data in the format described in Order XML Format section. ===[anchor|#sample-posting-xml-vbnet]Sample function for posting XML in VB.Net=== <pre><esc> Public Shared Function PostString(ByVal Data As String, ByVal Url As String, _ ByVal encode As Encoding) As String Dim result As String Dim webRequest As WebRequest = WebRequest.Create(Url) webRequest.Method = "POST" Dim bdata As Byte() = encode.GetBytes(Data) webRequest.ContentLength = bdata.Length Using requestStream As Stream = webRequest.GetRequestStream requestStream.Write(bdata, 0, bdata.Length) End Using Using webResponse As WebResponse = webRequest.GetResponse Using memoryStream As MemoryStream = New MemoryStream Dim length As Long = FileTransfer.TransferBytes(webResponse.GetResponseStream, memoryStream, _ &H2000, Nothing, New TimeSpan(0, 5, 0), Nothing, Nothing, New WaitHandle(0 - 1) {}) result = encode.GetString(memoryStream.GetBuffer, 0, CInt(length)) End Using End Using Return result End Function Public Shared Function PostString(ByVal Data As String, ByVal Url As String) As String Return WebHelper.PostString(Data, Url, Encoding.UTF8) End Function </esc></pre> If you put these two functions in a class and then call the 2nd function with your string and URL, it will return the result. ===[anchor|#posting-order-xml-php]Posting Order XML with PHP=== Sample PHP code that will post an order using the text/xml content type to EZPrints Order Collection and pull out the reference number: <pre><esc> <?php $PartnerNumber = '1'; // Your Partner Number Here $PartnerReference = '––Your Order Reference Here––'; $OrderXml = '<Order Test="true">––Your Order XML Here––</Order>'; $urlConn = curl_init ("https://order.ezprints.com/PostXmlOrder.axd? PartnerNumber=".$PartnerNumber."&PartnerReference=".urlencode($PartnerReference)); curl_setopt ($urlConn, CURLOPT_POST, 1); curl_setopt ($urlConn, CURLOPT_HTTPHEADER, array("Content-type", "text/xml")); curl_setopt ($urlConn, CURLOPT_POSTFIELDS, $OrderXml); curl_setopt ($urlConn, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($urlConn, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($urlConn); if (empty($result)) { print "ERROR: " . curl_error($urlConn) . "\n"; exit; } // Parse the response $xml = simplexml_load_string($result); echo "Obj:\r\n"; print_r($xml); echo "Reference="; echo $xml->attributes()->Reference; ?> </esc></pre> Here is essentially the same sample PHP that will post an order using multipart/form-data content type to G2 Order Collection and pull out the reference number: <pre><esc> <?php $PartnerNumber = '1'; // Your Partner Number Here $PartnerReference = '––Your Order Reference Here––'; $OrderXml = '<Order Test="true">––Your Order XML Here––</Order>'; $OrderXml = 'xml='.urlencode($OrderXml); $urlConn = curl_init ("https://order.ezprints.com/PostXmlOrder.axd? PartnerNumber=".$PartnerNumber."&PartnerReference=".urlencode($PartnerReference)); curl_setopt ($urlConn, CURLOPT_POST, 1); // Can use application/x-www-urlencoded as well here curl_setopt ($urlConn, CURLOPT_HTTPHEADER, array("Content-type", "multipart/form-data")); curl_setopt ($urlConn, CURLOPT_POSTFIELDS, $OrderXml); curl_setopt ($urlConn, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($urlConn, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($urlConn); if (empty($result)) { print "ERROR: " . curl_error($urlConn) . "\n"; exit; } // Parse the response $xml = simplexml_load_string($result); echo "Obj:\r\n"; print_r($xml); echo "Reference="; echo $xml->attributes()->Reference; ?> </esc></pre> ===[anchor|#parse-notifications-php]Receive and Parse Event Notifications with PHP=== <pre><esc> <?php $xml=$HTTP_RAW_POST_DATA; $obj=simplexml_load_string($xml); echo "Obj:\r\n"; print_r($obj); echo "Test="; echo $obj->attributes()->Test; ?> </esc></pre> When this XML is posted: <pre><esc> <Order Test="true" /> </esc></pre> It responds by printing out the entire xml object and then getting the Test attribute of the root element and its value. Link to the documentation for the SimpleXML functions the above sample code uses: [http://us3.php.net/manual/en/book.simplexml.php | http://us3.php.net/manual/en/book.simplexml.php] ===[anchor|#posting-shipping-calculator-perl]Posting to the Shipping Calculator with Perl=== <pre><esc> // Generate an XML stringto send to EZPrints. $doc is a DOMDocument populated with // required EZPrints data. Alternatively the $ezPrintsXML string can be generated manually. $ezPrintsXML = $doc->saveXML(); // create a header array that specifies a blank content type. $header[] = "Content-type:"; // initialize CURL to use the EZPrints URL $ch = curl_init("http://g1order.ezprints.com/ezpartners/shippingcalculator/xmlshipcalc.asp"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Returns response data instead of TRUE curl_setopt($ch, CURLOPT_POST, true); // specify that POST should be used curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // set the customized headers curl_setopt($ch, CURLOPT_POSTFIELDS, $ezPrintsXML); // use HTTP POST to send data $resp = curl_exec($ch); //execute post and get results as string into $resp variable curl_close ($ch); // close the curl object // $resp is the response from EZPrints. This will output that result echo $resp; </esc></pre> ===[anchor|#calculating-pano-prints-js]Calculating Panoramic Print Prices with JavaScript=== Pano Length = (Pano Height x Image Length)/Image Height. So if you want to make a 10" high pano with a 1000x2000 image the length will be: (10 x 2000)/1000 = 20" long. ezprints will bill in 6" increments with a minimum of 12" so if the price for a 10" panorama is $2.00, the charge would be: Ceiling(20/6) * $2.00 or 4 * $2.00 = $8.00. Here is some actual JavaScript code that calculates this: <pre><esc> var panoPrice = skuHash.get( sku ).price; var panoLength = " "; var panoInches = 0; var qty6InSegments = ""; var imgWidth = Number( item.originalWidth ); var imgHeight = Number( item.originalHeight ); var paperWidthInches = parseInt( skuHash.get( sku ).description ); var segmentLength = 6; if( imgWidth > imgHeight ) panoInches = ( imgWidth/imgHeight ) * paperWidthInches; else panoInches = ( imgHeight/imgWidth ) * paperWidthInches; qty6InSegments = Math.ceil(panoInches / segmentLength ); if (qty6InSegments < 2) qty6InSegments = 2; // Minimum length is 12 inches. panoPrice = ( skuHash.get( sku ).price * qty6InSegments) panoLength = Math.round(panoInches) + ' in long'; </esc></pre>
Meta Keywords:
Meta Description:
Change Comment:
ezprints.com
|
Privacy
|
Terms of Use
|
Contact Us
|
Documentation
|
FAQ