Beispiel #1
0
 /**
  * Tests the `__construct` method.
  *
  * @return void
  * @access public
  */
 public function test__construct()
 {
     $this->_object = new \Postman\Library\Email\Address\Recipient('*****@*****.**', 'cc');
     $this->assertIdentical($this->_object->getAddress(), '*****@*****.**');
     $this->assertIdentical($this->_object->getType(), 'cc');
     // This should throw an exception since it's not a valid recipient type.
     $this->expectException();
     $this->_object = new \Postman\Library\Email\Address\Recipient('*****@*****.**', 'fail');
 }
Beispiel #2
0
 /**
  * Save the model
  * @param string $modelName
  */
 public function save()
 {
     if (!$this->isNewRecord()) {
         $this->message = 'Failed, order allready exists';
         return false;
     }
     //Merge the address data into this model
     $this->setAttributes($this->billingAddress->getAddress('BillingAddress'));
     $this->setAttributes($this->shippingAddress->getAddress('DeliveryAddress'));
     return parent::save();
 }
Beispiel #3
0
 public static function getChurches()
 {
     $dados = Database::ReadAll("church", "*");
     if (!$dados) {
         return '';
     }
     foreach ($dados as $dado) {
         $church = new Church();
         $church->setId($dado['ID_CHURCH']);
         $church->setName($dado['NAME_CHURCH']);
         $church->setPastor($dado['NAME_PASTOR']);
         $church->setStatus($dado['STATUS']);
         $address = Address::getAddress('AND a.id_address = ' . $dado['ID_ADDRESS']);
         $church->setAddress($address);
         $churches[] = $church;
     }
     return $churches;
 }
 /**
  * Callback is initiated when:
  * Receiving transaction gets into mempool
  * Sending out transaction - has negative amount
  * Transaction gets 1st confirmation
  * This is most important function in whole thing, but very spaghetti. Has to be refactored
  */
 public function callback()
 {
     Log::info('=== CALLBACK. ' . 'User id: ' . Input::get('userid') . ', tx hash: ' . Input::get('txid'));
     /* the url structure is different, so different segments of URI */
     if (Input::get('cryptotype')) {
         $this->crypto_type_id = Input::get('cryptotype');
     }
     $server_callback_secret = Config::get('bitcoin.callback_secret');
     if ($server_callback_secret != Input::get('secret')) {
         Log::error('#callback: ' . SECRET_MISMATCH . ', full URL:  ' . Request::fullUrl());
         return Response::json(['#callback: ' . SECRET_MISMATCH]);
     }
     /*--------------------------------------------*/
     /*sends callback on receive notification
     		gets a transaction hash id
     		calls bitcoind via RPC to get transaction info
     		calls a web url specified in the user account
     		called from /home/api/walletnotify.sh
     		sudo curl http://127.0.0.1/api/callback/?txid=a6eb6a8c2a66dbdfeb87faf820492222a80c2db3422706bdc1eb3bff0dbe8ab1&local=n00nez&loginname=ammm&password=PsQWsO4sDLwqTxxx&debug=1*/
     $tx_id = Input::get('txid');
     // check if not null
     if (!$tx_id) {
         Log::error("#callback, no tx id: " . NO_TX_ID);
         return Response::json(['error' => NO_TX_ID]);
     }
     $user_id = Input::get('userid');
     if (!$user_id) {
         // TODO daaaaamn
         // return here with error
     }
     $this->user = User::find($user_id);
     $bitcoind_timestamp = Input::get('time');
     // TODO if user is not set here. decide how to set user
     $this->bitcoin_core->setRpcConnection($this->user->rpc_connection);
     try {
         $tx_info = $this->bitcoin_core->gettransaction($tx_id);
     } catch (Exception $e) {
         Log::error('#callback: get transaction exception: ' . $e->getMessage());
         return Response::json(['error' => '#callback: get transaction exception: ' . $e->getMessage()]);
     }
     $confirms = $tx_info['confirmations'];
     $block_hash = isset($tx_info['blockhash']) ? $tx_info['blockhash'] : null;
     $block_index = isset($tx_info['blockindex']) ? $tx_info['blockindex'] : null;
     $block_time = isset($tx_info['blocktime']) ? $tx_info['blocktime'] : null;
     $time = $tx_info['time'];
     $time_received = $tx_info['timereceived'];
     $fee = isset($tx_info['fee']) ? abs(bcmul($tx_info['fee'], SATOSHIS_FRACTION)) : null;
     $transaction_details = $tx_info["details"];
     foreach ($transaction_details as $tx) {
         $to_address = $tx['address'];
         // address where transaction was sent to. from address may be multiple inputs which means many addresses
         $account_name = $tx['account'];
         $address_from = '';
         //always blank as there is no way to know where bitcoin comes from UNLESS we do get rawtransaction
         $category = $tx['category'];
         $btc_amount = $tx["amount"];
         if (Input::get('debug') or API_DEBUG == true) {
             $this->print_debug($tx_id, $tx_info, $block_hash, $block_index, $block_time, $account_name, $to_address, $category, $btc_amount);
         }
         /******************* START of checking if its outgoing transaction *******************/
         if ($btc_amount < 0) {
             $this->processOutgoingTransaction($user_id, $btc_amount, $to_address, $tx_id, $confirms);
             continue;
             // loop more in case there is something
         }
         /******************* END of checking if its outgoing transaction *******************/
         Log::info("Address {$to_address}, amount (BTC): {$btc_amount}, confirms: {$confirms} received transaction id {$tx_id}");
         /* whether new transaction or notify was fired on 1st confirmation */
         $transaction_model = Transaction::getTransactionByTxIdAndAddress($tx_id, $to_address);
         $satoshi_amount = bcmul($btc_amount, SATOSHIS_FRACTION);
         $is_own_address = false;
         // if not own address, then unknown address received transaction
         /* create common data for transaction */
         $common_data = ['tx_id' => $tx_id, 'user_id' => $this->user->id, 'crypto_amount' => $satoshi_amount, 'network_fee' => $fee, 'crypto_type_id' => $this->crypto_type_id, 'address_to' => $to_address, 'address_from' => $address_from, 'confirmations' => $confirms, 'block_hash' => $block_hash, 'block_index' => $block_index, 'block_time' => $block_time, 'tx_time' => $time, 'tx_timereceived' => $time_received, 'tx_category' => $category, 'address_account' => $account_name];
         /******************* START processing the invoicing callback **************/
         $invoice_address_model = InvoiceAddress::getAddress($to_address);
         if ($invoice_address_model) {
             $is_own_address = true;
             $this->processInvoiceAddress($transaction_model, $invoice_address_model, $common_data, $satoshi_amount);
             continue;
             // continue into the next loop
         }
         /*************** END processing the invoicing callback **************/
         /*************************************************************************************/
         /* at this point its not the invoicing address, lookup address in address table
         			/*************************************************************************************/
         /************* It is incoming transaction, because it is sent to some of the inner addresses *************/
         $address_model = Address::getAddress($to_address);
         if ($address_model) {
             $is_own_address = true;
             $this->processUserAddress($transaction_model, $address_model, $common_data, $satoshi_amount);
             continue;
         }
         /* The receiving address wasn't in the database, so its not tied to any API user, but generated outside API directly in bitcoin core*/
         if (!$is_own_address) {
             /* This can be enabled when needed to save payment for unknown address received
              * but because we have change addresses that are used in 'sendmany', we don't want to bloat transactions table */
             //$this->processUnknownAddress( $confirms, $transaction_model, $common_data, $btc_amount, $to_address, $satoshi_amount );
             continue;
         }
     }
     return '*ok*';
     // just dummy return, since it's not being processed on other end. the return is processed in fetchUrl()
 }
