1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
4
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
6
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
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\NetAffiliationEx; |
13
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
14
|
|
|
|
15
|
|
|
if (!defined('COOKIES_BASE_DIR')){ |
16
|
|
|
define('COOKIES_BASE_DIR',public_path('upload/report')); |
17
|
|
|
} |
18
|
|
|
/** |
19
|
|
|
* Class NetAffiliation |
20
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
21
|
|
|
*/ |
22
|
|
|
class NetAffiliation extends AbstractNetwork implements NetworkInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var object |
26
|
|
|
*/ |
27
|
|
|
private $_network = null; |
28
|
|
|
private $_username = ''; |
29
|
|
|
private $_password = ''; |
30
|
|
|
private $_idSite = ''; |
31
|
|
|
private $_logged = false; |
32
|
|
|
protected $_tracking_parameter = 'argsite'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @method __construct |
36
|
|
|
*/ |
37
|
|
|
public function __construct(string $username, string $password,string $idSite='') |
38
|
|
|
{ |
39
|
|
|
$this->_network = new NetAffiliationEx(); |
40
|
|
|
$this->_username = $username; |
41
|
|
|
$this->_password = $password; |
42
|
|
|
if (trim($idSite)!=''){ |
43
|
|
|
$this->addAllowedSite($idSite); |
44
|
|
|
} |
45
|
|
|
$this->login( $this->_username, $this->_password ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function addAllowedSite($idSite){ |
49
|
|
|
if (trim($idSite)!=''){ |
50
|
|
|
$this->_network->addAllowedSite($idSite); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function login(string $username, string $password,string $idSite=''): bool |
55
|
|
|
{ |
56
|
|
|
if (trim($idSite)!=''){ |
57
|
|
|
$this->addAllowedSite($idSite); |
58
|
|
|
} |
59
|
|
|
$this->_logged = false; |
60
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
61
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
$this->_username = $username; |
65
|
|
|
$this->_password = $password; |
66
|
|
|
$credentials = array(); |
67
|
|
|
$credentials["user"] = $this->_username; |
68
|
|
|
$credentials["password"] = $this->_password; |
69
|
|
|
$credentials["apiPassword"] = $this->_password; |
70
|
|
|
$this->_network->login( $credentials ); |
71
|
|
|
//$this->_apiClient = $this->_network->getApiClient(); |
|
|
|
|
72
|
|
|
if ($this->_network->checkConnection()) { |
73
|
|
|
$this->_logged = true; |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->_logged; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function checkLogin() : bool |
84
|
|
|
{ |
85
|
|
|
return $this->_logged; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array of Merchants |
90
|
|
|
*/ |
91
|
|
View Code Duplication |
public function getMerchants() : array |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
if (!$this->checkLogin()) { |
94
|
|
|
return array(); |
95
|
|
|
} |
96
|
|
|
$arrResult = array(); |
97
|
|
|
$merchantList = $this->_network->getMerchantList(); |
98
|
|
|
foreach($merchantList as $merchant) { |
99
|
|
|
$Merchant = Merchant::createInstance(); |
100
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
101
|
|
|
$Merchant->name = $merchant['name']; |
102
|
|
|
$arrResult[] = $Merchant; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $arrResult; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param int|null $merchantID |
110
|
|
|
* @param int $page |
111
|
|
|
* @param int $items_per_page |
112
|
|
|
* |
113
|
|
|
* @return DealsResultset |
114
|
|
|
*/ |
115
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
116
|
|
|
{ |
117
|
|
|
$url = 'http://flux.netaffiliation.com/rsscp.php?sec=417771E811773642F4E017'; |
118
|
|
|
$xml = file_get_contents($url); |
119
|
|
|
$arrResult = array(); |
120
|
|
|
$arrResponse = xml2array($xml); |
121
|
|
|
if(!is_array($arrResponse) || count($arrResponse) <= 0) { |
122
|
|
|
return $arrResult; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$arrItems = $arrResponse['rss']['channel']['item']; |
126
|
|
View Code Duplication |
foreach($arrItems as $item) { |
|
|
|
|
127
|
|
|
$Deal = Deal::createInstance(); |
128
|
|
|
$Deal->merchant_ID = $item['idcamp']; |
129
|
|
|
$Deal->code = $item['code']; |
130
|
|
|
$Deal->name = $item['title']; |
131
|
|
|
$Deal->startDate = $item['startdate']; |
132
|
|
|
$Deal->endDate = $item['enddate']; |
133
|
|
|
$Deal->description = $item['description']; |
134
|
|
|
$Deal->url = $item['link']; |
135
|
|
|
if($merchantID > 0) { |
136
|
|
|
if($merchantID == $item['idcamp']) { |
137
|
|
|
$arrResult[] = $Deal; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
else { |
141
|
|
|
$arrResult[] = $Deal; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $arrResult; |
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param \DateTime $dateFrom |
151
|
|
|
* @param \DateTime $dateTo |
152
|
|
|
* @param int $merchantID |
|
|
|
|
153
|
|
|
* @return array of Transaction |
154
|
|
|
*/ |
155
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
156
|
|
|
{ |
157
|
|
|
if (!$this->checkLogin()) { |
158
|
|
|
return array(); |
159
|
|
|
} |
160
|
|
|
$arrResult = array(); |
161
|
|
View Code Duplication |
if (count( $arrMerchantID ) < 1) { |
|
|
|
|
162
|
|
|
$merchants = $this->getMerchants(); |
163
|
|
|
foreach ($merchants as $merchant) { |
164
|
|
|
$arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name]; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$transcationList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
169
|
|
View Code Duplication |
foreach($transcationList as $transaction) { |
|
|
|
|
170
|
|
|
$Transaction = Transaction::createInstance(); |
171
|
|
|
array_key_exists_safe( $transaction, |
172
|
|
|
'currency' ) ? $Transaction->currency = $transaction['currency'] : $Transaction->currency = ''; |
173
|
|
|
array_key_exists_safe( $transaction, |
174
|
|
|
'status' ) ? $Transaction->status = $transaction['status'] : $Transaction->status = ''; |
175
|
|
|
array_key_exists_safe( $transaction, |
176
|
|
|
'amount' ) ? $Transaction->amount = $transaction['amount'] : $Transaction->amount = ''; |
|
|
|
|
177
|
|
|
array_key_exists_safe( $transaction, |
178
|
|
|
'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
179
|
|
|
array_key_exists_safe( $transaction, |
180
|
|
|
'title' ) ? $Transaction->title = $transaction['title'] : $Transaction->title = ''; |
181
|
|
|
array_key_exists_safe( $transaction, |
182
|
|
|
'unique_id' ) ? $Transaction->unique_ID = $transaction['unique_id'] : $Transaction->unique_ID = ''; |
183
|
|
|
array_key_exists_safe( $transaction, |
184
|
|
|
'commission' ) ? $Transaction->commission = $transaction['commission'] : $Transaction->commission = 0; |
|
|
|
|
185
|
|
|
$date = new \DateTime( $transaction['date'] ); |
186
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
187
|
|
|
array_key_exists_safe( $transaction, |
188
|
|
|
'merchantId' ) ? $Transaction->merchant_ID = $transaction['merchantId'] : $Transaction->merchant_ID = ''; |
|
|
|
|
189
|
|
|
array_key_exists_safe( $transaction, |
190
|
|
|
'approved' ) ? $Transaction->approved = $transaction['approved'] : $Transaction->approved = ''; |
|
|
|
|
191
|
|
|
$arrResult[] = $Transaction; |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $arrResult; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param \DateTime $dateFrom |
200
|
|
|
* @param \DateTime $dateTo |
201
|
|
|
* @param int $merchantID |
202
|
|
|
* @return array of Stat |
203
|
|
|
*/ |
204
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
205
|
|
|
{ |
206
|
|
|
return array(); |
207
|
|
|
/* |
|
|
|
|
208
|
|
|
$this->_apiClient->setConnectId($this->_username); |
209
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
210
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
211
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
212
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
213
|
|
|
$arrResponse = json_decode($response, true); |
214
|
|
|
$reportItems = $arrResponse['reportItems']; |
215
|
|
|
$Stat = Stat::createInstance(); |
216
|
|
|
$Stat->reportItems = $reportItems; |
217
|
|
|
|
218
|
|
|
return array($Stat); |
219
|
|
|
*/ |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param array $params |
225
|
|
|
* |
226
|
|
|
* @return ProductsResultset |
227
|
|
|
*/ |
228
|
|
|
public function getProducts(array $params = []): ProductsResultset |
229
|
|
|
{ |
230
|
|
|
// TODO: Implement getProducts() method. |
231
|
|
|
throw new \Exception("Not implemented yet"); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function getTrackingParameter(){ |
235
|
|
|
return $this->_tracking_parameter; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.