Ejemplo n.º 1
0
 protected function __construct($type)
 {
     $this->config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     $this->db = new \mysqli($this->config->getConfig("DatabaseHost" . $type), $this->config->getConfig("DatabaseUser" . $type), $this->config->getConfig("DatabasePassword" . $type), $this->config->getConfig("DatabaseDatabase" . $type));
     if ($this->db->connect_errno) {
         print "DB connection error";
         exit;
     }
 }
Ejemplo n.º 2
0
 public function __construct($id, $initValues = NULL)
 {
     $this->id = (int) $id;
     $this->config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     #initValues is an object with values for fast restoring state (optimisation)
     if (isset($initValues)) {
         $this->assignValues($initValues);
     }
 }
Ejemplo n.º 3
0
 protected function __construct($type)
 {
     $this->config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     // if we need to use same credentials to the database then we need to use mysql_connect instead of mysql_pconnect.
     $this->dbId = mysql_pconnect($this->config->getConfig("DatabaseHost" . $type), $this->config->getConfig("DatabaseUser" . $type), $this->config->getConfig("DatabasePassword" . $type), true);
     if ($this->dbId > 0) {
         if (!mysql_select_db($this->config->getConfig("DatabaseDatabase" . $type), $this->dbId)) {
             exit;
         }
     }
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     $this->config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     if ($this->config->getConfig("SimulationMode")) {
         $this->baseUrl = "http://www.pesapi.ke";
     }
     $this->curl = curl_init($this->baseUrl);
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($this->curl, CURLOPT_COOKIESESSION, true);
     curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieFile);
     curl_setopt($this->curl, CURLOPT_HEADER, false);
     curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
     if (!$this->config->getConfig("SimulationMode")) {
         curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($this->curl, CURLOPT_SSLCERT, $this->config->getConfig("MpesaCertificatePath"));
         curl_setopt($this->curl, CURLOPT_SSLCERTTYPE, "PEM");
     }
 }
Ejemplo n.º 5
0
 public function __construct($account)
 {
     $this->account = $account;
     $this->settings = $account->getSettings();
     $this->config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     if ($this->config->getConfig("SimulationMode")) {
         $this->baseUrl = "http://www.pesapi.ke";
     }
     $this->cookieFile = tmpfile();
     $this->curl = curl_init($this->baseUrl);
     curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($this->curl, CURLOPT_COOKIESESSION, true);
     curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookieFile);
     curl_setopt($this->curl, CURLOPT_HEADER, true);
     curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true);
     if (TRUE or !$this->config->getConfig("SimulationMode")) {
         curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($this->curl, CURLOPT_SSLCERT, $this->settings["CERTIFICATE"]);
         curl_setopt($this->curl, CURLOPT_SSLCERTTYPE, "PEM");
     }
 }
Ejemplo n.º 6
0
 public function locateByTimeInterval($from, $until, $type)
 {
     $type = (int) $type;
     $settings = $this->getSettings();
     $lastSync = $settings["LAST_SYNC"];
     $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);
 }
Ejemplo n.º 7
0
 protected function credentialsOk()
 {
     $config = \PLUSPEOPLE\PesaPi\Configuration::instantiate();
     $dbId = @mysql_pconnect($config->getConfig("DatabaseHostRead"), $config->getConfig("DatabaseUserRead"), $config->getConfig("DatabasePasswordRead"), true);
     if ($dbId <= 0) {
         return false;
     }
     if (!mysql_select_db($config->getConfig("DatabaseDatabaseRead"), $dbId)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 public function __construct()
 {
     $this->config = Configuration::instantiate();
 }
Ejemplo n.º 9
0
 public function __construct()
 {
     $this->config = Configuration::instantiate();
     $this->initSyncDate = strtotime($this->config->getConfig('MpesaInitialSyncDate'));
     $this->lastSyncSetting = Base\SettingFactory::FactoryByName("LastSync");
 }
Ejemplo n.º 10
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();
 }