-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector.php
143 lines (126 loc) · 4.69 KB
/
connector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
class BWFCO_SMSCRU extends BWF_CO {
public static $instance = null;
public $v2 = true;
/**
* Constructor.
*
* @since 2.0.0
*/
public function __construct() {
$this->connector_url = WFCO_SMSCRU_PLUGIN_URL;
$this->dir = __DIR__;
$this->nice_name = __('SMSC.ru', 'autonami-automations-connectors');
$this->autonami_int_slug = 'BWFAN_SMSCRU_Integration';
$this->keys_to_track = array(
'login',
'password',
);
$this->form_req_keys = array(
'login',
'password',
);
add_filter('wfco_connectors_loaded', array($this, 'add_card'));
}
/**
* Returns an instance of the class.
*
* @return BWFCO_SMSCRU
*/
public static function get_instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Returns an array of field schema for the SMSC.ru connector.
*
* The schema includes fields for login and password, each with their respective
* labels, types, classes, and placeholders. Both fields are required.
*
* @return array An array of field schema.
*/
public function get_fields_schema() {
return array(
array(
'id' => 'login',
'label' => __('Login', 'autonami-automations-connectors'),
'type' => 'text',
'class' => 'bwfan_smscru_login',
'placeholder' => __('Enter your SMSC.ru login', 'autonami-automations-connectors'),
'required' => true,
),
array(
'id' => 'password',
'label' => __('Password', 'autonami-automations-connectors'),
'type' => 'password',
'class' => 'bwfan_smscru_password',
'placeholder' => __('Enter your SMSC.ru password', 'autonami-automations-connectors'),
'required' => true,
),
);
}
/**
* Retrieves the saved settings fields values for the current connector.
*
* @return array An array containing the saved settings fields values.
*/
public function get_settings_fields_values() {
$saved_data = WFCO_Common::$connectors_saved_data;
$old_data = isset($saved_data[$this->get_slug()]) ? $saved_data[$this->get_slug()] : array();
return array(
'login' => isset($old_data['login']) ? $old_data['login'] : '',
'password' => isset($old_data['password']) ? $old_data['password'] : '',
);
}
/**
* Retrieves API data based on the provided login and password.
*
* @param array $posted_data An array containing the login and password.
* @return array An array containing the API data or an error message.
*/
protected function get_api_data($posted_data) {
$login = isset($posted_data['login']) ? $posted_data['login'] : '';
$password = isset($posted_data['password']) ? $posted_data['password'] : '';
WFCO_SMSCRU_Common::set_headers($login, $password);
$call_class = new WFCO_SMSCRU_Call();
$call_class->set_data(array(
'phones' => '79119387283', // Test phone number
'mes' => 'Test message',
));
$response = $call_class->process();
if ($response['status'] === 'success') {
return array(
'status' => 'success',
'api_data' => array(
'login' => $login,
'password' => $password,
),
);
} else {
return array(
'status' => 'failed',
'message' => $response['message'],
);
}
}
/**
* Adds the SMSC.ru connector to the list of available connectors.
*
* @param array $available_connectors The list of available connectors.
* @return array The updated list of available connectors with the SMSC.ru connector added.
*/
public function add_card($available_connectors) {
$available_connectors['autonami']['connectors']['bwfco_smscru'] = array(
'name' => 'SMSC.ru',
'desc' => __('Send SMS via SMSC.ru', 'autonami-automations-connectors'),
'connector_class' => 'BWFCO_SMSCRU',
'image' => $this->get_image(),
'source' => '',
'file' => '',
);
return $available_connectors;
}
}
WFCO_Load_Connectors::register('BWFCO_SMSCRU');