Viewing file: Payment_model.php (1.63 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
class Payment_model extends CI_Model
{
public function getUserByEmail($email) {
$result = $this->db->get_where('users', array('email' => $email))->result_array();
return count($result) > 0 ? $result[0] : null;
}
public function insertTransaction($type,$user_id, $btc = false, $paypal = false) {
return $this->db->insert('transactions', array(
"id" => null,
"type" => $type,
"user" => $user_id,
"time" => time(),
"btc" => $btc ? 1 : 0,
"paypal" => $paypal ? 1 : 0
));
}
public function insertPayment($amount,$method,$user_id, $btc = false, $paypal = false) {
$this->db->insert('payments', array(
"id" => null,
"amount" => $amount,
"method" => $method,
"user" => $user_id,
"time" => time(),
"btc" => $btc ? 1 : 0,
"paypal" => $paypal ? 1 : 0
));
return $this->db->insert_id();
}
public function getPendingPayment($id) {
return $this->db->get_where("payments", array("id" => $id, "status" => 0))->result_array()[0];
}
public function acceptPayment($payment_id, $amount, $method, $user_id, $btc = false, $paypal = false) {
$this->db->query("UPDATE payments SET status = 1 WHERE id = $payment_id");
$this->db->query("UPDATE users SET balance = balance + $amount WHERE id = $user_id");
$this->insertTransaction("add_balance:$method:$amount",$user_id, $btc, $paypal);
}
}
?>
|