$username, 'password' => $password, 'trace' => true ); try { $client = new SoapClient(WSDL_SERVER, $config); $result = $client->getAccountInfo(); } catch( Exception $e ) { return false; } return true; } public static function downloadTransactions($username, $password, $filter_platform, $fromTS, $tillTS) { define('WSDL_SERVER', 'http://api.belboon.com/?wsdl'); $arr_filter_platform = explode(',', $filter_platform); $arr_filter_platform = array_map('trim', $arr_filter_platform); $arr_filter_platform = array_map('strtolower', $arr_filter_platform); $StartDate = date('Y-m-d', $fromTS); $EndDate = date('Y-m-d', $tillTS); $config = array( 'login' => $username, 'password' => $password, 'trace' => true ); $output_transactions = array(); $latest_timestamp = 0; try { $client = new SoapClient(WSDL_SERVER, $config); $result = $client->getEventList( null, // adPlatformIds null, // programId null, // eventType null, // eventStatus 'EUR', // eventCurrency $StartDate, // eventDateStart $EndDate, // eventDateEnd null, // eventChangeDateStart null, // eventChangeDateEnd array('eventdate' => 'ASC'), // orderBy null, // limit 0 // offset ); } catch (Expection $e) { //todo: error handling, mail to admin etc. return array(); } //print_r($result); foreach ($result->handler->events as $arr_transaction) { //print_r($transaction); $number = $arr_transaction['eventid']; $datetime_db = $arr_transaction['eventdate']; $sub_id = str_replace('subid=', '', $arr_transaction['subid']); $shop_id = $arr_transaction['programid']; $shop_name = $arr_transaction['programname']; $transaction_type = substr($arr_transaction['eventtype'], 0, 1); $price = $arr_transaction['netvalue']; $commission = $arr_transaction['eventcommission']; $checkdatetime_db = $arr_transaction['lastchangedate']; //we need the latest timestamp in case we have to get more transaction $timestamp = strtotime($datetime_db); if ($timestamp > $latest_timestamp) $latest_timestamp = $timestamp; //this has to happen after the latest timestamp stuff to calculate the right latest timestamp $platform = strtolower($arr_transaction['platformname']); if ( $filter_platform != '' && !in_array(html_entity_decode($platform), $arr_filter_platform) ) continue; if ($arr_transaction['eventstatus'] == 'PENDING') { $status = 'Open'; $confirmed = 0; } elseif ($arr_transaction['eventstatus'] == 'APPROVED') { $status = 'Confirmed'; $confirmed = $commission; } elseif ($arr_transaction['eventstatus'] == 'REJECTED') { $status = 'Cancelled'; $confirmed = 0; } $output_transactions[] = array( 'network' => 'belboon', 'number' => $number, 'datetime_db' => $datetime_db, 'sub_id' => $sub_id, 'shop_id' => $shop_id, 'shop_name' => $shop_name, 'transaction_type' => $transaction_type, 'price' => $price, 'commission' => $commission, 'confirmed' => $confirmed, 'checkdatetime_db' => $checkdatetime_db, 'status' => $status ); } //foreach //belboon can not track more than 500 sales with one call, so we need to call again if we run into that limit if (count($result->handler->events) >= 500) { unset($result); //save memory //echo $latest_timestamp.'
'; $additional_transactions = self::downloadTransactions($username, $password, $filter_platform, $filter, $latest_timestamp, $tillTS); //get more transactions starting at the latest timestamp of this call $output_transactions = array_merge($output_transactions, $additional_transactions); unset ($additional_transactions); //save memory } return $output_transactions; } //function } ?>