- <?php
- require_once 'Zend/Loader.php';
- //Mimeo Account Information
- $Mimeo_Root_URL = "https://connect.sandbox.mimeo.com/2010/09/";
- $Mimeo_User_Name = "[YOUR MIMEO EMAIL ADDRESS]";
- $Mimeo_Password = "[YOUR MIMEO PASSWORD]";
- //Actually Register the Printer
- $client = new Zend_Gdata_HttpClient();
- $client = $client->setClientLoginToken($_SESSION['Client_Login_Token']);
- $client->setHeaders('Authorization','GoogleLogin auth='.$_SESSION['Client_Login_Token']);
- $client->setHeaders('X-CloudPrint-Proxy','Mimeo');
- //GCP Services - Register
- $client->setUri('http://www.google.com/cloudprint/interface/fetch');
- // Your printer definition
- $Printer_ID = "[Your Printer ID]";
- //echo "Fetching: " . $Printer_ID . "<br />";
- $client->setParameterPost('printerid', $Printer_ID);
- $response = $client->request(Zend_Http_Client::POST);
- $JobResponse = json_decode($response->getBody());
- if(isset($JobResponse->jobs))
- {
- $Jobs = $JobResponse->jobs;
- // ----------------
- // Retrieve a list of print jobs for printer
- // ----------------
- foreach($Jobs as $Job)
- {
- $Job_ID = $Job->id;
- $Job_Title = $Job->title;
- $Job_Content_Type = $Job->contentType;
- $File_URL = $Job->fileUrl;
- $Job_NumberPages = $Job->numberOfPages;
- $Job_Status = $Job->status;
- $client->setUri($File_URL);
- $FileResponse = $client->request(Zend_Http_Client::POST);
- $FileContent = $FileResponse->getBody();
- // Set a local folder you wish to save print job PDF to.
- $Save_Filename = 'files/' . $Job_ID . ".pdf";
- //echo "Saving " . $Save_Filename . "<br />";
- $fh = fopen($Save_Filename, "w");
- if($fh==false)
- die("unable to create file");
- fputs($fh,$FileContent,strlen($FileContent));
- fclose ($fh);
- // Set a Full URL for your File
- $Print_Job_URL = "http://yourdomain.com/" . $Save_Filename;
- // ----------------
- // Begin Send a Print Job to Mimeo
- // ----------------
- // Order Delivery Information - Where Are You Sending? Users Info Should be Registered Somewhere
- $CompanyName = "";
- $FirstName = "";
- $LastName = "";
- $Name = "";
- $CareOf = "";
- $Street = "";
- $ApartmentOrSuite = "";
- $StateOrProvince = "";
- $City = "";
- $PostalCode = "";
- $Country = "";
- $IsResidential = "";
- $TelephoneNumber ="";
- $Email= "";
- // billing card info - Do not include if account credit or credit card
- $NameOnCard= "";
- $Number= "";
- $BillingPostalCode= "";
- $CreditCardType= "";
- $ExpirationMonth= "";
- $ExpirationYear= "";
- // Create a new product for ordering in the Mimeo system.
- $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
- $template = "custom";
- $url = "OrderService/NewProduct?template=" . $template . "&documentTemplateId=" . $Document_ID;
- $rest->createRequest($url,"GET","");
- $rest->sendRequest();
- $output = $rest->getResponseBody();
- $OrderTemplate = $output;
- $xml = new SimpleXMLElement($output);
- $OrderXML = new SimpleXMLElement($output);
- //Set these source of Document to be the PDF that is coming from Google Apps - Google Cloud Print
- $xml->Product->Content->DocumentSection[0]->Source = $Job_URL;
- // Set Shipping Information
- $xml->Addresses->RecipientAddress->CompanyName = $CompanyName;
- $xml->Addresses->RecipientAddress->Name = $Name;
- $xml->Addresses->RecipientAddress->FirstName = $FirstName;
- $xml->Addresses->RecipientAddress->LastName = $LastName;
- $xml->Addresses->RecipientAddress->CareOf = $CareOf;
- $xml->Addresses->RecipientAddress->Street = $Street;
- $xml->Addresses->RecipientAddress->ApartmentOrSuite = $ApartmentOrSuite;
- $xml->Addresses->RecipientAddress->City = $City;
- $xml->Addresses->RecipientAddress->StateOrProvince = $StateOrProvince;
- $xml->Addresses->RecipientAddress->PostalCode = $PostalCode;
- $xml->Addresses->RecipientAddress->Country = $Country;
- $xml->Addresses->RecipientAddress->TelephoneNumber = $TelephoneNumber;
- $xml->Addresses->RecipientAddress->Email = $Email;
- $xml->Addresses->RecipientAddress->IsResidential = $IsResidential;
- ///Set the order quantity
- $xml->Details->OrderQuantity = "1";
- //Set the XML to Send Back
- $SendXML = $xml->asXML();
- // Get the shipping options for this new product, with applied shipping information.
- // Currently just pulls the 1 to 3 Days entry entry, it can be updated to be more logical
- $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
- $url = "OrderService/GetShippingOptions";
- $rest->createRequest($url,"POST","");
- $rest->setHeader("Content-Type","application/xml");
- $rest->setBody($SendXML);
- $rest->sendRequest();
- $shipopts = $rest->getResponseBody();
- //Store Order Template for Manipulation
- $xml = new SimpleXMLElement($shipopts);
- $ShippingChoice = "";
- $_SESSION['Shipping'] = "";
- foreach ($xml->Details->ShippingOptions->ShippingOption as $ShippingOption)
- {
- if($ShippingOption->Name == '1 to 3 Days')
- {
- $ShippingChoice = $ShippingOption->Id;
- $ShippingChoiceName = $ShippingOption->Name;
- $Shipping_Choice = $ShippingChoice;
- $Shipping_Choice_Name = trim(strip_tags($ShippingChoiceName));
- }
- }
- ///Set the order ShippingChoice for the Order
- $xml->Details->ShippingChoice = $ShippingChoice;
- $xml->Details->ShippingOptions = "";
- //Set the XML to Send Back
- $SendXML = $xml->asXML();
- // Get the Quote for this Order
- $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
- $url = "OrderService/GetQuote";
- $rest->createRequest($url,"POST","");
- $rest->setHeader("Content-Type","application/xml");
- $rest->setBody($SendXML);
- $rest->sendRequest();
- $orderquote = $rest->getResponseBody();
- $xml = new SimpleXMLElement($orderquote);
- $OrderQuantity = $xml->Details->OrderQuantity;
- $ProductPrice = number_format(round($xml->Details->ProductPrice,4), 2, '.', ',');
- $ShippingPrice = number_format(round($xml->Details->ShippingPrice,4), 2, '.', ',');
- $TotalPrice = number_format(round($xml->Details->TotalPrice,4), 2, '.', ',');
- echo "<h3>Order Details</h3><ul>";
- echo "<li><strong>Quantity:</strong> " . $OrderQuantity . "</li>";
- // Set the Billing Information (If Applies)
- $xml->Payment->PaymentMethodType = "CreditCard";
- $xml->Payment->CreditCard->NameOnCard = $NameOnCard;
- $xml->Payment->CreditCard->Number = $Number;
- $xml->Payment->CreditCard->BillingPostalCode = $BillingPostalCode;
- $xml->Payment->CreditCard->CreditCardType = $CreditCardType;
- $xml->Payment->CreditCard->ExpirationMonth = $ExpirationMonth;
- $xml->Payment->CreditCard->ExpirationYear = $ExpirationYear;
- //Set the XML to Send Back and Place Order
- $SendXML = $xml->asXML();
- $rest = new MimeoRESTClient($Mimeo_Root_URL,$Mimeo_User_Name,$Mimeo_Password);
- $url = "OrderService/PlaceOrder";
- $rest->createRequest($url,"POST","");
- $rest->setHeader("Content-Type","application/xml");
- $rest->setBody($SendXML);
- $rest->sendRequest();
- $orderinfo = $rest->getResponseBody();
- $xml = new SimpleXMLElement($orderinfo);
- $OrderID = $xml->Details->OrderId;
- $OrderFriendlyId = $xml->OrderFriendlyId;
- // ----------------
- // End Send a Print Job to Mimeo
- // ----------------
- // ----------------
- // Begin Update Status of Google Cloud Print Job
- // ----------------
- //Update Status of the Print Job with Google
- $client = Zend_Gdata_ClientLogin::getHttpClient($G_Email, $G_Pass, 'cloudprint');
- $Client_Login_Token = $client->getClientLoginToken();
- $client->setHeaders('Authorization','GoogleLogin auth='.$Client_Login_Token);
- $client->setHeaders('X-CloudPrint-Proxy','Mimeo');
- //GCP Services - Register
- $client->setUri('http://www.google.com/cloudprint/interface/control');
- $client->setParameterPost('jobid', $Job_ID);
- $client->setParameterPost('status', 'Done');
- $response = $client->request(Zend_Http_Client::POST);
- $PrinterResponse = json_decode($response->getBody());
- // ----------------
- // End Update Status of Google Cloud Print Job
- // ----------------
- }
- }
- ?>