Exemple #1
0
 public function add()
 {
     if (!$this->user_session) {
         redirect(site_url('login'));
     }
     $currencies_array = $this->currencies->getCurrencies();
     $balance_currencies[''] = '-- Select Currency --';
     $balances = $this->balance->getBalanceByUserId($this->user_session['user_id']);
     $balances_array = array();
     foreach ($balances as $balance) {
         $balances_array[$balance['currency_code']] = $balance['balance'];
     }
     $balance_currencies = array();
     foreach ($currencies_array as $currency_code => $currency_info) {
         $balance_currencies[$currency_info['code']] = $currency_info['title'] . ' (' . get_currency_value_format(!empty($balances_array[$currency_info['code']]) ? $balances_array[$currency_info['code']] : 0, $currency_info) . ')';
     }
     $this->assign('balance_currencies', $balance_currencies);
     $posts = $this->input->post();
     if ($posts) {
         $balance_currency = $posts['balance_currency'];
         $amount = $posts['amount'];
         $master_key = $posts['master_key'];
         if ($balance_currency == '') {
             $this->validator->addError('Currency', 'Please select the currency of balance that you want to use for the transaction.');
         }
         if ($amount <= 0) {
             $this->validator->addError('Amount', 'Please input correct Amount .');
         } else {
             // check if out of balance
             if ($amount > $balances_array[$balance_currency]) {
                 $this->validator->addError('Balance', 'You have not enough balance to transfer the amount(<strong>' . get_currency_value_format($amount, $currencies_array[$balance_currency]) . '</strong>). Please input difference amount.');
             }
         }
         $check_master_key = getMasterKey();
         // check master KEy
         if ($master_key != $check_master_key) {
             $this->validator->addError('Master Key', 'Invalid master key entered. Master Key is a three digit number you have selected at the time of registration. Please try again.');
         }
         if (count($this->validator->errors) == 0) {
             $batch_number = tep_create_random_value(11, 'digits');
             $amount_text = get_currency_value_format($amount, $currencies_array[$balance_currency]);
             $amount = get_currency_value($amount, $currencies_array[$balance_currency]);
             $transaction_memo = 'Transfer to wallet';
             $transaction_data_array = array('from_userid' => $this->user_session['user_id'], 'batch_number' => $batch_number, 'to_userid' => $this->user_session['user_id'], 'amount' => $amount, 'transaction_time' => date('YmdHis'), 'transaction_memo' => $transaction_memo, 'from_account' => $this->user_session['account_number'], 'to_account' => $this->user_session['account_number'], 'transaction_currency' => $balance_currency, 'amount_text' => $amount_text, 'transaction_status' => 'completed');
             $this->transaction->insert($transaction_data_array);
             $balanceFrom = array('user_id' => $this->user_session['user_id'], 'currency_code' => $amount);
             $this->balance->updateBalance($balanceFrom, $amount, '-');
             $this->wallet->updateWallet($balanceFrom, $amount, '+');
             $dataEmail = array('firstname' => $this->user_session['firstname'], 'amount_text' => $amount_text, 'batch_number' => $batch_number, 'balance_currency' => $balance_currency, 'from_account' => $this->user_session['account_number'], 'fees_text' => 0);
             $this->email_model->sendmail('PAGE_ACCOUNT_TRANSFER_WALLET', $this->user_session['firstname'], $this->user_session['email'], $dataEmail);
         } else {
             $this->data['validerrors'] = $this->validator->errors;
         }
     }
     $this->data['posts'] = $posts;
     $this->view('wallet/add');
 }
Exemple #2
0
 if ($balance_currency == '') {
     $validator->addError('Currency', 'Please select the currency of balance that you want to use for the transaction.');
 }
 if ($amount <= 0) {
     $validator->addError('Amount', 'Please input correct Amount .');
 } else {
     // check if out of balance
     if ($amount > $balances_array[$balance_currency]) {
         $validator->addError('Balance', 'You have not enough balance to transfer the amount(<strong>' . get_currency_value_format($amount, $currencies_array[$balance_currency]) . '</strong>). Please input difference amount.');
     }
 }
 $check_account_query = db_query("SELECT account_number, firstname, lastname, account_name , user_id FROM " . _TABLE_USERS . " WHERE account_number='" . trim($to_account) . "' and account_number <>'" . $login_account_number . "'");
 if (db_num_rows($check_account_query) == 0) {
     $validator->addError('Account Number', 'Invalid account number. Please input correct account number of the user that you want to transfer to.');
 } else {
     $check_master_key = getMasterKey();
     // check master KEy
     if ($master_key != $check_master_key) {
         $validator->addError('Master Key', 'Invalid master key entered. Master Key is a three digit number you have selected at the time of registration. Please try again.');
     }
 }
 if (count($validator->errors) == 0) {
     $transfer_info = db_fetch_array($check_account_query);
     $transfer_info['amount'] = $amount;
     $transfer_info['balance_currency'] = $balance_currency;
     $transfer_info['amount_text'] = get_currency_value_format($amount, $currencies_array[$balance_currency]);
     $transfer_info['fees_text'] = get_currency_value_format($fees, $currencies_array[$balance_currency]);
     $transfer_info['transaction_memo'] = $transaction_memo;
     $smarty->assign('transfer_info', $transfer_info);
     $step = 'confirm';
 } else {
        if (!validate_password($curent_password, $account_info['password'])) {
            // wrong password
            $validator->addError('Password', ERROR_INVALID_PASSWORD);
        }
    }
    if ($validator->validateGeneral('New password', $new_password, _ERROR_FIELD_EMPTY)) {
        $validator->validateMinLength('New password', $new_password, 7, 'New password greater than 6 character');
    }
    if ($validator->validateGeneral('Confirm New Passwor', $re_password, _ERROR_FIELD_EMPTY)) {
        if ($new_password != $re_password) {
            $validator->addError('Confirm New Passwor', ERROR_INVALID_RE_PASSWORD);
        }
    }
    $master_key = db_prepare_input($_POST['master_key']);
    if ($validator->validateGeneral('Master Key', $master_key, _ERROR_FIELD_EMPTY)) {
        if ($master_key != getMasterKey()) {
            $validator->addError('Master Key', 'Invalid master key. Please try again.');
        }
    }
    if (count($validator->errors) == 0) {
        // update user personal info
        // create user data
        $signup_data_array = array('password' => encrypt_password($new_password));
        db_perform(_TABLE_USERS, $signup_data_array, 'update', " user_id='" . $login_userid . "' ");
        $smarty->assign('step', 'updated');
        postAssign($smarty);
    } else {
        postAssign($smarty);
    }
}
if ($master_key_pass) {