backoffice/application/controllers/PaymentController.php

83 lines
2.2 KiB
PHP

<?php
class PaymentController extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function createPaymentAggregator()
{
if($this->isLogged()) {
if (isset($_POST)) {
$emailExist = $this->db->get_where('payment_aggregators', ['email' => $_POST['email']]);
if ($emailExist->num_rows() == 0) {
$_POST['created_at'] = (new DateTime())->format('Y-m-d H:i:s');
$_POST['updated_at'] = (new DateTime())->format('Y-m-d H:i:s');
$this->db->insert('payment_aggregators', $_POST);
echo json_encode(['code' => 200]);
} else {
echo json_encode(['code'=> 419 , 'message' => $this->lang->line("L'email entré est déjà utilisé")]);
}
}
}
}
public function updatePaymentAggregator()
{
if($this->isLogged()) {
if (isset($_POST)) {
$emailExist = $this->db->get_where('payment_aggregators', ['id !=' => $_POST['id'], 'email' => $_POST['email']]);
if ($emailExist->num_rows() == 0) {
$_POST['updated_at'] = (new DateTime())->format('Y-m-d H:i:s');
$this->db->where('id',$_POST['id']);
$this->db->update('payment_aggregators',$_POST);
echo json_encode(['code' => 200]);
}else{
echo json_encode(['code'=> 419 , 'message' => $this->lang->line("L'email entré est déjà utilisé")]);
}
}
}
}
public function deletePaymentAggregator(){
if($this->isLogged()) {
if (isset($_POST)) {
$this->db->delete('payment_aggregators', ['id' => $_POST['id']]);
echo json_encode(['code' => 200]);
}
}
}
public function enableAggregator()
{
if($this->isLogged()) {
if (isset($_POST)) {
$date = (new DateTime())->format('Y-m-d H:i:s');
$this->db->update('payment_aggregators',['status' => 0 , 'updated_at' => $date]);
$this->db->where('id',$_POST['id']);
$this->db->update('payment_aggregators',['status' => 1 , 'updated_at' => $date]);
echo json_encode(['code' => 200]);
}
}
}
public function isLogged()
{
if (!$this->session->userdata('email')) {
$this->session->set_flashdata('error', 'log in first');
$data['alert'] = "ok";
$data['message'] = "Login first!";
$this->load->view('login', $data);
return false;
}
return true;
}
}