function get_new_Transactions($session, $to) { $transaction_update_time = olc_db_query(SELECT . "transaction_update_time from " . TABLE_EBAY_CONFIG); $update_time = olc_db_fetch_array($transaction_update_time); $transaction_update_time = $update_time['transaction_update_time']; if ($transaction_update_time == NULL) { $event_first_time = olc_db_query(SELECT . "starttime" . SQL_FROM . TABLE_AUCTION_LIST . " ORDER BY starttime ASC"); $first_time = olc_db_fetch_array($event_first_time); $from = $first_time['starttime']; } else { $from = $transaction_update_time; } //update time $cs = new EbatNs_ServiceProxy($session); $req = new GetSellerTransactionsRequestType(); $req->setModTimeFrom($from); $req->setModTimeTo($to); $res = $cs->GetSellerTransactions($req); $transactions = $res->getTransactionArray(); if ($res->getAck() == 'Success') { for ($i = 0; $i < count($transactions); $i++) { $transaction = $transactions[$i]; $tmp[$transaction->Item->getItemID()][$transaction->getTransactionID()] = array('endtime' => $transaction->getCreatedDate(), 'price' => $transaction->Item->SellingStatus->CurrentPrice->value, 'amount' => $transaction->getQuantityPurchased(), 'buyerid' => $transaction->Buyer->getUserID(), 'buyer_name' => $transaction->Buyer->RegistrationAddress->getName(), 'buyer_email' => $transaction->Buyer->getEmail(), 'buyer_land' => $transaction->Buyer->BuyerInfo->ShippingAddress->getCountryName(), 'buyer_countrycode' => $transaction->Buyer->BuyerInfo->ShippingAddress->getCountry(), 'buyer_state' => $transaction->Buyer->BuyerInfo->ShippingAddress->getStateOrProvince(), 'buyer_zip' => $transaction->Buyer->BuyerInfo->ShippingAddress->getPostalCode(), 'buyer_city' => $transaction->Buyer->BuyerInfo->ShippingAddress->getCityName(), 'buyer_street' => $transaction->Buyer->BuyerInfo->ShippingAddress->getStreet(), 'buyer_phone' => $transaction->Buyer->getPhone()); } $update_time = olc_db_query(SQL_UPDATE . TABLE_EBAY_CONFIG . " SET `transaction_update_time` = '" . $to . APOS . SQL_WHERE . "`id` =1"); } return $tmp; }
/** * @return GetSellerTransactionsResponseType * @param GetSellerTransactionsRequestType $request */ function GetSellerTransactions($request) { $request->setVersion(EBAY_WSDL_VERSION); return $this->call('GetSellerTransactions', $request); }
function updateTransactions($session, $days = null, $current_page = 1) { WPLE()->logger->info('*** updateTransactions(' . $days . ') - page ' . $current_page); $this->initServiceProxy($session); // set request handler $this->_cs->setHandler('TransactionType', array(&$this, 'handleTransactionType')); // $this->_cs->setHandler( 'PaginationResultType', array( & $this, 'handlePaginationResultType' ) ); // build request $req = new GetSellerTransactionsRequestType(); $req->setIncludeContainingOrder(true); // check if we need to calculate lastdate if ($this->current_lastdate) { $lastdate = $this->current_lastdate; WPLE()->logger->info('used current_lastdate from last run: ' . $lastdate); } else { // period 30 days, which is the maximum allowed $now = time(); $lastdate = $this->getDateOfLastTransaction(); WPLE()->logger->info('getDateOfLastTransaction() returned: ' . $lastdate); if ($lastdate) { $lastdate = mysql2date('U', $lastdate); } // if last date is older than 30 days, fall back to default if ($lastdate < $now - 3600 * 24 * 30) { WPLE()->logger->info('resetting lastdate - fall back default '); $lastdate = false; } } // save lastdate for next page $this->current_lastdate = $lastdate; // parameter $days has priority if ($days) { $req->NumberOfDays = $days; $this->NumberOfDays = $days; WPLE()->logger->info('NumberOfDays: ' . $req->NumberOfDays); // default: transactions since last change } elseif ($lastdate) { $req->ModTimeFrom = gmdate('Y-m-d H:i:s', $lastdate); $req->ModTimeTo = gmdate('Y-m-d H:i:s', time()); $this->ModTimeFrom = $req->ModTimeFrom; $this->ModTimeTo = $req->ModTimeTo; WPLE()->logger->info('lastdate: ' . $lastdate); WPLE()->logger->info('ModTimeFrom: ' . $req->ModTimeFrom); WPLE()->logger->info('ModTimeTo: ' . $req->ModTimeTo); // fallback: last 7 days (max allowed by ebay: 30 days) } else { $days = 7; $req->NumberOfDays = $days; $this->NumberOfDays = $days; WPLE()->logger->info('NumberOfDays (fallback): ' . $req->NumberOfDays); } // $req->DetailLevel = $Facet_DetailLevelCodeType->ReturnAll; if (!$this->is_ajax()) { $req->setDetailLevel('ReturnAll'); } // set pagination for first page $items_per_page = 100; // should be set to 200 for production $this->current_page = $current_page; $Pagination = new PaginationType(); $Pagination->setEntriesPerPage($items_per_page); $Pagination->setPageNumber($this->current_page); $req->setPagination($Pagination); // get transactions (single page) WPLE()->logger->info('fetching transactions - page ' . $this->current_page); $res = $this->_cs->GetSellerTransactions($req); $this->total_pages = $res->PaginationResult->TotalNumberOfPages; $this->total_items = $res->PaginationResult->TotalNumberOfEntries; // get transaction with pagination helper (doesn't work as expected) // EbatNs_PaginationHelper($proxy, $callName, $request, $responseElementToMerge = '__COUNT_BY_HANDLER', $maxEntries = 200, $pageSize = 200, $initialPage = 1) // $helper = new EbatNs_PaginationHelper( $this->_cs, 'GetSellerTransactions', $req, 'TransactionArray', 20, 10, 1); // $res = $helper->QueryAll(); // handle response and check if successful if ($this->handleResponse($res)) { WPLE()->logger->info("*** Transactions updated successfully."); // WPLE()->logger->info( "*** PaginationResult:".print_r($res->PaginationResult,1) ); // WPLE()->logger->info( "*** processed response:".print_r($res,1) ); WPLE()->logger->info("*** current_page: " . $this->current_page); WPLE()->logger->info("*** total_pages: " . $this->total_pages); WPLE()->logger->info("*** total_items: " . $this->total_items); // fetch next page recursively - only in days mode if ($res->HasMoreTransactions) { $this->current_page++; $this->updateTransactions($session, $days, $this->current_page); } } else { WPLE()->logger->error("Error on transactions update" . print_r($res, 1)); } }