Esempio n. 1
0
 public function index()
 {
     $this->load->model('balance_model', 'balance');
     $this->load->model('currencies_model', 'currencies');
     $this->load->model('wallet_model', 'wallet');
     $balances = $this->balance->getBalanceByUserId($this->user_session['user_id']);
     $currencies_array = $this->currencies->getCurrencies();
     $balances_array = array();
     foreach ($balances as $balance) {
         $balances_array[$balance['currency_code']] = $balance['balance'];
     }
     $balance_info_array = array();
     foreach ($currencies_array as $currency_code => $currency_info) {
         $balance_info_array[] = array('balance_code' => $currency_info['code'], 'balance_name' => $currency_info['title'], 'balance_text' => get_currency_value_format(!empty($balances_array[$currency_info['code']]) ? $balances_array[$currency_info['code']] : 0, $currency_info));
     }
     $this->data['balances'] = $balance_info_array;
     $wallets = $this->wallet->getBalanceByUserId($this->user_session['user_id']);
     $wallets_array = array();
     foreach ($wallets as $balance) {
         $wallets_array[$balance['currency_code']] = $balance['balance'];
     }
     $totals_info_array = array();
     $wallet_info_array = array();
     foreach ($currencies_array as $currency_code => $currency_info) {
         $wallet_info_array[] = array('balance_code' => $currency_info['code'], 'balance_name' => $currency_info['title'], 'balance_text' => get_currency_value_format(!empty($wallets_array[$currency_info['code']]) ? $wallets_array[$currency_info['code']] : 0, $currency_info));
         $totals_info_array[] = array('balance_text' => get_currency_value_format(!empty($wallets_array[$currency_info['code']]) ? $wallets_array[$currency_info['code']] : 0 + !empty($balances_array[$currency_info['code']]) ? $balances_array[$currency_info['code']] : 0, $currency_info));
     }
     $this->data['wallets'] = $wallet_info_array;
     $this->data['totals'] = $totals_info_array;
     $this->view('account/index');
 }
Esempio n. 2
0
 public function transfer()
 {
     $this->load->model('email_model');
     $login_id = $this->session->userdata('login_id');
     if (!$this->user_session && !$login_id) {
         redirect(site_url('login'));
     }
     if ($this->user_session) {
         $user_info = $this->user_session;
     } else {
         $user_info = $this->user->getUserById($login_id);
     }
     $this->data['success'] = $this->input->get('success');
     $currencies_array = $this->currencies->getCurrencies();
     $balance_currencies[''] = '-- Select Currency --';
     $balances = $this->wallet->getBalanceByUserId($user_info['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'];
         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.');
             }
         }
         $to_account = $posts['to_account'];
         $to_user_info = $this->user->getUser(array('account_number' => $posts['to_account']));
         if (!$to_user_info) {
             $this->validator->addError('Account Number', 'Invalid account number. Please input correct account number of the user that you want to transfer to.');
         } elseif (trim($to_account) == $user_info['account_number']) {
             $this->validator->addError('Account Number', 'Invalid account number. Please input correct account number of the user that you want to transfer to.');
         }
         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]);
             $transaction_memo = '';
             $fees = $amount * $this->configs['TRANSFER_FEES'] / 100;
             $fees_text = get_currency_value_format($fees, $currencies_array[$balance_currency]);
             $amount = get_currency_value($amount, $currencies_array[$balance_currency]);
             $fees = get_currency_value($fees, $currencies_array[$balance_currency]);
             $current_amount = $amount - $fees;
             $transaction_data_array = array('from_userid' => $user_info['user_id'], 'batch_number' => $batch_number, 'to_userid' => $to_user_info['user_id'], 'amount' => $amount, 'fee' => $fees, 'fee_text' => $fees_text, 'transaction_time' => date('YmdHis'), 'transaction_memo' => $transaction_memo, 'from_account' => $user_info['account_number'], 'to_account' => $to_user_info['account_number'], 'transaction_currency' => $balance_currency, 'amount_text' => $amount_text, 'transaction_status' => 'completed');
             $this->data['transaction_data'] = $transaction_data_array;
             $this->transaction->insert($transaction_data_array);
             $balanceFrom = array('user_id' => $user_info['user_id'], 'currency_code' => $balance_currency);
             $this->wallet->updateWallet($balanceFrom, $amount, '-');
             $balanceTo = array('user_id' => $to_user_info['user_id'], 'currency_code' => $balance_currency);
             $this->balance->updateBalance($balanceTo, $current_amount, '+');
             //admin transfer
             $batch_number_admin = tep_create_random_value(11, 'digits');
             $transaction_data_array_admin = array('from_userid' => $to_user_info['user_id'], 'batch_number' => $batch_number_admin, 'to_userid' => 1, 'amount' => $fees, 'fee' => 0, 'transaction_time' => date('YmdHis'), 'transaction_memo' => 'transaction fees #' . $batch_number, 'from_account' => $to_user_info['account_number'], 'to_account' => 'OOKCASH', 'transaction_currency' => $balance_currency, 'amount_text' => $fees_text, 'transaction_status' => 'completed', 'status' => '0');
             $this->transaction->insert($transaction_data_array_admin);
             $balanceAdmin = array('user_id' => 1, 'currency_code' => $balance_currency);
             $this->balance->updateBalance($balanceAdmin, $fees, '+');
             $dataEmail = array('firstname' => $to_user_info['firstname'], 'amount_text' => $amount_text, 'batch_number' => $batch_number, 'balance_currency' => $balance_currency, 'from_account' => $user_info['account_number'], 'fees_text' => $fees_text);
             $this->email_model->sendmail('TRANSFER_EMAIL', $to_user_info['firstname'], $to_user_info['email'], $dataEmail);
             redirect(site_url('wallet/transfer') . '?success=1');
         } else {
             $this->data['validerrors'] = $this->validator->errors;
         }
     }
     $this->data['posts'] = $posts;
     $this->view('wallet/transfer');
 }
