-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathauthnet_app_model.php
More file actions
executable file
·83 lines (72 loc) · 2.92 KB
/
authnet_app_model.php
File metadata and controls
executable file
·83 lines (72 loc) · 2.92 KB
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
class AuthnetAppModel extends AppModel {
public $log = array(); // false to disable
public $logModel = 'AuthnetTransactionLog'; // false to disable
public $config = array(
'AuthnetPluginVersion' => '1.0',
'logModel' => 'Authnet.AuthnetTransactionLog',
'logModel.useTable' => null,
);
/**
* Updates config from: app/config/authnet_config.php
* Sets up $this->logModel
* @param mixed $id
* @param string $table
* @param mixed $ds
*/
public function __construct($id = false, $table = null, $ds = null) {
// Default minimum config
$config = set::merge(array('login' => null, 'key' => null), $this->config);
// Try an import the plugins/authnet/config/authnet_config.php file and merge
// any default and datasource specific config with the defaults above
if (App::import(array('type' => 'File', 'name' => 'AUTHNET.AUTHNET_CONFIG', 'file' => APP.'config'.DS.'authnet_config.php'))) {
$AUTHNET_CONFIG = new AUTHNET_CONFIG();
if (isset($AUTHNET_CONFIG->config)) {
$config = set::merge($config, $AUTHNET_CONFIG->config);
}
} elseif (App::import(array('type' => 'File', 'name' => 'AUTHNET.AUTHNET_CONFIG', 'file' => 'config'.DS.'authnet_config.php'))) {
if (isset($AUTHNET_CONFIG->config)) {
$config = set::merge($config, $AUTHNET_CONFIG->config);
}
}
// Add any config from Configure class that you might have added at any
// point before the model is instantiated.
if (($configureConfig = Configure::read('AUTHNET.config')) != false) {
$config = set::merge($config, $configureConfig);
}
// double-check we have required keys
if (empty($config['login']) || empty($config['login'])) {
trigger_error(__d('authnet', "Invalid AUTHNET Configuration, missing 'login' field.", true), E_USER_WARNING);
die();
} elseif (empty($config['key']) || empty($config['key'])) {
trigger_error(__d('authnet', "Invalid AUTHNET Configuration, missing 'key' field.", true), E_USER_WARNING);
die();
}
$this->config = $config;
// initialize extras: transaction log model
if (!empty($this->config['logModel'])) {
if (App::import('model', $this->config['logModel'])) {
$this->logModel = ClassRegistry::init(array_pop(explode('.', $this->config['logModel'])));
if (isset($this->config['logModel.useTable']) && $this->config['logModel.useTable']!==null) {
$this->logModel->useTable = $this->config['logModel.useTable'];
}
}
}
ConnectionManager::create($this->useDbConfig, $config);
$db =& ConnectionManager::getDataSource($this->useDbConfig);
parent::__construct($id, $table, $ds);
}
/**
* Simple function to return the $config array
* @param array $config if set, merge with existing array
* @return array $config
*/
public function config($config = array()) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
if (!empty($config) && is_array($config)) {
$db->config = set::merge($db->config, $config);
}
return $db->config;
}
}
?>