-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoplata.admin.inc
230 lines (195 loc) · 7.16 KB
/
oplata.admin.inc
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/**
* @file
* Oplata.md admin form.
*/
/**
* Oplata.md module default settings form.
*/
function oplata_settings() {
$form = array();
$form['oplata_urlkey'] = array(
'#type' => 'textfield',
'#required' => true,
'#title' => t('URLKEY'),
'#default_value' => variable_get('oplata_urlkey', '')
);
$form['oplata_key'] = array(
'#type' => 'textfield',
'#required' => true,
'#title' => t('KEY'),
'#description' => t('The key of your shop.'),
'#default_value' => variable_get('oplata_key', '')
);
$form['oplata_oplid'] = array(
'#type' => 'textfield',
'#required' => true,
'#title' => t('OPLID'),
'#description' => t('The number of your shop.'),
'#default_value' => variable_get('oplata_oplid', '')
);
$form['oplata_cert'] = array(
'#type' => 'textfield',
'#required' => true,
'#title' => t('Path to certificat-file'),
'#description' => t('The relative path to the certificat file.'),
'#default_value' => variable_get('oplata_cert', '')
);
$form['oplata_ssl_version'] = array(
'#type' => 'select',
'#required' => true,
'#title' => t('SSL version'),
'#options' => array(2=>2,3=>3,),
'#default_value' => variable_get('oplata_ssl_version', 3)
);
$response = Oplata::inst()->getRates();
$currency = array();
foreach ($response as $id => $rate) {
$currency[$id] = $rate['currency'];
}
$form['oplata_granulity'] = array(
'#type' => 'textfield',
'#title' => t('Granulity'),
'#description' => t('Amount granulity. Possible only decimal values. Values must be separated by ";".'),
'#default_value' => variable_get('oplata_granulity', "5;10;20;50;75;100")
);
$form['oplata_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Debug mode'),
'#description' => t('If enabled the debug data can be saved into the log-files.'),
'#default_value' => variable_get('oplata_debug', 0)
);
$form['oplata_checkout_user_guide'] = array(
'#type' => 'textarea',
'#title' => t('Checkout user guide'),
'#default_value' => variable_get('oplata_checkout_user_guide', 'Checkout user guide
Do not close the page until confirmation of payment.'),
);
$form['oplata_success_message'] = array(
'#type' => 'textarea',
'#title' => t('Transaction success message'),
'#description' => t('Customize the success message. Allowable variables: !shopdata, !qid, !account, !status, !amount, !transid.'),
'#default_value' => variable_get('oplata_success_message', "Transaction succeed!
Transaction Id: !transid
Transaction number: !account
Amount: !amount
Oplata.md shop data: !shopdata")
);
$form['oplata_error_message'] = array(
'#type' => 'textarea',
'#title' => t('Transaction error message'),
'#description' => t('Customize the error message. Allowable variables: !status.'),
'#default_value' => variable_get('oplata_error_message', 'Transaction returns error code.')
);
$form['oplata_confirm_error_message'] = array(
'#type' => 'textarea',
'#title' => t('Transaction not confirmed message'),
'#default_value' => variable_get('oplata_confirm_error_message', 'The transaction not confirmed.')
);
$form['oplata_sign_error_message'] = array(
'#type' => 'textarea',
'#title' => t('Transaction signature error message'),
'#default_value' => variable_get('oplata_signature_error_message', 'Signature error! Please contact the site administrator.')
);
return system_settings_form($form);
}
/**
* Implementation of hook_validate().
*/
function oplata_settings_validate($form, &$form_state) {
if (!file_exists($file = getcwd().base_path().$form_state['values']['oplata_cert'])) {
form_set_error('oplata_cert', t('The certification file %file does not exists.', array('%file' => $file)));
}
}
/**
* Menu callback: manage the queue.
*/
function oplata_queue() {
$header = array(
array('data' => t('ID'), 'field' => 'q.qid'),
array('data' => t('User'), 'field' => 'u.uid'),
array('data' => t('Amount'), 'field' => 'q.amount'),
array('data' => t('Transaction ID')),
array('data' => t('Created'), 'field' => 'q.created', 'sort' => 'desc'),
array('data' => t('status'), 'field' => 'q.status'),
array('data' => t('Operations'), 'colspan' => 2),
);
$query = "SELECT q.*, u.uid, u.name FROM {oplata_queue} q
INNER JOIN {users} u ON u.uid=q.uid";
$tablesort = tablesort_sql($header);
$result = pager_query($query . $tablesort, 50);
$rows = array();
while ($row = db_fetch_object($result)) {
$rows[] = array(
$row->qid,
theme('username', $row),
$row->amount,
$row->transid,
$row->created,
$row->status,
$row->status=='wait' ? l(t('complete'), "admin/reports/oplata/{$row->qid}/complete") : '',
$row->status=='wait' ? l(t('emulate'), "admin/reports/oplata/{$row->qid}/emulate") : '',
);
}
$output = theme('table', $header, $rows);
$output .= theme('pager', 50);
return $output;
}
/**
* Menu callback: proceed the transaction.
*/
function oplata_transaction_proceed($form_state, $qid, $op) {
$form = array();
$form['transid'] = array(
'#type' => 'textfield',
'#title' => t('Transaction ID'),
'#maxlength' => 6,
'#required' => true,
);
$form['qid'] = array('#type' => 'hidden', '#value' => $qid);
$form['opt'] = array('#type' => 'hidden', '#value' => $op);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* Implementation of hook_submit().
*/
function oplata_transaction_proceed_submit($form, &$form_state) {
foreach ($form_state['values'] as $var => $value) $$var = $value;
db_query("UPDATE {oplata_queue} SET transid='%s' WHERE qid=%d", $transid, $qid);
$row = db_fetch_object(db_query("SELECT * FROM {oplata_queue} WHERE qid=%d", $qid));
if ($opt == 'emulate') {
$check = Oplata::inst()->getStatus($row->qid, $row->amount);
switch ($check) {
case '2':
db_query("UPDATE {oplata_queue} SET transid=%d, status='ok' WHERE qid=%d", $row->transid, $row->qid);
user_deposit_incoming($row->amount, 'Oplata.md', $row->qid, $row->uid);
drupal_set_message(t(variable_get('oplata_success_message', "Transaction succeed!
Transaction Id: !transid
Transaction number: !account
Amount: !amount
Oplata.md shop data: !shopdata"), array(
'!shopdata' => t('N/A'),
'!account' => $row->qid,
'!amount' => $row->amount,
'!transid' => $row->transid,
)));
break;
case '1':
db_query("UPDATE {oplata_queue} SET transid=%d, status='fail' WHERE qid=%d", $row->transid, $row->qid);
drupal_set_message(t(variable_get('oplata_confirm_error_message', 'The transaction not confirmed.')), 'error');
break;
case '-1':
drupal_set_message(t(variable_get('oplata_signature_error_message', 'Signature error! Please contact the site administrator.')), 'error');
break;
}
} elseif ($opt == 'complete') {
db_query("UPDATE {oplata_queue} SET status='ok' WHERE qid=%d", $qid);
user_deposit_incoming($row->amount, 'Oplata.md', $row->qid, $row->uid);
drupal_set_message(t('The transaction has been completed.'));
}
drupal_goto('admin/reports/oplata');
}