Beispiel #5
0
 public static function getPersons()
 {
     $dados = Database::ReadAll("person", "*");
     if (!$dados) {
         return '';
     }
     foreach ($dados as $dado) {
         $person = new Person();
         $person->setId($dado['ID_PERSON']);
         $person->setName($dado['NAME_PERSON']);
         $person->setEmail($dado['EMAIL']);
         $person->setAge($dado['AGE']);
         $person->setSex($dado['SEX']);
         $person->setPhone($dado['PHONE']);
         $person->setOperator($dado['OPERATOR']);
         $person->setMaritalStatus($dado['MARITAL_STATUS']);
         $person->setChildren($dado['CHILDREN']);
         $religion = Religion::getReligion("WHERE id_religion = " . $dado['ID_RELIGION']);
         $person->setReligion($religion);
         $address = Address::getAddress("AND id_address = " . $dado['ID_ADDRESS']);
         $person->setAddress($address);
         $login = Login::getLogin($dado['ID_PERSON']);
         $person->setLogin($login);
         $persons[] = $person;
     }
     return $persons;
 }
 /**
  * Adds a new address to the database
  * Also, modifies an Address object by setting the ID to a new value
  * Returns TRUE on success, FALSE otherwise
  * 
  * @global wpdb $wpdb
  * @param Address $address
  */
 public static function addAddress($address)
 {
     global $wpdb;
     $query = "INSERT INTO `datr_Addresses` (`address`, `meeting_room`, `locationID`, `instructionLink`, `contentLink`) VALUES ('" . $address->getAddress() . "', '" . $address->getMeetingRoom() . "', " . $address->getLocationID() . ", '" . $address->getInstructionLink() . "', '" . $address->getContentLink() . "')";
     $result = $wpdb->query($query);
     $address->setID($wpdb->insert_id);
     return $result;
 }
