예제 #1
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);
 }
예제 #2
0
파일: PesaPi.php 프로젝트: nyashkn/pesaPi
 public function __construct()
 {
     $this->config = Configuration::instantiate();
     $this->initSyncDate = strtotime($this->config->getConfig('MpesaInitialSyncDate'));
     $this->lastSyncSetting = Base\SettingFactory::FactoryByName("LastSync");
 }
예제 #3
0
파일: Loader.php 프로젝트: nyashkn/pesaPi
 private function setPassword($input)
 {
     $pwSetting = \PLUSPEOPLE\PesaPi\Base\SettingFactory::factoryByName("MpesaPassword");
     if ($input != "" and is_object($pwSetting)) {
         $pwSetting->setValueString($input);
         $pwSetting->update();
         return true;
     }
     return false;
 }
예제 #4
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();
 }