|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
|
4
|
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
|
6
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
|
7
|
|
|
use Padosoft\AffiliateNetwork\Merchant; |
|
8
|
|
|
use Padosoft\AffiliateNetwork\Stat; |
|
9
|
|
|
use Padosoft\AffiliateNetwork\Deal; |
|
10
|
|
|
use Padosoft\AffiliateNetwork\AbstractNetwork; |
|
11
|
|
|
use Padosoft\AffiliateNetwork\NetworkInterface; |
|
12
|
|
|
use Padosoft\AffiliateNetwork\AffiliateWindowEx; |
|
13
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class AffiliateFuture |
|
17
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
18
|
|
|
*/ |
|
19
|
|
|
class AffiliateFuture extends AbstractNetwork implements NetworkInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var object |
|
23
|
|
|
*/ |
|
24
|
|
|
private $_network = null; |
|
25
|
|
|
private $_apiClient = null; |
|
26
|
|
|
private $_username = ''; |
|
27
|
|
|
private $_password = ''; |
|
28
|
|
|
private $_logged = false; |
|
29
|
|
|
protected $_tracking_parameter = 'tracking'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @method __construct |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(string $username, string $password) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->_network = new \Oara\Network\Publisher\AffiliateFuture(); |
|
37
|
|
|
$this->_username = $username; |
|
38
|
|
|
$this->_password = $password; |
|
39
|
|
|
$this->_apiClient = null; |
|
40
|
|
|
$this->login( $this->_username, $this->_password ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function login(string $username, string $password): bool |
|
44
|
|
|
{ |
|
45
|
|
|
$this->_logged = false; |
|
46
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
|
47
|
|
|
return false; |
|
48
|
|
|
} |
|
49
|
|
|
$this->_username = $username; |
|
50
|
|
|
$this->_password = $password; |
|
51
|
|
|
$credentials = array(); |
|
52
|
|
|
$credentials["user"] = $this->_username; |
|
53
|
|
|
$credentials["password"] = $this->_password; |
|
54
|
|
|
$this->_network->login( $credentials ); |
|
55
|
|
|
if ($this->_network->checkConnection()) { |
|
56
|
|
|
$this->_logged = true; |
|
57
|
|
|
} |
|
58
|
|
|
return $this->_logged; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return bool |
|
63
|
|
|
*/ |
|
64
|
|
|
public function checkLogin() : bool |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->_logged; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return array of Merchants |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getMerchants() : array |
|
73
|
|
|
{ |
|
74
|
|
|
if (!$this->checkLogin()) { |
|
75
|
|
|
return array(); |
|
76
|
|
|
} |
|
77
|
|
|
$arrResult = array(); |
|
78
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
79
|
|
|
foreach($merchantList as $merchant) { |
|
80
|
|
|
$Merchant = Merchant::createInstance(); |
|
81
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
|
82
|
|
|
$Merchant->name = $merchant['name']; |
|
83
|
|
|
$Merchant->url = $merchant['url']; |
|
84
|
|
|
$Merchant->status = $merchant['joined'] == 'no' ? 'notjoined' : 'joined'; |
|
85
|
|
|
$arrResult[] = $Merchant; |
|
86
|
|
|
} |
|
87
|
|
|
return $arrResult; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param int|null $merchantID |
|
92
|
|
|
* @param int $page |
|
93
|
|
|
* @param int $items_per_page |
|
94
|
|
|
* |
|
95
|
|
|
* @return DealsResultset |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset |
|
98
|
|
|
{ |
|
99
|
|
|
// TODO: Implement getDeals() method. |
|
100
|
|
|
throw new \Exception("Not implemented yet"); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param \DateTime $dateFrom |
|
105
|
|
|
* @param \DateTime $dateTo |
|
106
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
107
|
|
|
* @return array of Transaction |
|
108
|
|
|
*/ |
|
109
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
$arrResult = array(); |
|
112
|
|
|
|
|
113
|
|
|
try { |
|
114
|
|
|
// Added timezone parameter |
|
115
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo, 'UTC'); |
|
116
|
|
|
|
|
117
|
|
|
if (is_array($transactionList)) { |
|
118
|
|
|
foreach ($transactionList as $transaction) { |
|
119
|
|
|
try { |
|
120
|
|
|
|
|
121
|
|
|
$myTransaction = Transaction::createInstance(); |
|
122
|
|
|
|
|
123
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
|
124
|
|
|
$myTransaction->date = $transaction['date']; |
|
125
|
|
|
if (!empty($transaction['date'])) { |
|
126
|
|
|
$date = new \DateTime($transaction['date'], new \DateTimeZone('UTC')); |
|
127
|
|
|
$myTransaction->date = $date; |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
|
130
|
|
|
if (isset($transaction['custom_id'])) { |
|
131
|
|
|
$myTransaction->custom_ID = $transaction['custom_id']; |
|
132
|
|
|
} |
|
133
|
|
|
$myTransaction->status = $transaction['status']; |
|
134
|
|
|
$myTransaction->amount = \Oara\Utilities::parseDouble($transaction['amount']); |
|
|
|
|
|
|
135
|
|
|
$myTransaction->commission = \Oara\Utilities::parseDouble($transaction['commission']); |
|
|
|
|
|
|
136
|
|
|
$myTransaction->currency = $transaction['currency']; |
|
137
|
|
|
$arrResult[] = $myTransaction; |
|
138
|
|
|
} catch (\Exception $e) { |
|
139
|
|
|
echo "[AffiliateFuture][Error] id: " . $myTransaction['unique_id'] . " msg: ".$e->getMessage(); |
|
140
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
} catch (\Exception $e) { |
|
145
|
|
|
echo "[AffiliateFuture][Error] ". $e->getMessage(); |
|
146
|
|
|
var_dump($e->getTraceAsString()); |
|
147
|
|
|
throw new \Exception($e); |
|
148
|
|
|
} |
|
149
|
|
|
return $arrResult; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param \DateTime $dateFrom |
|
154
|
|
|
* @param \DateTime $dateTo |
|
155
|
|
|
* @param int $merchantID |
|
156
|
|
|
* @return array of Stat |
|
157
|
|
|
*/ |
|
158
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
159
|
|
|
{ |
|
160
|
|
|
return array(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param array $params |
|
166
|
|
|
* |
|
167
|
|
|
* @return ProductsResultset |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
170
|
|
|
{ |
|
171
|
|
|
// TODO: Implement getProducts() method. |
|
172
|
|
|
throw new \Exception("Not implemented yet"); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function getTrackingParameter(){ |
|
176
|
|
|
return $this->_tracking_parameter; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.