PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / trunk
Fluent Support – Helpdesk & Customer Support Ticket System vtrunk
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Services / Integrations / NotificationIntegrationBase.php

NotificationIntegrationBase.php in Fluent Support – Helpdesk & Customer Support Ticket System trunk, at app/Services/Integrations/NotificationIntegrationBase.php

83 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Services\Integrations;
4
5 use FluentSupport\App\Models\Meta;
6 use FluentSupport\App\Services\Helper;
7
8 abstract class NotificationIntegrationBase
9 {
10 abstract public function getSettings($withFields = false);
11
12 abstract public function getFields();
13
14 public function getKey()
15 {
16 return $this->key;
17 }
18
19 public function saveSettings($settings)
20 {
21 return $this->save($settings);
22 }
23
24 public function save($settings)
25 {
26 $exist = Meta::where('object_type', 'integration_settings')
27 ->where('key', $this->key)
28 ->first();
29
30 if ($exist) {
31 $exist->value = maybe_serialize($settings);
32 $exist->save();
33 } else {
34 $exist = Meta::insert([
35 'object_type' => 'integration_settings',
36 'key' => $this->key,
37 'value' => maybe_serialize($settings)
38 ]);
39 }
40
41 return $settings;
42 }
43
44 public function get()
45 {
46 $exist = Meta::where('object_type', 'integration_settings')
47 ->where('key', $this->key)
48 ->first();
49
50 if ($exist) {
51 return Helper::safeUnserialize($exist->value);
52 }
53
54 return false;
55 }
56
57 public function sendRequest($url, $params = [], $method = 'GET', $extraHeaders = [])
58 {
59 $request = wp_remote_request($url, [
60 'method' => $method,
61 'body' => $params,
62 'headers' => $extraHeaders
63 ]);
64
65 if (is_wp_error($request)) {
66 return new \WP_Error($request->get_error_code(), $request->get_error_message());
67 } else if (!$request) {
68 return new \WP_Error(423, __('API Request Error', 'fluent-support'), $request->get_error_data());
69 }
70
71 $code = wp_remote_retrieve_response_code($request);
72 $response = wp_remote_retrieve_body($request);
73
74 $response = json_decode($response, true);
75
76 if ($code > 299) {
77 return new \WP_Error($code, __('API Response Error', 'fluent-support'), $response);
78 }
79
80 return $response;
81 }
82 }
83