-
Notifications
You must be signed in to change notification settings - Fork 3
/
commerce_sagepay.module
83 lines (68 loc) · 2.02 KB
/
commerce_sagepay.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
<?php
/**
* @file
* Contains commerce_sagepay.module.
*/
define('COMMERCE_SAGEPAY_MODULE_PATH', dirname(__FILE__) . '/src');
use Drupal\commerce_sagepay\HelperSetup;
use Drupal\commerce_sagepay\SetupException;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function commerce_sagepay_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the commerce_sagepay module.
case 'help.page.commerce_sagepay':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides Integration with the SagePay Payment Gateway (http://www.sagepay.com) using Form, Server or Token method.') . '</p>';
return $output;
default:
}
}
/**
* Autoload class handler.
*/
function commerce_sagepay_autoloader($class) {
$filepath = '';
for ($i = 0, $n = strlen($class); $i < $n; $i++) {
$char = $class[$i];
if (preg_match('/[A-Z]/', $char)) {
$char = '/' . strtolower($char);
}
$filepath .= $char;
}
$filename = COMMERCE_SAGEPAY_MODULE_PATH . $filepath . '.php';
if (file_exists($filename)) {
include $filename;
}
}
/**
* Exception handler function.
*/
function commerce_sagepay_exception_handler($ex) {
SagepayUtil::log("Exception:" . $ex->getMessage() . PHP_EOL . $ex->getTraceAsString());
if ($ex instanceof SetupException) {
die('Setup error: ' . $ex->getMessage());
}
else {
die(
'An unexpected error seems to have occurred.<br/>
Try to refresh the page or you can contact us if the problem persist.' . $ex->getMessage()
);
}
}
spl_autoload_register('commerce_sagepay_autoloader');
set_exception_handler('commerce_sagepay_exception_handler');
require_once COMMERCE_SAGEPAY_MODULE_PATH . '/Sagepay/sagepay.php';
if (!function_exists('url')) {
/**
* Define alias for HelperCommon::url.
*/
function url() {
$args = func_get_args();
return call_user_func_array('HelperCommon::url', $args);
}
}
HelperSetup::checkDependencies();