Esempio n. 3
0
<?php

userLoginCheck();
if (!tep_session_is_registered('payee_account') && tep_not_null($payee_account)) {
    tep_redirect(get_href_link(PAGE_TRANSFER));
}
//bof: get currencies
$currency = get_currency($checkout_currency);
$balance = get_currency_value_format($checkout_amount, $currency);
$transfer_info['fees_text'] = get_currency_value_format($fees, $currency);
$smarty->assign('amount', $balance);
$smarty->assign('fees_text', $fees_text);
$smarty->assign('success_url', $success_url);
$smarty->assign('fail_url', $fail_url);
$smarty->assign('cancel_url', $cancel_url);
$smarty->assign('status_url', $status_url);
$smarty->assign('extra_fields', $extra_fields);
$smarty->assign('to_acount', $payee_account);
//eof: get currencies
$sql_user = "******" . _TABLE_USERS . " WHERE account_number='" . $payee_account . "'";
$user_query = db_query($sql_user);
if (db_num_rows($user_query) == 0) {
    tep_redirect(get_href_link(PAGE_TRANSFER));
}
$user_to_info = db_fetch_array($user_query);
$smarty->assign('user_to_info', $user_to_info);
$stepValue = 'confirm';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $master_key = db_prepare_input($_POST['master_key']);
    $memo = db_prepare_input($_POST['transaction_memo']);
    $sql_check = "SELECT account_name, firstname, lastname FROM " . _TABLE_USERS . " WHERE user_id='" . $login_userid . "' and account_number='" . $login_account_number . "' and master_key='" . $master_key . "'";
Esempio n. 4
0
<?php

