Beispiel #1
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();
     }
 }
Beispiel #2
0
 public function locateByReceipt($receipt)
 {
     return TransactionFactory::factoryByReceipt($this, $receipt);
 }
Beispiel #3
0
 public function locateByTimeInterval($from, $until, $type)
 {
     $type = (int) $type;
     $lastSyncSetting = \PLUSPEOPLE\PesaPi\Base\SettingFactory::factoryByName("LastSync");
     $lastSync = $lastSyncSetting->getValue();
     $config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     $initSyncDate = strtotime($config->getConfig('MpesaInitialSyncDate'));
     // never go before initial sync date (not reliable to do so)
     if ($from <= 0 or $from < $initSyncDate) {
         $from = $initSyncDate;
     }
     if ($until <= 0) {
         $until = $lastSync;
     }
     // default is up until last sync, and no later to enhance default performance
     if ($until > $lastSync) {
         $this->forceSyncronisation();
     }
     return TransactionFactory::factoryByTimeInterval($from, $until, $type);
 }