$value) { $key = str_replace("%7E", "~", rawurlencode($key)); $value = str_replace("%7E", "~", rawurlencode($value)); $queryParamsUrl[] = $key."=".$value; } // glue all the "params=value"'s with an ampersand $signature['queryUrl']= implode("&", $queryParamsUrl); // we'll use this string to make the signature $StringToSign = $signature['method']."\n".$signature['host']."\n".$signature['uri']."\n".$signature['queryUrl']; // make signature $signature['string'] = str_replace("%7E", "~", rawurlencode( base64_encode( hash_hmac("sha256",$StringToSign,$secret,True ) ) ) ); return $signature; } function getSignedUrl($params, $key, $secret, $assoc) { // This function creates a complete Amazon request with the appropriate signature $signature = generateSignature($params, $key, $secret, $assoc); return $signedUrl= "http://".$signature['host'].$signature['uri'].'?'.$signature['queryUrl'].'&Signature='.$signature['string']; } function load_form($message='') { global $NYT_API; global $server_path; //Display form to allow user to select NYT Bestseller List to look at $nyt_bestseller_lists = 'http://api.nytimes.com/svc/books/v2/lists/names.xml?api-key=' . $NYT_API ; // go get the XML $xml = simplexml_load_file($nyt_bestseller_lists); $html = '
Sorry you cannot send this order to Amazon as it has already been submitted.'; $message = $message . '
Search for another order number.
'; } if (isset($message)) { $html .= $message; } $html .= 'Order Number: ' . $id . '
'; $html .= 'Order Date: ' . $order_date->toString(' mm/dd/yyyy') . '
'; if (isset($submitted_date)) { $html .= 'Order Submitted Date: ' . $submitted_date->toString(' mm/dd/yyyy hh:mm:ss') . '
'; } $html .= 'Vendor: ' . $vendor_name . '
'; if ($order_total > 0) { $html .= 'Order Total: ' . $order_total . ' ' . $currency . '
'; } $html .= 'There was an error connecting to the server, please try again!
"; } return $html; } function create_order($books){ $order_date = Zend_Date::now(); $order = new Order(); $order->content->vendor->vendorId = '640c99b4-0b62-4c6b-9346-846fc9156da9'; $order->content->orderName = 'Amazon Order of NYT Items - No Shelving Location - '.time(); $order->content->orderNumberRange = 'default'; $order->content->currency = 'USD'; $order->content->exchangeRate = 1; $order->create(); if ( $order->hasPO() ): foreach ($books as $book): $item = new Item(); $resource->oclcNumber = $book['oclcnumber']; $item->content->resources->resource = array(array("worldcatResource" => $resource)); $copyConfig->copyCount = $book['copyCount']; $copyConfig->branchId = BRANCH_ID; $copyConfig->shelvingLocationId = 'MAIN-STACKS'; $copyConfig->orderStatus = 'OPEN'; $copyConfig->purchaseStatus = 'NO'; $item->content->copyConfigs->copyConfig = array($copyConfig); $item->content->quantity = $book['copyCount']; $item->content->orderingPrice = $book['price']; $order->addItem($item); endforeach; endif; $order_info['order_id'] = $order->getPO(); return $order_info; } function update_order_status($id, $status){ global $order_service_url; $request = $order_service_url . $id; $client = new Zend_Http_Client(); $client->setUri($request); $client->setConfig(array( 'maxredirects' => 2, 'strictredirects' => true)); $client->setHeaders('Accept: application/json'); $response = $client->request(); // have the JSON need to change the field and pass back $order = Zend_Json::decode($response); $order['status'] = $status; $updated_order = Zend_Json::encode($order); $update_request = $order_service_url . $id; $client->setUri($update_request); $response = $client->setRawData($updated_order, 'application/json')->request('PUT'); // check to make sure change made if ($response->isSuccessful()) { $message = 'Order has been moved to a SUBMITTED status is WMS.
'; } else { $message = 'The status of this order could not be updated.
'; //Debugging message info - uncomment to see what the server is doing //$message = $message . 'URL Requested: ' . $order_create_url . '
Status: ' . $response->getStatus() . '
Message: ' . $response->getMessage() . '
Sorry not all these items could be added to the cart.
'; // List items that couldn't be added to the cart $message = $message . 'The following items were not added to the cart:
'; $message = $message . 'Please update your order then recreate the cart
'; // Reload the order list and allow user to edit load_order($order_id, true, $message); } else { $cart_url = $xml->Cart->PurchaseURL; $subtotal = $xml->Cart->SubTotal->FormattedPrice; $message = 'Amazon Cart Successfully Created
'; $message = $message . ''; $message = $message . 'Subtotal: ' . $subtotal . '
'; $html = load_order($id, false, $message); } } } else { // Create a error message for order submitted $message = 'Sorry this order has already been submitted. You cannot resubmit it.
'; $html = load_order($id, false, $message); } return $html; } if (isset($_REQUEST['step'])) { $step = $_REQUEST['step']; } else { $step = ''; } switch ($step) { case "show_nyt_lists": if ((strlen($_REQUEST['list-name']) > 0) and (strlen($_REQUEST['oclcSym']) > 0)) { $list_id = $_REQUEST['list-name']; $oclcSym = urlencode($_REQUEST['oclcSym']); // Load the order list $html = load_list($list_id, $oclcSym); } else { $message = "Please make sure that you've selected a list and input and OCLC Symbol before searching for a list.
"; $html = load_form($message); } break; case "order": if (isset($_REQUEST['books'])) { // Need to parse the form data and create a books array $to_order = $_REQUEST['books']; $books = array(); foreach ($to_order as $book) { if (isset($_REQUEST[$book . '_copies'])) { $copies = $_REQUEST[$book . '_copies']; } else { $copies = "1"; } $price = $_REQUEST[$book . '_price']; $b = array(); $b['oclcnumber'] = $book; $b['copyCount'] = $copies; $b['price'] = $price; $books[] = $b; } $response = create_order($books); if (isset($response['order_id'])) { $order_id = $response['order_id']; $html = place_order($order_id); } else { $html = $response['message']; } } elseif (isset($_REQUEST['list-name']) and isset($_REQUEST['oclcSym'])) { $list_id = $_REQUEST['list-name']; $oclcSym = $_REQUEST['oclcSym']; $message = 'Please select at least one book you want to order.
'; $html = load_list($list_id, $oclcSym, $message); } else { $html = "Error
"; } break; case "update": if (isset($_REQUEST['order_id']) and isset($_REQUEST['item_id'])) { $order = new Order(); $order->getById(''); $failed_ids = array(); foreach($_REQUEST['item_id'] as $item_id) { $item = new Item(); $item->getById($order, $item_id); if( !$item->delete() ): $failed_ids[] = $item_id; endif; } if (sizeof($failed_ids) >= 1) { // Build message that shows all ids that couldn't be removed $message = 'The following items on the order could not be removed: ' . implode(", ", $failed_ids). '
'; } else { $message = 'Items successfully removed from the order.
'; } // Reload the order list $html = load_order($order_id, true, $message); } else { $html = 'Error. You cannot update an order without order ID and item id information.
'; } break; default: //Display form to allow user to select NYT Bestseller List to look at $html = load_form(); } ?>