-
Notifications
You must be signed in to change notification settings - Fork 5
/
class-pc-utils.php
executable file
·70 lines (58 loc) · 2.01 KB
/
class-pc-utils.php
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
<?php
class PointCheckout_Card_Utils extends PointCheckout_Card_Parent
{
private $pcConfig;
public function __construct()
{
parent::__construct();
$this->pcOrder = new PointCheckout_Card_Order();
$this->pcConfig = PointCheckout_Card_Config::getInstance();
}
public function apiCall($url, $body)
{
try {
$headers = array(
'Content-Type: application/json',
'X-PointCheckout-Api-Key:' . $this->pcConfig->getApiKey(),
'X-PointCheckout-Api-Secret:' . $this->pcConfig->getApiSecret()
);
$_BASE_URL = $this->getApiBaseUrl() . $url;
$ch = curl_init($_BASE_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if (!is_null($body)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$response = curl_exec($ch);
} catch (Exception $e) {
$this->log('Failed to connect call PointChckout API: ' . $e->getMessage());
throw $e;
}
return json_decode($response);
}
public function log($messages)
{
$logger = wc_get_logger();
$logger->error($messages, 'pointcheckout_card');
}
public function getApiBaseUrl()
{
if ($this->pcConfig->isLiveMode()) {
return 'https://api.pointcheckout.com/mer/v2.0/';
} elseif ($this->pcConfig->isStagingMode()) {
return 'https://api.staging.pointcheckout.com/mer/v2.0/';
} else {
return 'https://api.test.pointcheckout.com/mer/v2.0/';
}
}
public function getAdminUrl()
{
if ($this->pcConfig->isLiveMode()) {
return 'https://admin.pointcheckout.com';
} elseif ($this->pcConfig->isStagingMode()) {
return 'https://admin.staging.pointcheckout.com';
} else {
return 'https://admin.test.pointcheckout.com';
}
}
}