function invokeListOrdersByNextToken(MarketplaceWebServiceOrders_Interface $service, $request, $tokens) { try { $response = $service->listOrdersByNextToken($request); echo '我执行了,invokeListOrdersByNextToken,,'; echo "Service Response\n"; echo "=============================================================================\n"; echo " ListOrdersByNextTokenResponse\n"; if ($response->isSetListOrdersByNextTokenResult()) { echo " ListOrdersByNextTokenResult\n"; $listOrdersByNextTokenResult = $response->getListOrdersByNextTokenResult(); if ($listOrdersByNextTokenResult->isSetCreatedBefore()) { echo " CreatedBefore\n"; echo " " . $listOrdersByNextTokenResult->getCreatedBefore() . "\n"; } if ($listOrdersByNextTokenResult->isSetLastUpdatedBefore()) { echo " LastUpdatedBefore\n"; echo " " . $listOrdersByNextTokenResult->getLastUpdatedBefore() . "\n"; } if ($listOrdersByNextTokenResult->isSetOrders()) { echo " Orders\n"; $orders = $listOrdersByNextTokenResult->getOrders(); $orderList = $orders->getOrder(); foreach ($orderList as $order) { $val = ''; if ($order->isSetSellerOrderId()) { // echo(" SellerOrderId\n"); // echo(" " . $order->getSellerOrderId() . "\n"); } if ($order->isSetPurchaseDate()) { $CreatedDate = strtotime($order->getPurchaseDate()); } if ($order->isSetLastUpdateDate()) { $PaidTime = strtotime($order->getLastUpdateDate()); } $orderstatus = ''; if ($order->isSetOrderStatus()) { if ($order->getOrderStatus() == 'Unshipped') { $orderstatus = 822; } } if ($order->isSetAmazonOrderId() && $orderstatus == '822') { $val = $order->getAmazonOrderId(); $request = new MarketplaceWebServiceOrders_Model_ListOrderItemsRequest(); $request->setSellerId(MERCHANT_ID); $request->setAmazonOrderId($val); if ($val != '') { invokeListOrderItems($service, $request, $val, $account); } } if ($order->isSetFulfillmentChannel()) { // echo(" FulfillmentChannel\n"); // echo(" " . $order->getFulfillmentChannel() . "\n"); } if ($order->isSetSalesChannel()) { // echo(" SalesChannel\n"); // echo(" " . $order->getSalesChannel() . "\n"); } if ($order->isSetOrderChannel()) { // echo(" OrderChannel\n"); // echo(" " . $order->getOrderChannel() . "\n"); } if ($order->isSetShipServiceLevel()) { // echo(" ShipServiceLevel\n"); // echo(" " . $order->getShipServiceLevel() . "\n"); } $Street1 = ''; $Street2 = ''; $CityName = ''; $StateOrProvince = ''; if ($order->isSetShippingAddress()) { $shippingAddress = $order->getShippingAddress(); if ($shippingAddress->isSetName()) { $Name = mysql_escape_string($shippingAddress->getName()); } if ($shippingAddress->isSetAddressLine1()) { $Street1 = mysql_escape_string($shippingAddress->getAddressLine1()); } if ($shippingAddress->isSetAddressLine2()) { $Street2 = mysql_escape_string($shippingAddress->getAddressLine2()); } if ($shippingAddress->isSetAddressLine3()) { // echo(" " . $shippingAddress->getAddressLine3() . "\n"); } if ($shippingAddress->isSetCity()) { $CityName = mysql_escape_string($shippingAddress->getCity()); } if ($shippingAddress->isSetCounty()) { $CountryName = $shippingAddress->getCounty(); } if ($shippingAddress->isSetDistrict()) { // echo(" " . $shippingAddress->getDistrict() . "\n"); } if ($shippingAddress->isSetStateOrRegion()) { $StateOrProvince = $shippingAddress->getStateOrRegion(); } if ($shippingAddress->isSetPostalCode()) { $PostalCode = $shippingAddress->getPostalCode(); } if ($shippingAddress->isSetCountryCode()) { $Country = $shippingAddress->getCountryCode(); } if ($shippingAddress->isSetPhone()) { $Phone = $shippingAddress->getPhone(); } } if ($order->isSetOrderTotal()) { $orderTotal = $order->getOrderTotal(); if ($orderTotal->isSetCurrencyCode()) { $Currency = $orderTotal->getCurrencyCode(); } if ($orderTotal->isSetAmount()) { $AmountPaid = $orderTotal->getAmount(); } } if ($order->isSetNumberOfItemsShipped()) { // echo(" " . $order->getNumberOfItemsShipped() . "\n"); } if ($order->isSetNumberOfItemsUnshipped()) { // echo(" " . $order->getNumberOfItemsUnshipped() . "\n"); } if ($order->isSetPaymentExecutionDetail()) { $paymentExecutionDetail = $order->getPaymentExecutionDetail(); $paymentExecutionDetailItemList = $paymentExecutionDetail->getPaymentExecutionDetailItem(); foreach ($paymentExecutionDetailItemList as $paymentExecutionDetailItem) { // echo(" PaymentExecutionDetailItem\n"); if ($paymentExecutionDetailItem->isSetPayment()) { // echo(" Payment\n"); $payment = $paymentExecutionDetailItem->getPayment(); if ($payment->isSetCurrencyCode()) { // echo(" CurrencyCode\n"); // echo(" " . $payment->getCurrencyCode() . "\n"); } if ($payment->isSetAmount()) { // echo(" Amount\n"); // echo(" " . $payment->getAmount() . "\n"); } } if ($paymentExecutionDetailItem->isSetSubPaymentMethod()) { // echo(" SubPaymentMethod\n"); // echo(" " . $paymentExecutionDetailItem->getSubPaymentMethod() . "\n"); } } } if ($order->isSetPaymentMethod()) { //echo(" PaymentMethod\n"); //echo(" " . $order->getPaymentMethod() . "\n"); } if ($order->isSetMarketplaceId()) { //echo(" MarketplaceId\n"); // echo(" " . $order->getMarketplaceId() . "\n"); } if ($order->isSetBuyerEmail()) { // echo(" BuyerEmail\n"); // echo(" " . $order->getBuyerEmail() . "\n"); $Email = $order->getBuyerEmail(); } if ($order->isSetBuyerName()) { $UserID = mysql_escape_string($order->getBuyerName()); } if ($order->isSetShipmentServiceLevelCategory()) { //echo(" ShipmentServiceLevelCategory\n"); // echo(" " . $order->getShipmentServiceLevelCategory() . "\n"); } $Country_q = countryname_change($Country); $sql = "INSERT INTO `ebay_order` (`ebay_paystatus`,`ebay_ordersn` ,`ebay_tid` ,`ebay_ptid` ,`ebay_orderid` ,"; $sql .= "`ebay_createdtime` ,`ebay_paidtime` ,`ebay_userid` ,`ebay_username` ,`ebay_usermail` ,`ebay_street` ,"; $sql .= "`ebay_street1` ,`ebay_city` ,`ebay_state` ,`ebay_couny` ,`ebay_countryname` ,`ebay_postcode` ,`ebay_phone`"; $sql .= " ,`ebay_currency` ,`ebay_total` ,`ebay_status`,`ebay_user`,`ebay_shipfee`,`ebay_account`,`recordnumber`,`ebay_addtime`,`ebay_note`,`ebay_site`,`eBayPaymentStatus`,`PayPalEmailAddress`,`ShippedTime`,`RefundAmount`,`ebay_warehouse`,`order_no`)VALUES ('Complete','{$val}', '{$tid}' , '{$ptid}' , '{$orderid}' , '{$CreatedDate}' , '{$PaidTime}' , '{$UserID}' ,"; $sql .= " '{$Name}' , '{$Email}' , '{$Street1}' , '{$Street2}' , '{$CityName}','{$StateOrProvince}' , '{$Country}' , '{$Country_q}' , '{$PostalCode}' , '{$Phone}' , '{$Currency}' , '{$AmountPaid}' , '{$orderstatus}','{$user}','{$shipingfee}','{$account}','" . ($addrecordnumber == '' ? $val : $addrecordnumber) . "','{$mctime}','{$BuyerCheckoutMessage}','{$site}','{$eBayPaymentStatus}','{$PayPalEmailAddress}','{$ShippedTime}','{$RefundAmount}','{$defaultstoreid}','{$order_no}')"; $sg = "select * from ebay_order where ebay_ordersn ='{$val}' "; $sg = $dbcon->execute($sg); $sg = $dbcon->getResultArray($sg); if (count($sg) == 0) { $dbcon->execute($sql); addLog("ordersn:{$val} 添加成功。"); } else { addLog("ordersn:{$val} 在数据库中已经存在。"); } } } if ($listOrdersByNextTokenResult->isSetNextToken()) { echo " NextToken\n"; echo " " . $listOrdersByNextTokenResult->getNextToken() . "\n"; $tokens = $listOrdersByNextTokenResult->getNextToken(); return $tokens; } else { return 0; } } if ($response->isSetResponseMetadata()) { echo " ResponseMetadata\n"; $responseMetadata = $response->getResponseMetadata(); if ($responseMetadata->isSetRequestId()) { echo " RequestId\n"; echo " " . $responseMetadata->getRequestId() . "\n"; } } } catch (MarketplaceWebServiceOrders_Exception $ex) { echo "Caught Exception: " . $ex->getMessage() . "\n"; echo "Response Status Code: " . $ex->getStatusCode() . "\n"; echo "Error Code: " . $ex->getErrorCode() . "\n"; echo "Error Type: " . $ex->getErrorType() . "\n"; echo "Request ID: " . $ex->getRequestId() . "\n"; echo "XML: " . $ex->getXML() . "\n"; } }
/** * Get Order Action Sample * This operation takes up to 50 order ids and returns the corresponding orders. * * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface * @param mixed $request MarketplaceWebServiceOrders_Model_GetOrder or array of parameters */ function invokeGetOrder(MarketplaceWebServiceOrders_Interface $service, $request) { global $user, $account, $dbcon, $defaultstoreid, $is_debug; try { $response = $service->getOrder($request); echo "Service Response\n"; echo "=============================================================================\n"; echo " GetOrderResponse\n"; if ($response->isSetGetOrderResult()) { echo " GetOrderResult\n"; $getOrderResult = $response->getGetOrderResult(); if ($getOrderResult->isSetOrders()) { echo " Orders\n"; $orders = $getOrderResult->getOrders(); $orderList = $orders->getOrder(); foreach ($orderList as $order) { echo " Order\n"; $val = ''; if ($order->isSetAmazonOrderId()) { $val = $order->getAmazonOrderId(); } if ($order->isSetSellerOrderId()) { // echo(" SellerOrderId\n"); // echo(" " . $order->getSellerOrderId() . "\n"); } if ($order->isSetPurchaseDate()) { $CreatedDate = strtotime($order->getPurchaseDate()); } if ($order->isSetLastUpdateDate()) { $PaidTime = strtotime($order->getLastUpdateDate()); } if ($order->isSetOrderStatus()) { if ($order->getOrderStatus() == 'Unshipped') { $orderstatus = 822; } } //comment by andy 20130518 if ($order->isSetAmazonOrderId() && $orderstatus == '822') { $val = $order->getAmazonOrderId(); } if ($order->isSetFulfillmentChannel()) { // echo(" FulfillmentChannel\n"); // echo(" " . $order->getFulfillmentChannel() . "\n"); } if ($order->isSetSalesChannel()) { // echo(" SalesChannel\n"); // echo(" " . $order->getSalesChannel() . "\n"); } if ($order->isSetOrderChannel()) { // echo(" OrderChannel\n"); // echo(" " . $order->getOrderChannel() . "\n"); } if ($order->isSetShipServiceLevel()) { // echo(" ShipServiceLevel\n"); // echo(" " . $order->getShipServiceLevel() . "\n"); } $Street1 = ''; $Street2 = ''; $CityName = ''; $StateOrProvince = ''; if ($order->isSetShippingAddress()) { $shippingAddress = $order->getShippingAddress(); if ($shippingAddress->isSetName()) { $Name = mysql_escape_string($shippingAddress->getName()); } if ($shippingAddress->isSetAddressLine1()) { $Street1 = mysql_escape_string($shippingAddress->getAddressLine1()); } if ($shippingAddress->isSetAddressLine2()) { $Street2 = mysql_escape_string($shippingAddress->getAddressLine2()); } if ($shippingAddress->isSetAddressLine3()) { // echo(" " . $shippingAddress->getAddressLine3() . "\n"); } if ($shippingAddress->isSetCity()) { $CityName = mysql_escape_string($shippingAddress->getCity()); } if ($shippingAddress->isSetCounty()) { $CountryName = $shippingAddress->getCounty(); } if ($shippingAddress->isSetDistrict()) { // echo(" " . $shippingAddress->getDistrict() . "\n"); } if ($shippingAddress->isSetStateOrRegion()) { $StateOrProvince = $shippingAddress->getStateOrRegion(); } if ($shippingAddress->isSetPostalCode()) { $PostalCode = $shippingAddress->getPostalCode(); } if ($shippingAddress->isSetCountryCode()) { $Country = $shippingAddress->getCountryCode(); } if ($shippingAddress->isSetPhone()) { $Phone = $shippingAddress->getPhone(); } } if ($order->isSetOrderTotal()) { $orderTotal = $order->getOrderTotal(); if ($orderTotal->isSetCurrencyCode()) { $Currency = $orderTotal->getCurrencyCode(); } if ($orderTotal->isSetAmount()) { $AmountPaid = $orderTotal->getAmount(); } } if ($order->isSetNumberOfItemsShipped()) { // echo(" " . $order->getNumberOfItemsShipped() . "\n"); } if ($order->isSetNumberOfItemsUnshipped()) { // echo(" " . $order->getNumberOfItemsUnshipped() . "\n"); } if ($order->isSetPaymentExecutionDetail()) { $paymentExecutionDetail = $order->getPaymentExecutionDetail(); $paymentExecutionDetailItemList = $paymentExecutionDetail->getPaymentExecutionDetailItem(); foreach ($paymentExecutionDetailItemList as $paymentExecutionDetailItem) { // echo(" PaymentExecutionDetailItem\n"); if ($paymentExecutionDetailItem->isSetPayment()) { // echo(" Payment\n"); $payment = $paymentExecutionDetailItem->getPayment(); if ($payment->isSetCurrencyCode()) { // echo(" CurrencyCode\n"); // echo(" " . $payment->getCurrencyCode() . "\n"); } if ($payment->isSetAmount()) { // echo(" Amount\n"); // echo(" " . $payment->getAmount() . "\n"); } } if ($paymentExecutionDetailItem->isSetSubPaymentMethod()) { // echo(" SubPaymentMethod\n"); // echo(" " . $paymentExecutionDetailItem->getSubPaymentMethod() . "\n"); } } } if ($order->isSetPaymentMethod()) { //echo(" PaymentMethod\n"); //echo(" " . $order->getPaymentMethod() . "\n"); } if ($order->isSetMarketplaceId()) { //echo(" MarketplaceId\n"); // echo(" " . $order->getMarketplaceId() . "\n"); } if ($order->isSetBuyerEmail()) { // echo(" BuyerEmail\n"); // echo(" " . $order->getBuyerEmail() . "\n"); $Email = $order->getBuyerEmail(); } if ($order->isSetBuyerName()) { $UserID = mysql_escape_string($order->getBuyerName()); } if ($order->isSetShipmentServiceLevelCategory()) { //echo(" ShipmentServiceLevelCategory\n"); // echo(" " . $order->getShipmentServiceLevelCategory() . "\n"); } if (empty($val)) { die("髪富amazon匡汽園催"); } $addrecordnumber = $val; $Country_q = countryname_change($Country); $mctime = time(); $Phone = htmlentities($Phone, ENT_QUOTES); $StateOrProvince = addslashes($StateOrProvince); if ($Country_q == 'France' || $Country_q == 'Germany') { if (empty($Street2) && !empty($Street1)) { $Street2 = $Street1; } if (!empty($Street2) && empty($Street1)) { $Street1 = $Street2; } if (empty($CityName) && !empty($StateOrProvince)) { $CityName = $StateOrProvince; } if (!empty($CityName) && empty($StateOrProvince)) { $StateOrProvince = $CityName; } } $sql = "INSERT INTO `ebay_order` (`ebay_paystatus`,`ebay_ordersn` ,`ebay_tid` ,`ebay_ptid` ,`ebay_orderid` ,"; $sql .= "`ebay_createdtime` ,`ebay_paidtime` ,`ebay_userid` ,`ebay_username` ,`ebay_usermail` ,`ebay_street` ,"; $sql .= "`ebay_street1` ,`ebay_city` ,`ebay_state` ,`ebay_couny` ,`ebay_countryname` ,`ebay_postcode` ,`ebay_phone`"; $sql .= " ,`ebay_currency` ,`ebay_total` ,`ebay_status`,`ebay_user`,`ebay_shipfee`,`ebay_account`,`recordnumber`,`ebay_addtime`,`ebay_note`,`ebay_site`,`eBayPaymentStatus`,`PayPalEmailAddress`,`ShippedTime`,`RefundAmount`,`ebay_warehouse`,`order_no`)VALUES ('Complete','{$val}', '{$tid}' , '{$ptid}' , '{$orderid}' , '{$CreatedDate}' , '{$PaidTime}' , '{$UserID}' ,"; $sql .= " '{$Name}' , '{$Email}' , '{$Street1}' , '{$Street2}' , '{$CityName}','{$StateOrProvince}' , '{$Country}' , '{$Country_q}' , '{$PostalCode}' , '{$Phone}' , '{$Currency}' , '{$AmountPaid}' , '{$orderstatus}','{$user}','{$shipingfee}','{$account}','{$addrecordnumber}','{$mctime}','{$BuyerCheckoutMessage}','{$site}','{$eBayPaymentStatus}','{$PayPalEmailAddress}','{$ShippedTime}','{$RefundAmount}','{$defaultstoreid}','{$order_no}')"; $sg = "select * from ebay_order where ebay_ordersn ='{$val}' "; $sg = $dbcon->execute($sg); $sg = $dbcon->getResultArray($sg); if (count($sg) == 0) { if ($dbcon->execute($sql)) { echo "ordersn:{$val} add successfully。"; addLog("ordersn:{$val} add successfully。"); } else { echo "ordersn:{$val} error <br>"; echo "sql:{$sql} <br>"; //addLog("ordersn:$val add successfully。"); } } else { echo "ordersn:{$val} has been in db。"; addLog("ordersn:{$val} has been in db。"); } } } } if ($response->isSetResponseMetadata()) { echo " ResponseMetadata\n"; $responseMetadata = $response->getResponseMetadata(); if ($responseMetadata->isSetRequestId()) { echo " RequestId\n"; echo " " . $responseMetadata->getRequestId() . "\n"; } } } catch (MarketplaceWebServiceOrders_Exception $ex) { echo "Caught Exception: " . $ex->getMessage() . "\n"; echo "Response Status Code: " . $ex->getStatusCode() . "\n"; echo "Error Code: " . $ex->getErrorCode() . "\n"; echo "Error Type: " . $ex->getErrorType() . "\n"; echo "Request ID: " . $ex->getRequestId() . "\n"; echo "XML: " . $ex->getXML() . "\n"; } }