if (!tep_session_is_registered('login_account_number') && tep_not_null($login_account_number)) {
    tep_redirect(get_href_link(PAGE_LOGIN));
}
// get currencies balance
$currencies_balance = array();
$sql_balances = "SELECT currency_code, balance FROM " . _TABLE_USER_BALANCE . " WHERE user_id='" . $login_userid . "'";
$balances_query = db_query($sql_balances);
while ($balance = db_fetch_array($balances_query)) {
    $balances_array[$balance['currency_code']] = $balance['balance'];
}
// get all currencies_list
$currencies_array = get_currencies();
foreach ($currencies_array as $currency_code => $currency_info) {
    $balance_info_array[] = array('balance_name' => $currency_info['title'], 'balance_text' => get_currency_value_format($balances_array[$currency_code], $currency_info));
}
$smarty->assign('balances', $balance_info_array);
$_html_main_content = $smarty->fetch('home/login_balance.html');
Esempio n. 5
0
 public function transfer()
 {
     if (!$this->user_session) {
         redirect(site_url('login'));
     }
     $sci_info = $this->session->userdata('sci');
     if (!$sci_info || empty($sci_info['checkout_currency'])) {
         $this->validator->addError('SCI Information', 'You haven\'t yet input sci info');
         $this->assign('validerrors', $this->validator->errors);
     } else {
         $checkout_amount = $sci_info['checkout_amount'];
         $currency = $this->currencies->getCurrencyByCode($sci_info['checkout_currency']);
         $balance = get_currency_value_format($checkout_amount, $currency);
         $fees = $checkout_amount * $this->configs['TRANSFER_FEES'] / 100;
         $fees_text = get_currency_value_format($fees, $currency);
         $checkout_amount = get_currency_value($checkout_amount, $currency);
         $fees = get_currency_value($fees, $currency);
         $balance_current = $this->balance->getBalance(array('user_id' => $this->user_session['user_id'], 'currency_code' => $sci_info['checkout_currency']));
         $this->data['sci_info'] = $sci_info;
         $sci_user = $this->user->getUser(array('account_number' => $sci_info['payee_account']));
         if (!$sci_user) {
             redirect(site_url('transfer'));
         }
         $this->data['sci_user'] = $sci_user;
         $posts = $this->input->post();
         if ($posts) {
             $master_key = $posts['master_key'];
             if ($master_key != $this->user_session['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 ($checkout_amount <= 0) {
                 if (empty($posts['checkout_amount'])) {
                     $this->validator->addError('Amount', 'Amount greater than 0');
                 } else {
                     $amount = $posts['checkout_amount'];
                     if ($validator->validateNumber('Amount', $amount, 'Amount greater than 0')) {
                         $checkout_amount = $amount;
                         $balance = get_currency_value_format($checkout_amount, $currency);
                         $fees = $checkout_amount * TRANSFER_FEES / 100;
                         $fees_text = get_currency_value_format($fees, $currency);
                         $checkout_amount = get_currency_value($checkout_amount, $currency);
                         $fees = get_currency_value($fees, $currency);
                         if ($checkout_amount > $balance_current['balance']) {
                             $this->validator->addError('Amount', 'You don\'t have enough money to transfer');
                         }
                     }
                 }
             }
             if (count($this->validator->errors) == 0) {
                 $sci_info['checkout_amount'] = $checkout_amount;
                 $sci_info['transaction_memo'] = $posts['transaction_memo'];
                 $sci_info['balance'] = $balance;
                 $sci_info['fees'] = $fees;
                 $sci_info['fees_text'] = $fees_text;
                 $sci_info['master_key'] = $master_key;
                 $this->session->set_userdata('sci', $sci_info);
                 redirect('sci/preview');
             } else {
                 $this->assign('validerrors', $this->validator->errors);
             }
         }
     }
     $this->view('sci/transfer');
 }
Esempio n. 6
0
    exit;
}
$amount = $_POST['amount'];
$balance_currency = $_POST['balance_currency'];
//dv tien
//bof: get currencies
$currency = get_currency($balance_currency);
if (!$currency) {
    $data_result = array('status' => 'error', 'error_code' => 'ERR_014', 'error_title' => $__ERROR_CODE['ERR_014']);
    echo json_encode($data_result);
    exit;
}
$fees = $amount * TRANSFER_FEES / 100;
$batch_number = tep_create_random_value(11, 'digits');
$amount_text = get_currency_value_format($amount, $currency);
$fees_text = get_currency_value_format($fees, $currency);
if (!is_numeric($amount) && !is_float($amount) || $amount < 0) {
    $data_result = array('status' => 'error', 'error_code' => 'ERR_013', 'error_title' => $__ERROR_CODE['ERR_013']);
    echo json_encode($data_result);
    exit;
}
//get User from
$from_acount_number = $_POST['acount_number'];
$master_key = $_POST['master_key'];
$pin = $_POST['pin'];
$checkUserFrom = 'select * from ' . _TABLE_USERS . ' where md5(account_number)="' . $from_acount_number . '" AND md5(login_pin)="' . $pin . '" AND md5(master_key)="' . $master_key . '"';
$user_check = db_query($checkUserFrom);
if (db_num_rows($user_check) == 0) {
    $data_result = array('status' => 'error', 'error_code' => 'ERR_011', 'error_title' => $__ERROR_CODE['ERR_011']);
    echo json_encode($data_result);
    exit;
Esempio n. 7
0
    $smarty->assign('payee_account', $payee_account);
}
$account_info = db_fetch_array(db_query("SELECT account_name, account_type, referral_count FROM " . _TABLE_USERS . " WHERE user_id='" . $login_userid . "'"));
//BOF: main account balances
// get all currencies_list
$currencies_array = get_currencies();
// get main account balances
$sql_balances = "SELECT currency_code, balance FROM " . _TABLE_USER_BALANCE . " WHERE user_id='" . $login_userid . "'";
$balances_query = db_query($sql_balances);
while ($balance = db_fetch_array($balances_query)) {
    $balances_array[$balance['currency_code']] = $balance['balance'];
}
foreach ($currencies_array as $currency_code => $currency_info) {
    $balance_info_array[] = array('balance_code' => $currency_info['code'], 'balance_name' => $currency_info['title'], 'balance_text' => get_currency_value_format($balances_array[$currency_code], $currency_info));
}
$smarty->assign('balances', $balance_info_array);
// get wallet balances
$sql_wallets = "SELECT currency_code, balance FROM " . _TABLE_USER_WALLET . " WHERE user_id='" . $login_userid . "'";
$wallets_query = db_query($sql_wallets);
while ($wallet = db_fetch_array($wallets_query)) {
    $wallets_array[$wallet['currency_code']] = $wallet['balance'];
}
foreach ($currencies_array as $currency_code => $currency_info) {
    $wallet_info_array[] = array('balance_code' => $currency_info['code'], 'balance_name' => $currency_info['title'], 'balance_text' => get_currency_value_format($wallets_array[$currency_code], $currency_info));
    $totals_info_array[] = array('balance_text' => get_currency_value_format($wallets_array[$currency_code] + $balances_array[$currency_code], $currency_info));
}
$smarty->assign('wallets', $wallet_info_array);
$smarty->assign('totals', $totals_info_array);
//EOF: main account balances
$smarty->assign('account_info', $account_info);
$_html_main_content = $smarty->fetch('account/account.html');
Esempio n. 8
0
    exit;
}
$checkUser = '******' . _TABLE_USERS . ' where account_number = "' . $acount_number . '"';
$user_check = db_query($checkUser);
if (db_num_rows($user_check) == 0) {
    $data_result = array('status' => 'error', 'error_code' => 'ERR_011', 'error_title' => $__ERROR_CODE['ERR_011']);
    echo json_encode($data_result);
    exit;
}
$user = db_fetch_array($user_check);
if (empty($balance_currency)) {
    $data_result = array('status' => 'error', 'error_code' => 'ERR_010', 'error_title' => $__ERROR_CODE['ERR_010']);
    echo json_encode($data_result);
    exit;
}
$sql_currencies_page = "SELECT * FROM " . _TABLE_CURRENCIES . " WHERE code='{$balance_currency}'";
$currency_page_query = db_query($sql_currencies_page);
if (db_num_rows($currency_page_query) <= 0) {
    $data_result = array('status' => 'error', 'error_code' => 'ERR_010', 'error_title' => $__ERROR_CODE['ERR_011']);
    echo json_encode($data_result);
    exit;
}
$balance_currency = db_fetch_array($currency_page_query);
$sql_balances = "SELECT currency_code, balance FROM " . _TABLE_USER_BALANCE . " WHERE user_id='" . $user['user_id'] . "' AND currency_code = '{$balance_currency['code']}'";
$balances_query = db_query($sql_balances);
$balances = db_fetch_array($balances_query);
$amount_text = get_currency_value_format($balances['balance'], $balance_currency);
$data_result = array('status' => 'success', 'amount' => $balances['balance'], 'amount_text' => $amount_text, 'balance_currency' => $balance_currency['code']);
echo json_encode($data_result);
exit;
die;
Esempio n. 9
0
 public function balance()
 {
     $login_id = $this->session->userdata('login_id');
     if (!$login_id) {
         redirect(site_url('login'));
     }
     $user_session = $this->session->userdata('user');
     if ($user_session) {
         redirect(site_url('home'));
     }
     $this->load->model('balance_model', 'balance');
     $this->load->model('currencies_model', 'currencies');
     $balances = $this->balance->getBalanceByUserId($login_id);
     $balances_array = array();
     foreach ($balances as $balance) {
         $balance = $balance;
         $balances_array[$balance['currency_code']] = $balance['balance'];
     }
     // get all currencies_list
     $currencies_array = $this->currencies->getCurrencies();
     foreach ($currencies_array as $currency_code => $currency_info) {
         if (!empty($balances_array[$currency_info['code']])) {
             $balance_info_array[] = array('balance_name' => $currency_info['title'], 'balance_text' => get_currency_value_format($balances_array[$currency_info['code']], $currency_info));
         }
     }
     $this->data['balances'] = $balance_info_array;
     $this->view('login/balance');
 }
