Exemplo n.º 1
0
 public function forceSyncronisation()
 {
     return true;
     // determine the start time
     $lastSyncSetting = \PLUSPEOPLE\PesaPi\Base\SettingFactory::FactoryByName("LastSync");
     $lastSync = $lastSyncSetting->getValue();
     $config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     $initSyncDate = strtotime($config->getConfig('MpesaInitialSyncDate'));
     if ($lastSync <= $initSyncDate) {
         $startSyncTime = $initSyncDate;
     } else {
         $startSyncTime = $lastSync;
     }
     $startSyncTime -= 1;
     $now = time();
     // perform file fetch
     $loader = new MpesaPaybill\Loader();
     $pages = $loader->retrieveData($startSyncTime);
     // perform analysis/scrubbing
     $scrubber = new MpesaPaybill\Scrubber();
     foreach ($pages as $page) {
         $rows = $scrubber->scrubRows($page);
         // save data to database
         foreach ($rows as $row) {
             $payment = Transaction::import($row);
             if (is_object($payment)) {
                 $this->handleCallback($payment);
             }
         }
     }
     // save last entry time as last sync
     $this->lastSyncSetting->setValueDate($now);
     $this->lastSyncSetting->update();
 }