|
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
|
|
|
/** |
|
15
|
|
|
* Class Skimlinks |
|
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
17
|
|
|
*/ |
|
18
|
|
|
class Skimlinks extends AbstractNetwork implements NetworkInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var object |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_network = null; |
|
24
|
|
|
private $_apiClient = null; |
|
25
|
|
|
private $_password = ''; |
|
26
|
|
|
private $_idSite = ''; |
|
27
|
|
|
protected $_country = ''; |
|
28
|
|
|
protected $_tracking_parameter = 'xcust'; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @method __construct |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(string $username, string $password, string $idSite = '', string $country = '') |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$this->_network = new \Oara\Network\Publisher\Skimlinks; |
|
38
|
|
|
$this->_username = $username; |
|
|
|
|
|
|
39
|
|
|
$this->_password = $password; |
|
40
|
|
|
$this->login( $this->_username, $this->_password, $idSite, $this->_country); |
|
|
|
|
|
|
41
|
|
|
$this->_apiClient = null; |
|
42
|
|
|
|
|
43
|
|
|
if (trim($idSite)!=''){ |
|
44
|
|
|
$this->addAllowedSite($idSite); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function login(string $username, string $password, string $idSite = '', string $country = ''): bool{ |
|
49
|
|
|
$this->_logged = false; |
|
|
|
|
|
|
50
|
|
|
if (isNullOrEmpty( $password )) { |
|
51
|
|
|
return false; |
|
52
|
|
|
} |
|
53
|
|
|
$this->_username = $username; |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
//<JC> Split public and private api key |
|
56
|
|
|
$apis_key = explode("|", $password); |
|
57
|
|
|
$public_key = str_replace("pub=", "", $apis_key[0]); |
|
58
|
|
|
$private_key = str_replace("priv=", "", $apis_key[1]); |
|
59
|
|
|
|
|
60
|
|
|
$this->_password = $private_key; |
|
61
|
|
|
$this->_idSite = $idSite; |
|
62
|
|
|
|
|
63
|
|
|
if (trim($idSite)!=''){ |
|
64
|
|
|
$this->addAllowedSite($idSite); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (strpos($country, '-') !== false) { |
|
68
|
|
|
$a_country = explode("-", $country); |
|
69
|
|
|
$country = $a_country[1]; |
|
70
|
|
|
} |
|
71
|
|
|
$this->_country = strtoupper($country); |
|
72
|
|
|
|
|
73
|
|
|
$credentials = array(); |
|
74
|
|
|
$credentials["user"] = $this->_username; |
|
|
|
|
|
|
75
|
|
|
$credentials["apikey"] = $public_key; |
|
76
|
|
|
$credentials["private_apikey"] = $private_key; |
|
77
|
|
|
$credentials["id_site"] = $idSite; |
|
78
|
|
|
|
|
79
|
|
|
$credentials['country'] = $country; |
|
80
|
|
|
$this->_network->login($credentials); |
|
81
|
|
|
$this->_logged = true; |
|
82
|
|
|
|
|
83
|
|
|
return $this->_logged; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function addAllowedSite($idSite){ |
|
87
|
|
|
if (trim($idSite)!=''){ |
|
88
|
|
|
$this->_network->addAllowedSite($idSite); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return bool |
|
95
|
|
|
*/ |
|
96
|
|
|
public function checkLogin() : bool |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->_logged; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return array of Merchants |
|
103
|
|
|
*/ |
|
104
|
|
View Code Duplication |
public function getMerchants() : array |
|
|
|
|
|
|
105
|
|
|
{ |
|
106
|
|
|
if (!$this->checkLogin()) { |
|
107
|
|
|
return array(); |
|
108
|
|
|
} |
|
109
|
|
|
$arrResult = array(); |
|
110
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
111
|
|
|
foreach($merchantList as $merchant) { |
|
112
|
|
|
$Merchant = Merchant::createInstance(); |
|
113
|
|
|
$Merchant->merchant_ID = $merchant['id']; |
|
114
|
|
|
$Merchant->name = $merchant['name']; |
|
115
|
|
|
$arrResult[] = $Merchant; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $arrResult; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param int $merchantID |
|
123
|
|
|
* @return array of Deal |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
|
126
|
|
|
{ |
|
127
|
|
|
$arrResult = array(); |
|
128
|
|
|
return $arrResult; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param \DateTime $dateFrom |
|
133
|
|
|
* @param \DateTime $dateTo |
|
134
|
|
|
* @param array $arrMerchantID |
|
135
|
|
|
* @return array of Transaction |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
138
|
|
|
{ |
|
139
|
|
|
$arrResult = array(); |
|
140
|
|
|
try { |
|
141
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
|
142
|
|
|
|
|
143
|
|
|
foreach($transactionList as $transaction) { |
|
144
|
|
|
|
|
145
|
|
|
$myTransaction = Transaction::createInstance(); |
|
146
|
|
|
try { |
|
147
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
|
148
|
|
|
$myTransaction->title =''; |
|
149
|
|
|
$myTransaction->currency = $transaction['currency']; |
|
150
|
|
|
if (!empty($transaction['date'])) { |
|
151
|
|
|
$date = new \DateTime($transaction['date']); |
|
152
|
|
|
$myTransaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
if (!empty($transaction['last_updated'])) { |
|
155
|
|
|
$date = new \DateTime($transaction['last_updated']); |
|
156
|
|
|
$myTransaction->update_date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
if (!empty($transaction['click_date'])){ |
|
159
|
|
|
$date = new \DateTime($transaction['click_date']); |
|
160
|
|
|
$myTransaction->click_date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
|
163
|
|
|
$myTransaction->custom_ID = array_key_exists('custom_id', $transaction) ? $transaction['custom_id'] : ''; |
|
164
|
|
|
$myTransaction->status = $transaction['status']; |
|
165
|
|
|
$myTransaction->amount = $transaction['amount']; |
|
166
|
|
|
$myTransaction->commission = $transaction['commission']; |
|
167
|
|
|
$myTransaction->approved = false; |
|
168
|
|
|
if ($transaction['status'] == \Oara\Utilities::STATUS_CONFIRMED){ |
|
169
|
|
|
$myTransaction->approved = true; |
|
170
|
|
|
} |
|
171
|
|
|
$account_id = $transaction['publisher_id']; |
|
|
|
|
|
|
172
|
|
|
$id_site = $transaction['publisher_domain_id']; |
|
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
$arrResult[] = $myTransaction; |
|
175
|
|
|
} catch (\Exception $e) { |
|
176
|
|
|
echo "<br><br>errore transazione Skimlinks, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; |
|
177
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
} catch (\Exception $e) { |
|
181
|
|
|
echo "<br><br>errore generico transazione Skimlinks: ".$e->getMessage()."<br><br>"; |
|
182
|
|
|
var_dump($e->getTraceAsString()); |
|
183
|
|
|
throw new \Exception($e); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
return $arrResult; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @param \DateTime $dateFrom |
|
191
|
|
|
* @param \DateTime $dateTo |
|
192
|
|
|
* @param int $merchantID |
|
193
|
|
|
* @return array of Stat |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
196
|
|
|
{ |
|
197
|
|
|
return array(); |
|
198
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @param array $params |
|
204
|
|
|
* |
|
205
|
|
|
* @return ProductsResultset |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
208
|
|
|
{ |
|
209
|
|
|
// TODO: Implement getProducts() method. |
|
210
|
|
|
throw new \Exception("Not implemented yet"); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function getTrackingParameter(){ |
|
214
|
|
|
return $this->_tracking_parameter; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
} |
|
219
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.