Beispiel #7
0
 public static function getMissions($where = null)
 {
     $dados = Database::ReadAll("mission", "*", $where);
     if (!$dados) {
         return '';
     }
     foreach ($dados as $dado) {
         $mission = new Mission();
         $mission->setId($dado['ID_MISSION']);
         $mission->setName($dado['NAME_MISSION']);
         $mission->setDateBegin($dado['DATE_INICIAL']);
         $mission->setDateEnd($dado['DATE_END']);
         $mission->setStatus($dado['STATUS']);
         $team = Team::getTeam("WHERE id_team = " . $dado['ID_TEAM']);
         $mission->setTeam($team);
         if (!empty($dado['ID_ADDRESS'])) {
             $address = Address::getAddress("AND id_address = " . $dado['ID_ADDRESS']);
             $mission->setAddress($address);
         }
         if (!empty($dado['ID_CHURCH'])) {
             $church = Church::getChurch("WHERE id_church = " . $dado['ID_CHURCH']);
             $mission->setChurch($church);
         }
         $missions[] = $mission;
     }
     return $missions;
 }
Beispiel #8
0
 /**
  * Tests the `__construct` method.
  *
  * @return void
  * @access public
  */
 public function test__construct()
 {
     $this->_object = new \Postman\Library\Email\Address('*****@*****.**');
     $this->assertIdentical($this->_object->getAddress(), '*****@*****.**');
 }
Beispiel #9
0
 public static function getLeaders()
 {
     $dados = Database::ReadAll("calebe c, person p", "c.*, p.*", "WHERE p.id_person = c.id_person AND c.leader = 2");
     if (!$dados) {
         return '';
     }
     foreach ($dados as $dado) {
         $calebe = new Calebe();
         $calebe->setId($dado['ID_PERSON']);
         $calebe->setName($dado['NAME_PERSON']);
         $calebe->setEmail($dado['EMAIL']);
         $calebe->setAge($dado['AGE']);
         $calebe->setSex($dado['SEX']);
         $calebe->setPhone($dado['PHONE']);
         $calebe->setOperator($dado['OPERATOR']);
         $calebe->setMaritalStatus($dado['MARITAL_STATUS']);
         $calebe->setChildren($dado['CHILDREN']);
         $calebe->setBaptism($dado['BAPTISM']);
         $calebe->setLeader($dado['LEADER']);
         $calebe->setTimeStudy($dado['TIME_STUDY']);
         $calebe->setStatus($dado['STATUS']);
         $calebe->setDateInsert($dado['INSERT_DATE']);
         $religion = Religion::getReligion("WHERE id_religion = " . $dado['ID_RELIGION']);
         $calebe->setReligion($religion);
         $address = Address::getAddress("AND id_address = " . $dado['ID_ADDRESS']);
         $calebe->setAddress($address);
         $login = Login::getLogin($dado['ID_PERSON']);
         $calebe->setLogin($login);
         $calebes[] = $calebe;
     }
     return $calebes;
 }
Beispiel #10
0
 public static function getResident($where)
 {
     $dado = Database::ReadOne("resident r, person p", "r.*, p.*", "WHERE p.id_person = r.id_person {$where}");
     if (!$dado) {
         return '';
     }
     $resident = new Resident();
     $resident->setId($dado['ID_PERSON']);
     $resident->setName($dado['NAME_PERSON']);
     $resident->setEmail($dado['EMAIL']);
     $resident->setAge($dado['AGE']);
     $resident->setSex($dado['SEX']);
     $resident->setPhone($dado['PHONE']);
     $resident->setOperator($dado['OPERATOR']);
     $resident->setMaritalStatus($dado['MARITAL_STATUS']);
     $resident->setChildren($dado['CHILDREN']);
     $resident->setDateInsert($dado['INSERT_DATE']);
     $resident->setNumberResident($dado['NUMBER_RESIDENT_HOUSE']);
     $resident->setHouseFather($dado['HOUSEFATHER']);
     $resident->setCognateAdventista($dado['COGNATE_ADVENTISTA']);
     $religion = Religion::getReligion("WHERE id_religion = " . $dado['ID_RELIGION']);
     $resident->setReligion($religion);
     $address = Address::getAddress("AND id_address = " . $dado['ID_ADDRESS']);
     $resident->setAddress($address);
     $research = Research::getResearch('WHERE id_resident = ' . $dado['ID_PERSON']);
     $resident->setResearch($research);
     return $resident;
 }