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
|
|
View Code Duplication |
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->_country = $country; |
41
|
|
|
$this->login( $this->_username, $this->_password, $idSite, $this->_country); |
|
|
|
|
42
|
|
|
$this->_apiClient = null; |
43
|
|
|
|
44
|
|
|
if (trim($idSite)!=''){ |
45
|
|
|
$this->addAllowedSite($idSite); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function login(string $username, string $password, string $idSite = '', string $country = ''): bool{ |
50
|
|
|
$this->_logged = false; |
|
|
|
|
51
|
|
|
if (isNullOrEmpty( $password )) { |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
$this->_username = $username; |
|
|
|
|
55
|
|
|
|
56
|
|
|
//<JC> Split public and private api key |
57
|
|
|
$apis_key = explode("|", $password); |
58
|
|
|
$public_key = str_replace("pub=", "", $apis_key[0]); |
59
|
|
|
$private_key = str_replace("priv=", "", $apis_key[1]); |
60
|
|
|
|
61
|
|
|
$this->_password = $private_key; |
62
|
|
|
$this->_idSite = $idSite; |
63
|
|
|
|
64
|
|
|
if (trim($idSite)!=''){ |
65
|
|
|
$this->addAllowedSite($idSite); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (strpos($country, '-') !== false) { |
69
|
|
|
$a_country = explode("-", $country); |
70
|
|
|
$country = $a_country[1]; |
71
|
|
|
} |
72
|
|
|
$this->_country = strtoupper($country); |
73
|
|
|
|
74
|
|
|
$credentials = array(); |
75
|
|
|
$credentials["user"] = $this->_username; |
|
|
|
|
76
|
|
|
$credentials["apikey"] = $public_key; |
77
|
|
|
$credentials["private_apikey"] = $private_key; |
78
|
|
|
$credentials["id_site"] = $idSite; |
79
|
|
|
|
80
|
|
|
$credentials['country'] = $this->_country; |
81
|
|
|
$this->_network->login($credentials); |
82
|
|
|
$this->_logged = true; |
83
|
|
|
|
84
|
|
|
return $this->_logged; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function addAllowedSite($idSite){ |
88
|
|
|
if (trim($idSite)!=''){ |
89
|
|
|
$this->_network->addAllowedSite($idSite); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function checkLogin() : bool |
98
|
|
|
{ |
99
|
|
|
return $this->_logged; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array of Merchants |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public function getMerchants() : array |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
if (!$this->checkLogin()) { |
108
|
|
|
return array(); |
109
|
|
|
} |
110
|
|
|
$arrResult = array(); |
111
|
|
|
|
112
|
|
|
$merchantList = $this->_network->getMerchantList(); |
113
|
|
|
foreach($merchantList as $merchant) { |
114
|
|
|
$Merchant = Merchant::createInstance(); |
115
|
|
|
$Merchant->merchant_ID = $merchant['id']; |
116
|
|
|
$Merchant->name = $merchant['name']; |
117
|
|
|
$arrResult[] = $Merchant; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $arrResult; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param int $merchantID |
125
|
|
|
* @return array of Deal |
126
|
|
|
*/ |
127
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
128
|
|
|
{ |
129
|
|
|
$arrResult = array(); |
130
|
|
|
return $arrResult; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param \DateTime $dateFrom |
135
|
|
|
* @param \DateTime $dateTo |
136
|
|
|
* @param array $arrMerchantID |
137
|
|
|
* @return array of Transaction |
138
|
|
|
*/ |
139
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
140
|
|
|
{ |
141
|
|
|
$arrResult = array(); |
142
|
|
|
try { |
143
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
144
|
|
|
|
145
|
|
|
foreach($transactionList as $transaction) { |
146
|
|
|
|
147
|
|
|
$myTransaction = Transaction::createInstance(); |
148
|
|
|
try { |
149
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
150
|
|
|
$myTransaction->title =''; |
151
|
|
|
$myTransaction->currency = $transaction['currency']; |
152
|
|
|
if (!empty($transaction['date'])) { |
153
|
|
|
$date = new \DateTime($transaction['date']); |
154
|
|
|
$myTransaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
if (!empty($transaction['last_updated'])) { |
157
|
|
|
$date = new \DateTime($transaction['last_updated']); |
158
|
|
|
$myTransaction->update_date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
159
|
|
|
} |
160
|
|
|
if (!empty($transaction['click_date'])){ |
161
|
|
|
$date = new \DateTime($transaction['click_date']); |
162
|
|
|
$myTransaction->click_date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
165
|
|
|
$myTransaction->custom_ID = array_key_exists('custom_id', $transaction) ? $transaction['custom_id'] : ''; |
166
|
|
|
$myTransaction->status = $transaction['status']; |
167
|
|
|
$myTransaction->amount = $transaction['amount']; |
168
|
|
|
$myTransaction->commission = $transaction['commission']; |
169
|
|
|
$myTransaction->approved = false; |
170
|
|
|
if ($transaction['status'] == \Oara\Utilities::STATUS_CONFIRMED){ |
171
|
|
|
$myTransaction->approved = true; |
172
|
|
|
} |
173
|
|
|
$account_id = $transaction['publisher_id']; |
|
|
|
|
174
|
|
|
$id_site = $transaction['publisher_domain_id']; |
|
|
|
|
175
|
|
|
|
176
|
|
|
$arrResult[] = $myTransaction; |
177
|
|
|
} catch (\Exception $e) { |
178
|
|
|
echo "<br><br>errore transazione Skimlinks, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; |
179
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} catch (\Exception $e) { |
183
|
|
|
echo "<br><br>errore generico transazione Skimlinks: ".$e->getMessage()."<br><br>"; |
184
|
|
|
var_dump($e->getTraceAsString()); |
185
|
|
|
throw new \Exception($e); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return $arrResult; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param \DateTime $dateFrom |
193
|
|
|
* @param \DateTime $dateTo |
194
|
|
|
* @param int $merchantID |
195
|
|
|
* @return array of Stat |
196
|
|
|
*/ |
197
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
198
|
|
|
{ |
199
|
|
|
return array(); |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param array $params |
206
|
|
|
* |
207
|
|
|
* @return ProductsResultset |
208
|
|
|
*/ |
209
|
|
|
public function getProducts(array $params = []): ProductsResultset |
210
|
|
|
{ |
211
|
|
|
// TODO: Implement getProducts() method. |
212
|
|
|
throw new \Exception("Not implemented yet"); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function getTrackingParameter(){ |
216
|
|
|
return $this->_tracking_parameter; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
} |
221
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.