function refund_payment($payment) { /* * echo "<pre>"; print_r($payment); echo "</pre>"; die(); * */ $payments_data = explode('_', $payment->id); switch ($payments_data[0]) { case 'c': // credit cards $query = "select * from mdl_card_payments " . "where id={$payments_data['1']}"; $result = $this->db->query($query); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $amount = $row['psum']; $card_last_four = $row['card_last_four']; $exp_date = $row['exp_date']; $trans_id = $row['trans_id']; } $pr = new ProcessPayment(); $status = $pr->makeRefund($amount, $card_last_four, $exp_date, $trans_id); if ($status) { $query = "update mdl_card_payments " . "set refunded=1 " . "where id={$payments_data['1']}"; $this->db->query($query); } break; case 'i': // invoices $query = "delete from mdl_invoice " . "where id={$payments_data['1']}"; break; case 'p': // partial payments (cash/cheque) $query = "delete from mdl_partial_payments " . "where id={$payments_data['1']}"; break; } $this->db->query($query); }