-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitcoinpayflow.php
More file actions
130 lines (82 loc) · 3.45 KB
/
bitcoinpayflow.php
File metadata and controls
130 lines (82 loc) · 3.45 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
129
130
<?php
class bitcoinPayFlow {
//API Configuration
const API_URL = 'https://bitcoinpayflow.com/';
const RESULT_FORMAT = 'array'; //default is 'json'
const EXT = '.php';
private $apiMethods = array('orders', 'tokens');
public function __construct(){
}
public function __call($method, $params = array()) {
$this->_validateMethod($method);
$url = $this->_buildUrl($method);
print_r($url);
$options = $this->_buildParams($method , $params);
// @REMOVE Output POST variables
pre_print($options, 'POST:' . $method);
$result = $this->_connect($url, $options);
$result = $this->_formatResults($result);
return $result;
}
private function _buildParams($method, $params = array()){
foreach ($params[0] as $k => $v){
$options[$k] = $v;
}
return $options;
}
private function _buildUrl($method){
$url = self::API_URL . $method;
return $url;
}
private function _validateMethod($method){
if(in_array($method, $this->apiMethods)){
return TRUE;
} else {
die('FAILURE: Unknown Method');
}
}
private function _formatResults($results){
if(self::RESULT_FORMAT == strtolower('array')){
$results = json_decode($results, true);
}
return $results;
}
private function _connect($url, $params = NULL){
//open connection
$ch = curl_init();
//set the url
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, TRUE);
//add POST fields
if ($params != NULL){
//url encode params array before POST
$postData = http_build_query($params, '', '&');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
//curl_setopt($ch,CURLOPT_HTTPHEADER,array());
//MUST BE REMOVED BEFORE PRODUCTION (USE for SSL)
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; BTChash; '
.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
//execute CURL connection
$returnData = curl_exec($ch);
//$code = $this->returnCode($returnData);
if( $returnData === false)
{
die('<br />Connection error:' . curl_error($ch));
}
else
{
//Log successful CURL connection
}
//close CURL connection
curl_close($ch);
return $returnData;
}
}