|
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\ProductsResultset; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class LinkShare |
|
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
17
|
|
|
*/ |
|
18
|
|
|
class LinkShare extends AbstractNetwork implements NetworkInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var object |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_network = null; |
|
24
|
|
|
private $_username = ''; |
|
25
|
|
|
private $_password = ''; |
|
26
|
|
|
private $_apiClient = null; |
|
27
|
|
|
protected $_tracking_parameter = ''; |
|
28
|
|
|
private $_idSite = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @method __construct |
|
32
|
|
|
*/ |
|
33
|
|
View Code Duplication |
public function __construct(string $username, string $password, string $idSite='') |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$this->_network = new \Oara\Network\Publisher\LinkShare; |
|
36
|
|
|
$this->_username = $username; |
|
37
|
|
|
$this->_password = $password; |
|
38
|
|
|
$this->_password = $password; |
|
39
|
|
|
$idSite = $this->_idSite; |
|
40
|
|
|
|
|
41
|
|
|
$this->login( $this->_username, $this->_password, $idSite ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
View Code Duplication |
public function login(string $username, string $password,string $idSite=''): bool{ |
|
|
|
|
|
|
45
|
|
|
$this->_logged = false; |
|
|
|
|
|
|
46
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
|
47
|
|
|
|
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
$this->_username = $username; |
|
51
|
|
|
$this->_password = $password; |
|
52
|
|
|
$credentials = array(); |
|
53
|
|
|
$credentials["user"] = $this->_username; |
|
54
|
|
|
$credentials["password"] = $this->_password; |
|
55
|
|
|
$credentials["idSite"] = $idSite; |
|
56
|
|
|
$this->_network->login($credentials); |
|
57
|
|
|
if ($this->_network->checkConnection()) { |
|
58
|
|
|
$this->_logged = true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->_logged; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function checkLogin() : bool |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->_logged; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return array of Merchants |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getMerchants() : 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
|
|
|
$arrResult[] = $Merchant; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $arrResult; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param int $merchantID |
|
91
|
|
|
* @return array of Deal |
|
92
|
|
|
*/ |
|
93
|
|
View Code Duplication |
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$arrResult = array(); |
|
96
|
|
|
$arrResponse = $this->_apiClient->getFullEarnings(null, null, null, $this->_username, $this->_password); |
|
97
|
|
|
foreach($arrResponse as $response) { |
|
98
|
|
|
$Deal = Deal::createInstance(); |
|
99
|
|
|
$Deal->transaction_ID = $response->transactionID; |
|
|
|
|
|
|
100
|
|
|
$Deal->affiliate_ID = $response->affiliate_ID; |
|
|
|
|
|
|
101
|
|
|
$Deal->campaign_name = $response->campaignName; |
|
|
|
|
|
|
102
|
|
|
$Deal->campaign_ID = $response->campaignID; |
|
|
|
|
|
|
103
|
|
|
$date = new \DateTime($response->date); |
|
|
|
|
|
|
104
|
|
|
$Deal->date = $response->date; |
|
|
|
|
|
|
105
|
|
|
$Deal->programName = $response->program_name; |
|
|
|
|
|
|
106
|
|
|
$Deal->merchant_ID = $response->programID; |
|
107
|
|
|
$Deal->commission = $response->commission; |
|
|
|
|
|
|
108
|
|
|
$Deal->amount = $response->saleValue; |
|
|
|
|
|
|
109
|
|
|
$Deal->status = $response->status; |
|
|
|
|
|
|
110
|
|
|
$Deal->referrer = $response->referrer; |
|
|
|
|
|
|
111
|
|
|
if($merchantID > 0) { |
|
112
|
|
|
if($merchantID == $response->programID) { |
|
113
|
|
|
$arrResult[] = $Deal; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
else { |
|
117
|
|
|
$arrResult[] = $Deal; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $arrResult; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param \DateTime $dateFrom |
|
126
|
|
|
* @param \DateTime $dateTo |
|
127
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
128
|
|
|
* @return array of Transaction |
|
129
|
|
|
*/ |
|
130
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
|
|
133
|
|
|
$arrResult = array(); |
|
134
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
|
135
|
|
|
foreach($transactionList as $transaction) { |
|
136
|
|
|
$Transaction = Transaction::createInstance(); |
|
137
|
|
|
if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
|
138
|
|
|
$Transaction->currency = $transaction['currency']; |
|
139
|
|
|
} else { |
|
140
|
|
|
$Transaction->currency = "EUR"; |
|
141
|
|
|
} |
|
142
|
|
|
$Transaction->status = $transaction['status']; |
|
143
|
|
|
$Transaction->amount = $transaction['amount']; |
|
144
|
|
|
array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
|
145
|
|
|
$Transaction->title = ''; |
|
146
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
|
147
|
|
|
$Transaction->commission = $transaction['commission']; |
|
148
|
|
|
$date = new \DateTime($transaction['date']); |
|
149
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
150
|
|
|
// Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
|
151
|
|
|
if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
|
152
|
|
|
$Transaction->click_date = new \DateTime($transaction['click_date']); |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
|
155
|
|
|
$Transaction->update_date = new \DateTime($transaction['update_date']); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
|
158
|
|
|
$Transaction->campaign_name = $transaction['merchantName']; |
|
159
|
|
|
$Transaction->IP = $transaction['IP']; |
|
160
|
|
|
$Transaction->approved = false; |
|
161
|
|
|
if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){ |
|
162
|
|
|
$Transaction->approved = true; |
|
163
|
|
|
} |
|
164
|
|
|
$arrResult[] = $Transaction; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
return $arrResult; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param \DateTime $dateFrom |
|
172
|
|
|
* @param \DateTime $dateTo |
|
173
|
|
|
* @param int $merchantID |
|
174
|
|
|
* @return array of Stat |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
177
|
|
|
{ |
|
178
|
|
|
// TODO |
|
179
|
|
|
return array(); |
|
180
|
|
|
/* |
|
|
|
|
|
|
181
|
|
|
$this->_apiClient->setConnectId($this->_username); |
|
182
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
|
183
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
|
184
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
|
185
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
|
186
|
|
|
$arrResponse = json_decode($response, true); |
|
187
|
|
|
$reportItems = $arrResponse['reportItems']; |
|
188
|
|
|
$Stat = Stat::createInstance(); |
|
189
|
|
|
$Stat->reportItems = $reportItems; |
|
190
|
|
|
|
|
191
|
|
|
return array($Stat); |
|
192
|
|
|
*/ |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @param array $params |
|
198
|
|
|
* |
|
199
|
|
|
* @return ProductsResultset |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
202
|
|
|
{ |
|
203
|
|
|
// TODO: Implement getProducts() method. |
|
204
|
|
|
throw new \Exception("Not implemented yet"); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
public function getTrackingParameter(){ |
|
208
|
|
|
return $this->_tracking_parameter; |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.