} else { if ($is_add_valid == "False") { $error_message = "The Item is not available to add to the cart"; } } if ($is_add_valid == "True") { $cart = array(); $cart["id"] = trim($cart_results->CartId[0]); $cart["HMAC"] = trim($cart_results->HMAC[0]); $cart["price"] = trim($cart_results->CartItems->SubTotal->FormattedPrice[0]); $cart["purchaseUrl"] = trim($cart_results->PurchaseURL[0]); $cart["items"] = array(); } } else { // we already have the cart, so modify it $amazon_client = new AmazonClient($key, "SOAP"); $cart_results = $amazon_client->CartAdd($cart["id"], $cart["HMAC"], array($asin => $number)); $is_add_valid = $cart_results->Request->IsValid; if ($cart_results->Request != NULL && $cart_results->Request->Errors != NULL && $cart_results->Request->Errors->Error != NULL) { $error_message = trim($cart_results->Request->Errors->Error[0]->Message . ""); $is_add_valid = "False"; } else { if ($is_add_valid == "False") { $error_message = "The Item is not available to add to the cart"; } } if ($is_add_valid == "True") { $cart["HMAC"] = trim($cart_results->HMAC[0]); $cart["price"] = trim($cart_results->CartItems->SubTotal->FormattedPrice[0]); } else { if ($is_add_valid == "False") {
<?php /** * Simple demonstration using PHP Class Library to consume Amazon Web Services */ /* Please replace this with your own amazon key You can retrieve this from http://aws.amazon.com */ $key = "your_amazon_key"; /* creating the AmazonClient object */ require_once "AmazonClient.php"; $amazon_client = new AmazonClient($key, "SOAP"); /************************************************************************/ /* Invoking the ItemSearch operation */ $items = $amazon_client->ItemSearch("Web Services Sanjiva", "Books"); foreach ($items->Item as $item) { echo $item->ASIN . ". "; echo $item->ItemAttributes->Title . " - "; #echo $item->DetailPageURL. " - "; echo $item->ItemAttributes->Author . "\n"; } /************************************************************************/ /* Invoking the ItemLookup operation */ $lookups = $amazon_client->ItemLookup("0131488740"); echo $lookups->Item->ASIN . ". "; echo $lookups->Item->ItemAttributes->Title . " - "; echo $lookups->Item->ItemAttributes->Author . "\n"; /************************************************************************/ /* Invoking the CartCreate operation */ $cart = $amazon_client->CartCreate(array("0131488740" => 5)); echo $cart->CartId . " - "; echo $cart->CartItems->SubTotal->FormattedPrice . "\n";
* * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* Extract the arguments from HTTP GET request */ $amazon_query = $_GET["amazon_query"]; $amazon_index = $_GET["amazon_index"]; $amazon_key = $_GET["amazon_key"]; $page = $_GET["page"]; /* Call service only if the query is set, ignore otherwise */ if (isset($amazon_query) && !empty($amazon_query) && isset($amazon_key)) { require_once "wso2/amazon/AmazonClient.php"; $amazon_client = new AmazonClient($amazon_key); $res = $amazon_client->itemSearch($amazon_query, $amazon_index, $page); /* Check for the soap - fault */ if ($res["soap-fault"]) { $soap_reason = $res["soap-fault-reason"]; printf("SOAP fault : {$soap_reason}\n"); } elseif ($res["error"]) { $error_message = $res["error-msg"]; printf("Error Message: {$error_message}\n"); } elseif ($res["results"] != NULL) { $pages = $res["pages"]; /* Render the numbers to display, This allows access by page number */ $next_exist = true; $prev_exist = true; $end_list = 10; if ($pages - $page <= $end_list) {