-
Notifications
You must be signed in to change notification settings - Fork 0
/
ideal_payment_api.module
executable file
·473 lines (432 loc) · 15.5 KB
/
ideal_payment_api.module
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?php
// $Id: q_menu.module,v 6-x-0.1 2008/07/08 15:31:52 qrios Exp $
// $Id$
/**
* @file
* Generic iDEAL payment API module for iDEAL payment processing. No shoppingcart module needed.
* For iDEAL ING/PB Advanced & RABO Professional
*
* Development by Qrios | http://www.qrios.nl | c.kodde {at} qrios {dot} nl
*
*
*/
//First load include based on available lib
$lib = ideal_payment_api_get_lib();
$path_module = drupal_get_path('module', 'ideal_payment_api');
if ($lib == 'thinmpi'){
require_once($path_module.'/ideal_payment_api_thinmpi.inc.php');
}
elseif ($lib == 'connector'){
require_once($path_module.'/ideal_payment_api_connector.inc.php');
}
/**
* Implementation of hook_help().
*/
function ideal_payment_api_help($section = '') {
$output = '';
switch ($section) {
case "admin/help#ideal_payment_api":
$output = t("Generic iDEAL payment API module for iDEAL payment processing. No shoppingcart module needed.");
break;
}
return $output;
}
/**
* Implementation of hook_cron().
*/
function ideal_payment_api_cron() {
ideal_payment_api_refresh_issuerlist();
ideal_payment_api_auto_recheck();
}
/**
* Implementation of hook_menu().
*/
function ideal_payment_api_menu() {
$items['admin/settings/ideal'] = array(
'title' => 'iDEAL Payment API',
'description' => 'iDEAL Payment API settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('ideal_payment_api_admin_settings'),
'access arguments' => array('administer iPAPI'),
'type' => MENU_NORMAL_ITEM,
);
$items['ideal/payment_test'] = array(
'title' => 'iDEAL Payment API Test',
'description' => 'iDEAL Payment API Test.',
'page callback' => 'ideal_payment_api_test',
'access arguments' => array('administer iPAPI'),
'type' => MENU_NORMAL_ITEM,
);
$items['ideal/payment_statreq'] = array(
'title' => t('IDEAL Payment status request'),
'page callback' => 'ideal_payment_api_statreq_call',
'page arguments' => array(FALSE, FALSE),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['ideal/payment_statreq_recheck'] = array(
'title' => t('iDEAL Statusrequest recheck'),
'description' => t('Manual Statusrequest for iDEAL payments.'),
'page callback' => 'ideal_payment_api_statreq_recheck',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_perm().
*/
function ideal_payment_api_perm() {
return array('administer iPAPI', 'make iPAPI payments');
}
/**
* Menu callback; presents the sitemap settings page.
*/
function ideal_payment_api_admin_settings() {
$form['ideal_payment_api_privatekey'] = array(
'#type' => 'textfield',
'#title' => t('privatekey'),
'#default_value' => variable_get('ideal_payment_api_privatekey', 'priv.pem'),
'#description' => t('The private key .pem file located in */security.'),
);
$form['ideal_payment_api_privatekeypass'] = array(
'#type' => 'textfield',
'#title' => t('privatekeypass'),
'#default_value' => variable_get('ideal_payment_api_privatekeypass', ''),
'#description' => t('The private key password used for generating the key file.'),
'#required' => TRUE,
);
$form['ideal_payment_api_privatecert'] = array(
'#type' => 'textfield',
'#title' => t('privatecert'),
'#default_value' => variable_get('ideal_payment_api_privatecert', 'cert.cer'),
'#description' => t('The private certificate .cer file located in */security.'),
'#required' => TRUE,
);
$form['ideal_payment_api_authenticationtype'] = array(
'#type' => 'textfield',
'#title' => t('authenticationtype'),
'#default_value' => variable_get('ideal_payment_api_authenticationtype', 'SHA1_RSA'),
'#description' => t('Authentication type protocol. Leave SHA1_RSA default if unsure.'),
'#required' => TRUE,
);
$form['ideal_payment_api_certificate0'] = array(
'#type' => 'textfield',
'#title' => t('certificate0'),
'#default_value' => variable_get('ideal_payment_api_certificate0', 'ideal.cer'),
'#description' => t('Certificate0 contains the signing certificate of your acquirer. This would probably be ideal.cer or webserver.cer.'),
'#required' => TRUE,
);
$form['ideal_payment_api_acquirerurl'] = array(
'#type' => 'textfield',
'#title' => t('acquirerurl'),
'#default_value' => variable_get('ideal_payment_api_acquirerurl', 'ssl://idealtest.secure-ing.com:443/ideal/iDeal'),
'#description' => t('Address of the iDEAL acquiring server. Use ssl://idealtest.secure-ing.com:443/ideal/iDeal during integration/test. Use ssl://ideal.secure-ing.com:443/ideal/iDeal only for production. Look into integration documents for Rabo equivalents.'),
'#required' => TRUE,
);
$form['ideal_payment_api_acquirertimeout'] = array(
'#type' => 'textfield',
'#title' => t('acquirertimeout'),
'#default_value' => variable_get('ideal_payment_api_acquirertimeout', '10'),
'#description' => t('Do not change AcquirerTimeout unless you have specific reasons to do so.'),
'#required' => TRUE,
);
$form['ideal_payment_api_merchantid'] = array(
'#type' => 'textfield',
'#title' => t('merchantid'),
'#default_value' => variable_get('ideal_payment_api_merchantid', '000000000'),
'#description' => t('Default MerchantID enables you to test the example demoshop. Your own Merchant ID can be retrieved via the iDEAL Dashboard.'),
'#required' => TRUE,
);
$form['ideal_payment_api_subid'] = array(
'#type' => 'textfield',
'#title' => t('subid'),
'#default_value' => variable_get('ideal_payment_api_subid', '0'),
'#description' => t('Do not change subID unless you have specific reasons to do so.'),
);
$form['ideal_payment_api_currency'] = array(
'#type' => 'textfield',
'#title' => t('currency'),
'#default_value' => variable_get('ideal_payment_api_currency', 'EUR'),
'#description' => t('Do not change currency unless you have specific reasons to do so'),
'#required' => TRUE,
);
$form['ideal_payment_api_expirationperiod'] = array(
'#type' => 'textfield',
'#title' => t('expirationperiod'),
'#default_value' => variable_get('ideal_payment_api_expirationperiod', 'PT10M'),
'#description' => t('ExpirationPeriod is the timeframe during which the transaction is allowed to take place. Maximum is PT1H (1 hour).'),
'#required' => TRUE,
);
$form['ideal_payment_api_language'] = array(
'#type' => 'textfield',
'#title' => t('language'),
'#default_value' => variable_get('ideal_payment_api_language', 'nl'),
'#description' => t('Language is only used for showing errormessages in the prefered language. nl/en.'),
'#required' => TRUE,
);
return system_settings_form($form);
}
//The Payment Page API
/**
* Arguments:
* $order_id, $order_desc, $order_total, $path_back_error, $path_back_succes
*
* $order_id, integer, must be unique, or else payment will be rejected
* $order_desc, string
* $order_total, decimal number ###,##
* $path_back_error, string, drupal path to redirect to on unsuccesfull payment. Probably the originating product/order form.
* $path_back_succes, string, drupal path to redirect to on succesfull payment. Probably the home page or a "thank you" page.
* All arguments are required
*/
function ideal_payment_api_payment_page($order_id, $order_desc, $order_total, $path_back_error, $path_back_succes) {
//Check permissions
if (user_access('make iPAPI payments')) {
//Fill TransReq session var
$order = array(
'order_id' => $order_id,
'description' => $order_desc,
'amount' => $order_total * 100, //amount *100
'path_back_error' => $path_back_error,
'path_back_succes' => $path_back_succes,
);
$form_html = drupal_get_form('ideal_payment_api_issuer_form', $order);
return $form_html;
}
else{
drupal_set_message(t('Sorry, you have no privelidges to make payments.') . $order_id, 'warning');
return FALSE;
}
}
/**
* Refresh issuer list
*/
function ideal_payment_api_refresh_issuerlist() {
$arr_issuers = ideal_payment_api_dirreq_call();
if (is_array($arr_issuers) && count($arr_issuers) > 0) {
db_query("TRUNCATE TABLE {ideal_payment_api_issuers}");
foreach ($arr_issuers as $issuer) {
db_query("INSERT INTO {ideal_payment_api_issuers} (iss_id, iss_name) VALUES (%d, '%s')", $issuer->issuerID, $issuer->issuerName );
}
}
else {
//@TODO: move into watchdog. And present error in hook_requirements.
print_r($arr_issuers); //Contains error message
}
}
/**
* Load issuer form
*/
function ideal_payment_api_issuer_form($order) {
$form['order'] = array(
'#type' => 'value',
'#value' => $order,
);
//Load issuers
$options['choose'] = t('Choose your bank...');
$result = db_query('SELECT * FROM {ideal_payment_api_issuers} ORDER BY iss_id ASC');
while ($row = db_fetch_object($result)) {
$options[$row->iss_id] = $row->iss_name;
}
$form['ideal_dirreq_form'] = array(
'#type' => 'fieldset',
'#title' => t('Please choose your bank'),
'#collapsible' => FALSE,
'#description' => t('You will be returned to this website after completing your IDEAL payment transaction.'),
);
$form['ideal_dirreq_form']['issuer'] = array(
'#type' => 'select',
'#default_value' => NULL,
'#options' => $options,
'#disabled' => empty($options) ? TRUE : FALSE,
'#required' => TRUE,
'#weight' => 0,
);
$form['ideal_dirreq_form']['submit'] = array(
'#type' => 'submit',
'#value' => t('Go to my bank') .' ->',
'#weight' => 1,
);
return $form;
}
/**
* Validate issuer form
*/
function ideal_payment_api_issuer_form_validate($form, $form_state) {
$issuer = $form_state['values']['issuer'];
if ($issuer == 'choose') {
form_set_error('issuer', t('Please select your bank.'));
}
if (empty($form_state['order'])) {
form_set_error('order', t('You did not provide an order, probably due to a technical issue.'));
}
}
/**
* Submit issuer form
*/
function ideal_payment_api_issuer_form_submit($form, &$form_state) {
ideal_payment_api_transreq_call($form_state['values']['issuer']);
}
/**
* Theme issuer form/
* @ingroup theme
*/
function theme_ideal_payment_api_issuer_form($form) {
dpm($form['order']);
$output = '';
$output .= '<div class="order">';
$output .= $form['order']['#value']['description']; //no filter_xss, because often we get a table. Passer should escape XSS!
$output .= '</div>';
$output .= drupal_render($form);
return $output;
}
/**
* Recheck payment status manually
*/
function ideal_payment_api_statreq_recheck() {
$form_html = drupal_get_form('ideal_payment_api_statreq_recheck_form', $form);
}
/*
* Load status recheck form
*/
function ideal_payment_api_statreq_recheck_form() {
$form['ideal_dirreq_form']['submit'] = array(
'#type' => 'submit',
'#value' => t('Recheck my payment status') .' ->',
'#weight' => 1,
);
return $form;
}
/*
* Load status recheck form
*/
function ideal_payment_api_statreq_recheck_form_submit($form, &$form_state) {
$order = ideal_payment_api_order_load($form_state['order']['order_id']);
ideal_payment_api_statreq_call($order);
}
/*
* Automated status request
*/
function ideal_payment_api_auto_recheck() {
$result = db_query('SELECT * FROM {ideal_payment_api_orders} WHERE payment_status = 0');
while ($order = db_fetch_array($result)) {
$order['order_id'] = $order['oid']; //To be compatible with order session var
ideal_payment_api_statreq_call($order, TRUE);
}
}
/**
*----------------
*Helper functions
*/
/**
* Get configuration
*/
function LoadConfiguration() {
$url_base = url(NULL, array('absolute' => TRUE));
//Load configuration in array
$arr_conf = array(
'PRIVATEKEY' => filter_xss(variable_get('ideal_payment_api_privatekey', 'priv.pem')),
'PRIVATEKEYPASS' => filter_xss(variable_get('ideal_payment_api_privatekeypass', FALSE)),
'PRIVATECERT' => filter_xss(variable_get('ideal_payment_api_privatecert', 'cert.cer')),
'AUTHENTICATIONTYPE' => filter_xss(variable_get('ideal_payment_api_authenticationtype', 'SHA1_RSA')),
'CERTIFICATE0' => filter_xss(variable_get('ideal_payment_api_certificate0', 'ideal.cer')),
'ACQUIRERURL' => filter_xss(variable_get('ideal_payment_api_acquirerurl', 'ssl://idealtest.secure-ing.com:443/ideal/iDeal')),
'ACQUIRERTIMEOUT' => filter_xss(variable_get('ideal_payment_api_acquirertimeout', 10)),
'MERCHANTID' => check_plain(variable_get('ideal_payment_api_merchantid', '000000000')),
'SUBID' => filter_xss(variable_get('ideal_payment_api_subid', 0)),
'MERCHANTRETURNURL' => $url_base.'ideal/payment_statreq',
'CURRENCY' => filter_xss(variable_get('ideal_payment_api_currency', 'EUR')),
'EXPIRATIONPERIOD' => filter_xss(variable_get('ideal_payment_api_expirationperiod', 'PT10M')),
'LANGUAGE' => filter_xss(variable_get('ideal_payment_api_language', 'nl')),
//debug
//'LOGFILE' => 'Connector_log.txt',
//'TraceLevel' => 'DEBUG,ERROR',
);
//IMPORTANT, 'DESCRIPTION' is bound to max. 32 chars!!
$arr_conf['DESCRIPTION'] = t('order# ') . $_SESSION['ideal_payment_api_order_data']['order_id'];
return $arr_conf;
}
/**
* Lookup installed PHP iDEAL lib
*/
function ideal_payment_api_get_lib() {
$path_module = drupal_get_path('module', 'ideal_payment_api');
if (file_exists($path_module.'/lib/ThinMPI.php')) {
$lib = 'thinmpi'; //Rabo + old ING
}
elseif (file_exists($path_module.'/lib/iDEALConnector.php')) {
$lib = 'connector'; //New ING
}
return $lib;
}
/**
* Save order
*/
function ideal_payment_api_order_save($order_id, $user_id, $description, $amount, $issuer_id, $transaction_id, $payment_status) {
//Save order
if ($order_id = NULL) {
$order_id = db_next_id('ideal_payment_api_orders');
$inserted = db_query("INSERT INTO {ideal_payment_api_orders} (user_id, description, amount, issuer_id, transaction_id, payment_status) VALUES
(%d,'%s', %d, '%s', '%s', %d)", $user_id, $description, $amount, $issuer_id, $transaction_id, $payment_status);
}
else {
$inserted = db_query("INSERT INTO {ideal_payment_api_orders} (oid, user_id, description, amount, issuer_id, transaction_id, payment_status) VALUES
(%d, %d,'%s', %d, '%s', '%s', %d)", $order_id, $user_id, $description, $amount, $issuer_id, $transaction_id, $payment_status);
}
if ($inserted) {
return $order_id;
}
else {
return 0;
}
}
/**
* Update order status
*/
function ideal_payment_api_order_update($order_id, $payment_status) {
if (db_query("UPDATE {ideal_payment_api_orders} SET payment_status = %d WHERE oid = %d", $payment_status, $order_id)) {
if ($payment_status == 1) {
//Destroy session order var when payment is OK
unset($_SESSION['ideal_payment_api_order_data']);
}
return TRUE;
}
else {
return FALSE;
}
}
/**
* Delete order
*/
function ideal_payment_api_order_delete($order_id) {
if (db_query("DELETE FROM {ideal_payment_api_orders} WHERE oid = %d", $order_id)) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Load order
*/
function ideal_payment_api_order_load($order_id) {
$result = db_query("SELECT * FROM {ideal_payment_api_orders} WHERE oid = %d", $order_id);
$order = db_fetch_array($result);
if (is_array($order)) {
return $order;
}
else {
return FALSE;
}
}
/**
* Test this API
*/
function ideal_payment_api_test() {
$order_id = 800;
$order_desc = 'test opmerking';
$order_total = '315';
$path_back_error = 'ideal/payment_test';
$path_back_succes = NULL; // = home
return ideal_payment_api_payment_page($order_id, $order_desc, $order_total, $path_back_error, $path_back_succes);
}