Beispiel #1
0
 public function availableBalance($time = null)
 {
     $time = (int) $time;
     if (0 == $time) {
         $time = time();
     }
     $balance = \PLUSPEOPLE\PesaPi\Base\TransactionFactory::factoryOneByTime($this, $time);
     if (is_object($balance)) {
         return $balance->getPostBalance();
     }
     return $amount;
 }
Beispiel #2
0
 public function availableBalance($time = null)
 {
     $time = (int) $time;
     $lastSyncSetting = \PLUSPEOPLE\PesaPi\Base\SettingFactory::factoryByName("LastSync");
     $lastSync = $lastSyncSetting->getValue();
     if ($lastSync < $time) {
         // we must have data all the way up to the specified time.
         $this->forceSyncronisation();
         // NOT DONE: Needs to be on the account
     }
     $balance = TransactionFactory::factoryOneByTime($this, $time);
     if (is_object($balance)) {
         return $balance->getPostBalance();
     }
     return $amount;
 }
Beispiel #3
0
 public function forceSyncronisation()
 {
     // determine the start time
     $settings = $this->getSettings();
     $lastSync = $settings["LAST_SYNC"];
     $now = time();
     // perform file fetch
     $loader = new Loader($this);
     $pages = $loader->retrieveData($lastSync);
     // perform analysis/scrubbing
     $scrubber = new Scrubber();
     foreach ($pages as $page) {
         $rows = $scrubber->scrubRows($page);
         // save data to database
         foreach ($rows as $row) {
             $tuple = Transaction::updateData($row, $this);
             if ($tuple[1] and is_object($tuple[0])) {
                 $this->handleCallback($tuple[0]);
             }
         }
     }
     // save last entry time as last sync - but only if any is found.
     // this way we are safeguarded against MPESA fallouts like the one of 3-5 November 2014
     $lastFound = \PLUSPEOPLE\PesaPi\Base\TransactionFactory::factoryOneByTime($this, $now);
     if (is_object($lastFound)) {
         $settings["LAST_SYNC"] = $lastFound->getTime();
         $this->setSettings($settings);
         $this->update();
     }
 }