· 4 years ago · Feb 13, 2021, 05:28 AM
1 public function QiwiHandler(){
2 model("Donation", "Alert", "Widget", "Filter");
3 require_once($_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php'); // Require autoload file generated by composer
4 $billPayments = new Qiwi\Api\BillPayments($this->config->qiwi["secret_key"]);
5 $postData = file_get_contents('php://input');
6 $data = json_decode($postData, 1);
7 $log_file = fopen($_SERVER['DOCUMENT_ROOT'] . '/app/controllers/qiwi.txt', 'a+');
8 fwrite($log_file, print_r(json_decode(file_get_contents('php://input')), true).PHP_EOL);
9 fwrite($log_file, print_r(getallheaders(), true).PHP_EOL);
10 fclose($log_file);
11 $donation = $this->DonationModel->getDonationInfo($data['bill']['customer']['account']);
12 if($data['bill']['status']['value'] == 'PAID'){
13 $validSignatureFromNotificationServer = $_SERVER['HTTP_X_API_SIGNATURE_SHA256'];
14 $notificationData = [
15 'bill' => [
16 'siteId' => $this->config->qiwi["public_key"],
17 'billId' => $donation['donation_id'].'-'.hash('sha256', $id.'RUB'.$donation['donation_ammount'].$donation['donation_create_time']).'-'.$donation['user_id'],
18 'amount' => ['value' => $data['bill']['amount']['value'], 'currency' => 'RUB'],
19 'status' => ['value' => 'PAID']
20 ],
21 'version' => '3'
22 ];
23 $secretKey = $this->config->qiwi["secret_key"];
24
25 $billPayments->checkNotificationSignature(
26 $validSignatureFromNotificationServer, $notificationData, $secretKey
27 );
28 if ($donation['donation_id'] == $data['bill']['customer']['account'] && $donation['donation_status'] == 0) {
29 if(!$this->DonationModel->editDonation($donation['donation_id'], [
30 "donation_end_time" => "NOW()",
31 "donation_status" => 1,
32 "donation_ammount" => (float) $donation['donation_ammount'],
33 ]));
34 $donation['donation_json'] = json_decode($donation['donation_json']);
35
36 if(!empty($donation['donation_json']->goal)){
37 $w_goal = $this->WidgetModel->getWidgetMoney($donation['donation_json']->goal);
38
39 $this->WidgetModel->editWidget($donation['donation_json']->goal, [
40 "widget_money" => $w_goal + (float) $donation['donation_ammount'],
41 ]);
42
43 $this->AlertModel->newAlert([
44 "widget_id" => $donation['donation_json']->goal,
45 "user_name" => $donation['donation_name'],
46 "sum" => (float) $donation['donation_ammount'],
47 "curr" => "RUB",
48 "type" => 1,
49 ], true);
50 }
51
52 $widgets = $this->WidgetModel->getUserAlertsWidget($donation['user_id']);
53 foreach ($widgets as $widget)
54 {
55 $this->AlertModel->newAlert([
56 "widget_id" => $widget['widget_id'],
57 "msg" => $this->FilterModel->url_to_html_element(base64_decode($donation['donation_json']->text)),
58 "user_name" => $donation['donation_name'],
59 "sum" => (float) $donation['donation_ammount'],
60 "curr" => "RUB",
61 "type" => 3,
62 ], true);
63 //$name = urlencode($this->FilterModel->url_to_html_element(base64_decode($donation['donation_json']->text)));
64 //file_get_contents("https://api.sdonate.ru/voice.php?text=".$this->FilterModel->url_to_html_element(base64_decode($donation['donation_json']->text))."&name=".$this->FilterModel->url_to_html_element(base64_decode($donation['donation_json']->text)));
65 }
66 }
67 }
68 }