-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommerce_taxcloud.install
98 lines (87 loc) · 3.05 KB
/
commerce_taxcloud.install
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
<?php
/**
* @file
* Commerce TaxCloud requirements, installation, and uninstallation.
*/
/**
* Implements hook_requirements().
*/
function commerce_taxcloud_requirements() {
$api_id = variable_get('commerce_taxcloud_api_id');
$api_key = variable_get('commerce_taxcloud_api_key');
// Find Commerce TaxCloud capture actions.
$commerce_taxcloud_actions = array('commerce_taxcloud_action_capture', 'commerce_taxcloud_action_authorize_capture');
drupal_alter('commerce_taxcloud_actions', $commerce_taxcloud_actions);
$rules_cache = rules_get_cache();
// Check if Commerce TaxCloud capture actions are enabled.
$actions_enabled = FALSE;
$rules = rules_config_load_multiple(FALSE);
foreach ($rules as $rule) {
if (get_class($rule) == 'RulesReactionRule') {
foreach ($rule->actions() as $action) {
if (get_class($action) == 'RulesAction') {
if (in_array($action->getElementName(), $commerce_taxcloud_actions) && $rule->active == 1) {
$actions_enabled = TRUE;
}
}
}
}
}
$t = get_t();
$requirements = array();
$info = libraries_load('php-taxcloud');
if (!$info['loaded']) {
$requirements['commerce_taxcloud'] = array(
'severity' => REQUIREMENT_WARNING,
'title' => $t('Commerce TaxCloud Integration'),
'value' => $t('Failed to load the PHP-TaxCloud library.'),
'description' => $t('Please make sure the PHP-TaxCloud library is installed in the libraries directory'),
);
}
elseif (empty($api_id) || empty($api_key)) {
$requirements['commerce_taxcloud'] = array(
'severity' => REQUIREMENT_WARNING,
'title' => $t('Commerce TaxCloud Integration'),
'value' => $t('API ID or API Key not set.'),
'description' => $t('Please make sure to set the API ID and API Key for TaxCloud.'),
);
}
elseif (!$actions_enabled) {
$requirements['commerce_taxcloud'] = array(
'severity' => REQUIREMENT_WARNING,
'title' => $t('Commerce TaxCloud Integration'),
'value' => $t('No actions are enabled.'),
'description' => $t('TaxCloud requires that transactions are captured. You cannot just use the service only for Lookups.'),
);
}
else {
$requirements['commerce_taxcloud'] = array(
'serverity' => REQUIREMENT_OK,
'title' => $t('Commerce TaxCloud Integration'),
'value' => $t('OK'),
);
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function commerce_taxcloud_schema() {
// Set up our cache table.
$schema['cache_commerce_taxcloud'] = drupal_get_schema_unprocessed('system', 'cache');
return $schema;
}
/**
* Implements hook_uninstall().
*/
function commerce_taxcloud_uninstall() {
variable_del('commerce_taxcloud_api_id');
variable_del('commerce_taxcloud_api_key');
variable_del('commerce_taxcloud_usps_id');
variable_del('commerce_taxcloud_address1');
variable_del('commerce_taxcloud_address2');
variable_del('commerce_taxcloud_city');
variable_del('commerce_taxcloud_state');
variable_del('commerce_taxcloud_zip');
variable_del('commerce_taxcloud_enable');
}