· 9 years ago · Aug 30, 2016, 04:08 AM
1<head>
2<? class indexController extends Controller {
3
4 // only for robokassa !!!
5 public function index()
6 {
7 $this->document->setActiveSection('tickets');
8 $this->document->setActiveItem('pay');
9
10 if(!$this->user->isLogged()) {
11 $this->session->data['error'] = "Вы не авторизированы!";
12 $this->response->redirect($this->config->url . 'account/login');
13 }
14 if($this->user->getAccessLevel() < 0) {
15 $this->session->data['error'] = "У Ð²Ð°Ñ Ð½ÐµÑ‚ доÑтупа к данному разделу!";
16 $this->response->redirect($this->config->url);
17 }
18 $this->load->model('users');
19 $this->load->model('invoices');
20
21 $this->data['user_balance'] = $this->user->getBalance();
22
23 $this->getChild(array('common/header', 'common/footer'));
24 return $this->load->view('worksheet/index', $this->data);
25 }
26
27 // for something...
28 public function indexaaa() {
29
30 $this->document->setActiveSection('account');
31 $this->document->setActiveItem('pay');
32
33 if(!$this->user->isLogged()) {
34 $this->session->data['error'] = "Вы не авторизированы!";
35 $this->response->redirect($this->config->url . 'account/login');
36 }
37 if($this->user->getAccessLevel() < 0) {
38 $this->session->data['error'] = "У Ð²Ð°Ñ Ð½ÐµÑ‚ доÑтупа к данному разделу!";
39 $this->response->redirect($this->config->url);
40 }
41 $this->load->model('users');
42 $this->load->model('invoices');
43 $secret_key = $this->config->ik_secretkey; // Ñекреткей
44 $ik_shop_id = $this->config->ik_shopid; // Ñвой ид магазина, который указан в наÑтройках магазина
45
46 $log_file = 'application/controllers/account/log.txt';
47
48 $err[1] = 'Ошибка - ÐÐµÐ²ÐµÑ€Ð½Ð°Ñ Ñумма платежа!';
49 $err[2] = 'Ошибка - Shop ID!';
50 $err[3] = 'Ошибка - Ðе верный ID платежа!';
51 $err[3] = 'Ошибка - Данный Ñчет уже оплачен!';
52 //Получение информации о платеже от ÑиÑтемы Interkassa
53 $post_shop_id = trim(stripslashes($_POST['ik_co_id'])); //Ðомер Ñайта продавца (eshopId);
54 $ik_payment_amount = trim(stripslashes($_POST['ik_payment_amount'])); //Сумма платежа (recipientAmount);
55 $ik_payment_id = trim(stripslashes($_POST['ik_payment_id'])); //Идентификатор платежа
56 $ik_pm_no = trim(stripslashes($_POST['ik_pm_no'])); //id
57 $ik_am = trim(stripslashes($_POST['ik_am'])); //im
58 $ik_paysystem_alias = trim(stripslashes($_POST['ik_paysystem_alias'])); //СпоÑоб оплаты
59 $ik_baggage_fields = trim(stripslashes($_POST['ik_baggage_fields'])); //пользовательÑкое поле
60 $ik_payment_state = trim(stripslashes($_POST['ik_payment_state'])); //Ð¡Ñ‚Ð°Ñ‚ÑƒÑ Ð¿Ð»Ð°Ñ‚ÐµÐ¶Ð° (paymentStatus);
61 $ik_trans_id = trim(stripslashes($_POST['ik_trans_id'])); //внутренний номер платежа
62 $ik_currency_exch = trim(stripslashes($_POST['ik_currency_exch'])); //Валюта платежа (recipientCurrency);
63 $ik_fees_payer = trim(stripslashes($_POST['ik_fees_payer'])); //плательщик комиÑÑии
64 //$ik_sign_hash = trim(stripslashes($_POST['ik_sign_hash'])); //ÐšÐ¾Ð½Ñ‚Ñ€Ð¾Ð»ÑŒÐ½Ð°Ñ Ð¿Ð¾Ð´Ð¿Ð¸ÑÑŒ
65
66 $sing_hash_str = $ik_shop_id.':'.
67 $ik_payment_amount.':'.
68 $ik_payment_id.':'.
69 $ik_paysystem_alias.':'.
70 $ik_baggage_fields.':'.
71 $ik_payment_state.':'.
72 $ik_trans_id.':'.
73 $ik_currency_exch.':'.
74 $ik_fees_payer.':'.$secret_key;
75
76 $log_data = $ik_am.':'.$ik_pm_no.':'.$ik_paysystem_alias.':'.$ik_payment_state.':'.$ik_trans_id.':'.$ik_currency_exch."\r\n";
77
78 //$sing_hash = strtoupper(md5($sing_hash_str));
79
80 $handle = fopen($log_file, "a");
81
82 $date_now = date("Y-m-d H:i:s");
83
84 fwrite($handle, 'DATA:'.$date_now.':'.utf8_encode($log_data));
85 $userid = $this->user->getId();
86 $invoice = $this->invoicesModel->getInvoiceById($ik_pm_no);
87 //if($ik_sign_hash === $sing_hash)
88 //{
89 if($invoice['invoice_ammount'] == $ik_am)
90 {
91 if($post_shop_id == $ik_shop_id)
92 {
93 if($invoice['invoice_id'] == $ik_pm_no)
94 {
95 if($invoice['invoice_status'] == 0)
96 {
97
98 $this->usersModel->upUserBalance($userid, $ik_am);
99 $this->invoicesModel->updateInvoice($ik_pm_no, array('invoice_status' => 1));
100 /*Success*/
101 }else{
102 $this->response->redirect($this->config->url . 'account/error');
103 $this->data['status'] = "error";
104 $this->data['error'] = $err[4];
105 }
106 }else{
107 $this->response->redirect($this->config->url . 'account/error');
108 $this->data['status'] = "error";
109 $this->data['error'] = $err[3];
110 }
111 }
112 else
113 {
114 fwrite($handle, $err[2].':'.$date_now.':'.$log_data);
115 $this->response->redirect($this->config->url . 'account/error');
116 $this->data['status'] = "error";
117 $this->data['error'] = $err[2];
118 }
119 }
120 else
121 {
122 fwrite($handle, $err[1].':'.$date_now.':'.$log_data);
123 $this->response->redirect($this->config->url . 'account/error');
124 $this->data['status'] = "error";
125 $this->data['error'] = $err[1];
126 }
127 //}
128 //else
129 //{
130 // fwrite($handle, $err[0].':'.$date_now.':'.$log_data);
131 //}
132
133 fclose($handle);
134 $this->getChild(array('common/header', 'common/footer'));
135 return $this->load->view('worksheet/index', $this->data);
136 }
137}?>