-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
executable file
·128 lines (117 loc) · 3.96 KB
/
Copy pathdb.php
File metadata and controls
executable file
·128 lines (117 loc) · 3.96 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
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
<?php
class plugins_stripe_db
{
/**
* @param $config
* @param bool $params
* @return mixed|null
* @throws Exception
*/
/**
* @var debug_logger $logger
*/
protected debug_logger $logger;
/**
* @param array $config
* @param array $params
* @return array|bool
*/
public function fetchData(array $config, array $params = []) {
if ($config['context'] === 'all') {
switch ($config['type']) {
case 'data':
$query = 'SELECT mo.* FROM mc_stripe AS mo';
break;
default:
return false;
}
try {
return component_routing_db::layer()->fetchAll($query, $params);
}
catch (Exception $e) {
if(!isset($this->logger)) $this->logger = new debug_logger(MP_LOG_DIR);
$this->logger->log('statement','db',$e->getMessage(),$this->logger::LOG_MONTH);
}
}
elseif ($config['context'] === 'one') {
switch ($config['type']) {
case 'root':
$query = 'SELECT * FROM mc_stripe ORDER BY id_stripe DESC LIMIT 0,1';
break;
case 'history':
$query = 'SELECT * FROM mc_stripe_history WHERE order_h = :order_h';
break;
case 'lastHistory':
$query = 'SELECT * FROM mc_stripe_history WHERE session_key_cart = :session_key_cart ORDER BY id_stripe_h DESC LIMIT 0,1';
break;
default:
return false;
}
try {
return component_routing_db::layer()->fetch($query, $params);
}
catch (Exception $e) {
if(!isset($this->logger)) $this->logger = new debug_logger(MP_LOG_DIR);
$this->logger->log('statement','db',$e->getMessage(),$this->logger::LOG_MONTH);
}
}
return false;
}
/**
* @param string $type
* @param array $params
* @return bool
*/
public function insert(string $type, array $params = []): bool {
switch ($type) {
case 'config':
$query = 'INSERT INTO mc_stripe (apikey, endpointkey, secret_signing_key)
VALUE(:apikey,:endpointkey, :secret_signing_key)';
break;
case 'history':
$query = 'INSERT INTO mc_stripe_history (session_key_cart,order_h,event_h,status_h)
VALUE(:session_key_cart,:order_h,:event_h,:status_h)';
break;
default:
return false;
}
try {
component_routing_db::layer()->insert($query,$params);
return true;
}
catch (Exception $e) {
if(!isset($this->logger)) $this->logger = new debug_logger(MP_LOG_DIR);
$this->logger->log('statement','db',$e->getMessage(),$this->logger::LOG_MONTH);
return false;
}
}
/**
* @param string $type
* @param array $params
* @return bool
*/
public function update(string $type, array $params = []): bool {
switch ($type) {
case 'config':
$query = 'UPDATE mc_stripe
SET
apikey=:apikey,
endpointkey=:endpointkey,
secret_signing_key=:secret_signing_key
WHERE id_stripe=:id';
break;
default:
return false;
}
try {
component_routing_db::layer()->update($query,$params);
return true;
}
catch (Exception $e) {
if(!isset($this->logger)) $this->logger = new debug_logger(MP_LOG_DIR);
$this->logger->log('statement','db',$e->getMessage(),$this->logger::LOG_MONTH);
return false;
}
}
}
?>