|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
|
4
|
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
|
6
|
|
|
use Padosoft\AffiliateNetwork\Merchant; |
|
7
|
|
|
use Padosoft\AffiliateNetwork\Stat; |
|
8
|
|
|
use Padosoft\AffiliateNetwork\Deal; |
|
9
|
|
|
use Padosoft\AffiliateNetwork\AbstractNetwork; |
|
10
|
|
|
use Padosoft\AffiliateNetwork\NetworkInterface; |
|
11
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
|
12
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
|
13
|
|
|
|
|
14
|
|
|
// require "../vendor/fubralimited/php-oara/Oara/Network/Publisher/Publicideas/Zapi/ApiClient.php"; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Publicideas |
|
18
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
19
|
|
|
*/ |
|
20
|
|
|
class Publicideas extends AbstractNetwork implements NetworkInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var object |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_network = null; |
|
26
|
|
|
private $_username = ''; |
|
27
|
|
|
private $_password = ''; |
|
28
|
|
|
private $_token = ''; |
|
29
|
|
|
private $_partner_id = ''; |
|
30
|
|
|
private $_logged = false; |
|
31
|
|
|
protected $_tracking_parameter = 'cb'; |
|
32
|
|
|
/** |
|
33
|
|
|
* @method __construct |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(string $username, string $password, string $token='',string $partner_id='') |
|
36
|
|
|
{ |
|
37
|
|
|
$this->_network = new \Oara\Network\Publisher\Publicidees; |
|
38
|
|
|
$this->_username = $username; |
|
39
|
|
|
$this->_password = $password; |
|
40
|
|
|
$this->_token = $token; |
|
41
|
|
|
$this->_partner_id = $partner_id; |
|
42
|
|
|
$this->login( $this->_username, $this->_password ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
public function login(string $username, string $password,string $idSite=''): bool{ |
|
|
|
|
|
|
46
|
|
|
$this->_logged = false; |
|
47
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
|
48
|
|
|
|
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
$this->_username = $username; |
|
52
|
|
|
$this->_password = $password; |
|
53
|
|
|
$credentials = array(); |
|
54
|
|
|
$credentials["user"] = $this->_username; |
|
55
|
|
|
$credentials["password"] = $this->_password; |
|
56
|
|
|
$this->_network->login($credentials); |
|
57
|
|
|
if ($this->_network->checkConnection()) { |
|
58
|
|
|
$this->_logged = true; |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $this->_logged; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
public function checkLogin() : bool |
|
69
|
|
|
{ |
|
70
|
|
|
$this->_logged = true; |
|
71
|
|
|
return $this->_logged; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return array of Merchants |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getMerchants() : array |
|
78
|
|
|
{ |
|
79
|
|
|
$arrResult = array(); |
|
80
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
81
|
|
|
foreach($merchantList as $merchant) { |
|
82
|
|
|
$Merchant = Merchant::createInstance(); |
|
83
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
|
84
|
|
|
$Merchant->name = $merchant['name']; |
|
85
|
|
|
$arrResult[] = $Merchant; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $arrResult; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param int $merchantID |
|
93
|
|
|
* @return array of Deal |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
|
96
|
|
|
{ |
|
97
|
|
|
$url = 'http://publisher.publicideas.com/xmlProgAff.php?partid='.$this->_partner_id.'&key='.$this->_token.'&noDownload=yes'; |
|
98
|
|
|
$xml = file_get_contents($url); |
|
99
|
|
|
$arrResult = array(); |
|
100
|
|
|
$arrResponse = xml2array($xml); |
|
101
|
|
|
if(!is_array($arrResponse) || count($arrResponse) <= 0) { |
|
102
|
|
|
return $arrResult; |
|
103
|
|
|
} |
|
104
|
|
|
$arrPartner = $arrResponse['partner']; |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
/* |
|
|
|
|
|
|
107
|
|
|
foreach($arrPartner as $partner) { |
|
108
|
|
|
$Deal = Deal::createInstance(); |
|
109
|
|
|
$Deal->program_name; |
|
110
|
|
|
if($merchantID > 0) { |
|
111
|
|
|
if($merchantID == $admediumItems['program']['@id']) { |
|
112
|
|
|
$arrResult[] = $Deal; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
else { |
|
116
|
|
|
$arrResult[] = $Deal; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
*/ |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/* |
|
|
|
|
|
|
124
|
|
|
$this->_apiClient->setConnectId($this->_username); |
|
125
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
|
126
|
|
|
$arrResponse = json_decode($this->_apiClient->getAdmedia(), true); |
|
127
|
|
|
$arrAdmediumItems = $arrResponse['admediumItems']['admediumItem']; |
|
128
|
|
|
$arrResult = array(); |
|
129
|
|
|
foreach($arrAdmediumItems as $admediumItems) { |
|
130
|
|
|
$Deal = Deal::createInstance(); |
|
131
|
|
|
$Deal->deal_ID = (int)$admediumItems['@id']; |
|
132
|
|
|
$Deal->name = $admediumItems['name']; |
|
133
|
|
|
$Deal->deal_type = $admediumItems['admediumType']; |
|
134
|
|
|
$Deal->merchant_ID = (int)$admediumItems['program']['@id']; |
|
135
|
|
|
$Deal->ppv = $admediumItems['trackingLinks']['trackingLink'][0]['ppv']; |
|
136
|
|
|
$Deal->ppc = $admediumItems['trackingLinks']['trackingLink'][0]['ppc']; |
|
137
|
|
|
if($merchantID > 0) { |
|
138
|
|
|
if($merchantID == $admediumItems['program']['@id']) { |
|
139
|
|
|
$arrResult[] = $Deal; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
else { |
|
143
|
|
|
$arrResult[] = $Deal; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
return $arrResult; |
|
148
|
|
|
*/ |
|
149
|
|
|
|
|
150
|
|
|
return array(); |
|
151
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param \DateTime $dateFrom |
|
156
|
|
|
* @param \DateTime $dateTo |
|
157
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
158
|
|
|
* @return array of Transaction |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
161
|
|
|
{ |
|
162
|
|
|
try { |
|
163
|
|
|
if (!$this->checkLogin()) { |
|
164
|
|
|
return array(); |
|
165
|
|
|
} |
|
166
|
|
|
$arrResult = array(); |
|
167
|
|
View Code Duplication |
if (count( $arrMerchantID ) < 1) { |
|
|
|
|
|
|
168
|
|
|
$merchants = $this->getMerchants(); |
|
169
|
|
|
foreach ($merchants as $merchant) { |
|
170
|
|
|
$arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name]; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
$transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom); |
|
174
|
|
|
foreach($transcationList as $transaction) { |
|
175
|
|
|
try { |
|
176
|
|
|
$myTransaction = Transaction::createInstance(); |
|
177
|
|
|
$myTransaction->currency = $transaction['currency']; |
|
178
|
|
|
$myTransaction->status = $transaction['status']; |
|
179
|
|
|
$myTransaction->amount = $transaction['amount']; |
|
180
|
|
|
$myTransaction->custom_ID = $transaction['custom_id']; |
|
181
|
|
|
$myTransaction->title = $transaction['title']; |
|
182
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
|
183
|
|
|
$myTransaction->commission = $transaction['commission']; |
|
184
|
|
|
if (!empty($transaction->date)) { |
|
185
|
|
|
$date = new \DateTime($transaction->date); |
|
186
|
|
|
$myTransaction->date = $date; |
|
|
|
|
|
|
187
|
|
|
} |
|
188
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
|
189
|
|
|
$myTransaction->approved = $transaction['approved']; |
|
190
|
|
|
$arrResult[] = $myTransaction; |
|
191
|
|
|
} catch (\Exception $e) { |
|
192
|
|
|
//echo "stepE "; |
|
193
|
|
|
echo "<br><br>errore transazione Publicideas, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; |
|
194
|
|
|
//var_dump($e->getTraceAsString()); |
|
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
} catch (\Exception $e) { |
|
198
|
|
|
throw new \Exception($e->getMessage()); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
return $arrResult; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param \DateTime $dateFrom |
|
206
|
|
|
* @param \DateTime $dateTo |
|
207
|
|
|
* @param int $merchantID |
|
208
|
|
|
* @return array of Stat |
|
209
|
|
|
*/ |
|
210
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
211
|
|
|
{ |
|
212
|
|
|
return array(); |
|
213
|
|
|
/* |
|
|
|
|
|
|
214
|
|
|
$this->_apiClient->setConnectId($this->_username); |
|
215
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
|
216
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
|
217
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
|
218
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
|
219
|
|
|
$arrResponse = json_decode($response, true); |
|
220
|
|
|
$reportItems = $arrResponse['reportItems']; |
|
221
|
|
|
$Stat = Stat::createInstance(); |
|
222
|
|
|
$Stat->reportItems = $reportItems; |
|
223
|
|
|
|
|
224
|
|
|
return array($Stat); |
|
225
|
|
|
*/ |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @param array $params |
|
231
|
|
|
* |
|
232
|
|
|
* @return ProductsResultset |
|
233
|
|
|
*/ |
|
234
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
235
|
|
|
{ |
|
236
|
|
|
// TODO: Implement getProducts() method. |
|
237
|
|
|
throw new \Exception("Not implemented yet"); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function getTrackingParameter(){ |
|
241
|
|
|
return $this->_tracking_parameter; |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.