Esempio n. 10
0
<?php

$sql_history = "SELECT * FROM " . _TABLE_TRANSACTIONS_HISTOTY . " WHERE transaction_status='completed'";
$history_query = db_query($sql_history);
while ($history = db_fetch_array($history_query)) {
    $history_id = $history['history_id'];
    $currency = get_currency($history['transaction_currency']);
    $balance = get_currency_value_format($history['amount'], $currency);
    $transfer_info['fees_text'] = get_currency_value_format($history['fee'], $currency);
    $sql_check = "SELECT account_name, firstname, lastname FROM " . _TABLE_USERS . " WHERE user_id='" . $history['from_userid'] . "'";
    $user_check = db_query($sql_check);
    $user_transfer = db_fetch_array($user_check);
    $smarty->assign('user_transfer', $user_transfer);
    $sql_user = "******" . _TABLE_USERS . " WHERE user_id='" . $history['to_userid'] . "'";
    $user_query = db_query($sql_user);
    if (db_num_rows($user_query) > 0) {
        if (!empty($history['status_url'])) {
            $dataPost = array('payee_account' => $history['to_account'], 'payer_account' => $history['from_account'], 'checkout_amount' => $history['amount'], 'checkout_currency' => $history['transaction_currency'], 'batch_number' => $history['batch_number'], 'transaction_status' => $history['transaction_status'], 'transaction_currency' => $history['transaction_currency']);
            $extra_fields = unserialize($history['extra_fields']);
            $dataPost = array_merge($extra_fields, $dataPost);
            if ($history['status_method'] == 'GET') {
                $results = curl_get($history['status_url'], $dataPost);
            } else {
                $results = curl_post($history['status_url'], $dataPost);
            }
            if ($results) {
                $sql_delete = "DELETE  FROM " . _TABLE_TRANSACTIONS_HISTOTY . " WHERE history_id='" . $history_id . "'";
                db_query($sql_delete);
            } else {
                if (strtotime($history['transaction_time']) < strtotime("-2 day")) {
                    $sql_delete = "DELETE  FROM " . _TABLE_TRANSACTIONS_HISTOTY . " WHERE history_id='" . $history_id . "'";
Esempio n. 11
0
            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 {
            postAssign($smarty);
            $smarty->assign('validerrors', $validator->errors);
        }
    }
    $smarty->assign('step', $step);
}
$_html_main_content = $smarty->fetch('account/transfer.html');
 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_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) {
     $batch_number = tep_create_random_value(11, 'digits');
     $amount_text = get_currency_value_format($amount, $currencies_array[$balance_currency]);
     $transaction_memo = 'Transfer to wallet';
     $transaction_data_array = array('from_userid' => $login_userid, 'batch_number' => $batch_number, 'to_userid' => $login_userid, 'amount' => $amount, 'transaction_time' => date('YmdHis'), 'transaction_memo' => $transaction_memo, 'from_account' => $login_account_number, 'to_account' => $login_account_number, 'transaction_currency' => $balance_currency, 'amount_text' => $amount_text, 'transaction_status' => 'completed');
     db_perform(_TABLE_TRANSACTIONS, $transaction_data_array);
     // deduce balance of the from account
     db_query("UPDATE " . _TABLE_USER_BALANCE . " SET balance=balance- " . $amount . ", last_updated='" . date('YmdHis') . "' WHERE user_id='" . $login_userid . "' and currency_code='" . $balance_currency . "'");
     // add balance to the account
     // check  user's balance currency init ?
     $check_balance = db_fetch_array(db_query("SELECT count(*) as total FROM " . _TABLE_USER_WALLET . " WHERE user_id='" . $login_userid . "' and currency_code='" . $balance_currency . "'"));
     $current_amount = $amount;
     if ($check_balance['total'] > 0) {
         db_query("UPDATE " . _TABLE_USER_WALLET . " SET balance=balance+ " . $current_amount . ", last_updated='" . date('YmdHis') . "' WHERE user_id='" . $login_userid . "' and currency_code='" . $balance_currency . "'");
     } else {
         $balance_data_array = array('user_id' => $login_userid, 'currency_code' => $balance_currency, 'balance' => $current_amount, 'last_updated' => date('YmdHis'));
         db_perform(_TABLE_USER_WALLET, $balance_data_array);
     }
Esempio n. 13
0
        tep_session_register('fail_url');
        unset($requests['fail_url']);
        $success_url = base64_decode($requests['success_url']);
        tep_session_register('success_url');
        unset($requests['success_url']);
        $status_url = base64_decode($requests['status_url']);
        tep_session_register('status_url');
        unset($requests['status_url']);
        $extra_fields = array();
        foreach ($requests as $key => $request) {
            $extra_fields[$key] = $request;
        }
        tep_session_register('extra_fields');
        $action = $requests['action'];
        $currency = get_currency($checkout_currency);
        $balance = get_currency_value_format($checkout_amount, $currency);
        $smarty->assign('amount', $balance);
        $smarty->assign('success_url', $success_url);
        $smarty->assign('fail_url', $fail_url);
        $smarty->assign('cancel_url', $cancel_url);
        $smarty->assign('status_url', $status_url);
        $user_info = db_fetch_array($user_query);
        $smarty->assign('user_info', $user_info);
        $smarty->assign('requests', $requests);
        //        tep_redirect(get_href_link(PAGE_LOGIN));
    } else {
        $validator->addError(ERROR_FIELD_SCI, ERROR_INVALID_ACCOUNT_SCI);
    }
} else {
    $smarty->assign('errors', $error_code);
    $smarty->assign('error_code', $__ERROR_CODE);
Esempio n. 14
0
     }
 }
 $to_account = db_prepare_input($_POST['to_account']);
 $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.');
 } elseif (trim($to_account) == $login_account_number) {
     $validator->addError('Account Number', 'Invalid account number. Please input correct account number of the user that you want to transfer to.');
 }
 $to_user_info = db_fetch_array($check_account_query);
 if (count($validator->errors) == 0) {
     $batch_number = tep_create_random_value(11, 'digits');
     $amount_text = get_currency_value_format($amount, $currencies_array[$balance_currency]);
     $transaction_memo = '';
     $fees = $amount * TRANSFER_FEES / 100;
     $fees_text = get_currency_value_format($fees, $currencies_array[$balance_currency]);
     $transaction_data_array = array('from_userid' => $user_login['user_id'], 'batch_number' => $batch_number, 'to_userid' => $to_user_info['user_id'], 'amount' => $amount, 'fee' => $fees, 'fee_text' => $fees_text, 'transaction_time' => date('YmdHis'), 'transaction_memo' => $transaction_memo, 'from_account' => $user_login['account_number'], 'to_account' => $to_user_info['account_number'], 'transaction_currency' => $balance_currency, 'amount_text' => $amount_text, 'transaction_status' => 'completed');
     db_perform(_TABLE_TRANSACTIONS, $transaction_data_array);
     // deduce balance of the from account
     db_query("UPDATE " . _TABLE_USER_WALLET . " SET balance=balance- " . $amount . ", last_updated='" . date('YmdHis') . "' WHERE user_id='" . $user_login['user_id'] . "' and currency_code='" . $balance_currency . "'");
     // add balance to the account
     // check  user's balance currency init ?
     $check_balance = db_fetch_array(db_query("SELECT count(*) as total FROM " . _TABLE_USER_BALANCE . " WHERE user_id='" . $to_user_info['user_id'] . "' and currency_code='" . $balance_currency . "'"));
     $current_amount = $amount - $fees;
     if ($check_balance['total'] > 0) {
         db_query("UPDATE " . _TABLE_USER_BALANCE . " SET balance=balance+ " . $current_amount . ", last_updated='" . date('YmdHis') . "' WHERE user_id='" . $to_user_info['user_id'] . "' and currency_code='" . $balance_currency . "'");
     } else {
         $balance_data_array = array('user_id' => $to_user_info['user_id'], 'currency_code' => $balance_currency, 'balance' => $current_amount, 'last_updated' => date('YmdHis'));
         db_perform(_TABLE_USER_BALANCE, $balance_data_array);
     }
     // Send Transaction Notify 	Email to User
Esempio n. 15
0
 public function success()
 {
     $transfer_info = $this->session->userdata('transfer_info');
     if (!$transfer_info) {
         redirect(site_url('transfer'));
     }
     $this->data['transfer_info'] = $transfer_info;
     $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) . ')';
     }
     if ($transfer_info['balance_currency'] == '') {
         $this->validator->addError('Currency', 'Please select the currency of balance that you want to use for the transaction.');
     }
     if ($transfer_info['amount'] <= 0) {
         $this->validator->addError('Amount', 'Please input correct Amount .');
     } else {
         // check if out of balance
         if ($transfer_info['amount'] > $balances_array[$transfer_info['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.');
         }
     }
     if (count($this->validator->errors) == 0) {
         $batch_number = tep_create_random_value(11, 'digits');
         $transaction_data_array = array('from_userid' => $this->user_session['user_id'], 'batch_number' => $batch_number, 'to_userid' => $transfer_info['user_id'], 'amount' => $transfer_info['amount'], 'fee' => $transfer_info['fees'], 'fee_text' => $transfer_info['fees_text'], 'transaction_time' => date('YmdHis'), 'transaction_memo' => $transfer_info['transaction_memo'], 'from_account' => $this->user_session['account_number'], 'to_account' => $transfer_info['account_number'], 'transaction_currency' => $transfer_info['balance_currency'], 'amount_text' => $transfer_info['amount_text'], 'transaction_status' => 'completed');
         $this->data['transaction_data'] = $transaction_data_array;
         $this->transaction->insert($transaction_data_array);
         $current_amount = $transfer_info['amount'] - $transfer_info['fees'];
         $balanceFrom = array('user_id' => $this->user_session['user_id'], 'currency_code' => $transfer_info['balance_currency']);
         $this->balance->updateBalance($balanceFrom, $transfer_info['amount'], '-');
         $balanceTo = array('user_id' => $transfer_info['user_id'], 'currency_code' => $transfer_info['balance_currency']);
         $this->balance->updateBalance($balanceTo, $current_amount, '+');
         //admin transfer
         $batch_number_admin = tep_create_random_value(11, 'digits');
         $transaction_data_array_admin = array('from_userid' => $transfer_info['user_id'], 'batch_number' => $batch_number_admin, 'to_userid' => 1, 'amount' => $transfer_info['fees'], 'fee' => 0, 'transaction_time' => date('YmdHis'), 'transaction_memo' => 'transaction fees #' . $batch_number, 'from_account' => $transfer_info['account_number'], 'to_account' => 'OOKCASH', 'transaction_currency' => $transfer_info['balance_currency'], 'amount_text' => $transfer_info['fees_text'], 'transaction_status' => 'completed', 'status' => '0');
         $this->transaction->insert($transaction_data_array_admin);
         $balanceAdmin = array('user_id' => 1, 'currency_code' => $transfer_info['balance_currency']);
         $this->balance->updateBalance($balanceAdmin, $transfer_info['fees'], '+');
         $this->load->model('email_model');
         $dataEmail = array('firstname' => $transfer_info['firstname'], 'amount_text' => $transfer_info['fees_text'], 'batch_number' => $batch_number, 'balance_currency' => $transfer_info['balance_currency'], 'from_account' => $this->user_session['account_number'], 'fees_text' => $transfer_info['fees_text']);
         $this->email_model->sendmail('TRANSFER_EMAIL', $transfer_info['firstname'], $transfer_info['email'], $dataEmail);
         $this->session->unset_userdata('transfer_info');
         $this->data['success'] = true;
     } else {
         $this->data['validerrors'] = $this->validator->errors;
     }
     $this->view('transfer/success');
 }