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 Admitad |
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
17
|
|
|
*/ |
18
|
|
|
class Admitad 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
|
|
|
public function __construct(string $username, string $password, string $idSite='') |
34
|
|
|
{ |
35
|
|
|
$this->_network = new \Oara\Network\Publisher\Admitad; |
36
|
|
|
$this->_username = $username; |
37
|
|
|
$this->_password = $password; |
38
|
|
|
$this->_idSite = $idSite; |
39
|
|
|
|
40
|
|
|
$this->login( $this->_username, $this->_password, $idSite ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function login(string $username, string $password,string $idSite=''): bool{ |
44
|
|
|
$this->_logged = false; |
|
|
|
|
45
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
46
|
|
|
|
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
$this->_username = $username; |
50
|
|
|
$this->_password = $password; |
51
|
|
|
$this->_idSite = $idSite; |
52
|
|
|
$credentials = array(); |
53
|
|
|
$credentials["user"] = $this->_username; |
54
|
|
|
$credentials["password"] = $this->_password; |
55
|
|
|
$credentials["idSite"] = $this->_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
|
|
|
* @throws \Exception |
75
|
|
|
*/ |
76
|
|
|
public function getMerchants() : array |
77
|
|
|
{ |
78
|
|
|
$arrResult = array(); |
79
|
|
|
$merchantList = $this->_network->getMerchantList(); |
80
|
|
|
foreach($merchantList as $merchant) { |
81
|
|
|
$Merchant = Merchant::createInstance(); |
82
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
83
|
|
|
$Merchant->name = $merchant['name']; |
84
|
|
|
$Merchant->status = $merchant['status']; |
85
|
|
|
$Merchant->url = $merchant['url']; |
86
|
|
|
if (!empty($merchant['launch_date'])) { |
87
|
|
|
$date = new \DateTime($merchant['launch_date']); |
88
|
|
|
$Merchant->launch_date = $date; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
$arrResult[] = $Merchant; |
91
|
|
|
} |
92
|
|
|
return $arrResult; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param null $merchantID |
97
|
|
|
* @param int $page |
98
|
|
|
* @param int $items_per_page |
99
|
|
|
* @return DealsResultset array of Deal |
100
|
|
|
* @throws \Exception |
101
|
|
|
*/ |
102
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=100 ): DealsResultset |
103
|
|
|
{ |
104
|
|
|
$arrResult = array(); |
105
|
|
|
|
106
|
|
|
$result = DealsResultset::createInstance(); |
107
|
|
|
|
108
|
|
|
$arrVouchers = $this->_network->getVouchers($this->_idSite); |
109
|
|
|
|
110
|
|
|
foreach($arrVouchers as $voucher) { |
111
|
|
|
if (!empty($voucher['tracking']) && !empty($voucher['advertiser_id'])) { |
112
|
|
|
$Deal = Deal::createInstance(); |
113
|
|
|
$Deal->deal_ID = md5($voucher['tracking']); // Use link to generate a unique deal ID |
|
|
|
|
114
|
|
|
$Deal->merchant_ID = $voucher['advertiser_id']; |
115
|
|
|
$Deal->merchant_name = $voucher['advertiser_name']; |
116
|
|
|
$Deal->code = $voucher['code']; |
117
|
|
|
$Deal->name = $voucher['name']; |
118
|
|
|
$Deal->description = $voucher['description']; |
119
|
|
|
$Deal->start_date = $Deal->convertDate($voucher['start_date']); |
|
|
|
|
120
|
|
|
$Deal->end_date = $Deal->convertDate($voucher['end_date']); |
|
|
|
|
121
|
|
|
$Deal->default_track_uri = $voucher['tracking']; |
122
|
|
|
$Deal->discount_amount = $voucher['discount_amount']; |
123
|
|
|
$Deal->is_percentage = $voucher['is_percentage']; |
124
|
|
|
$Deal->is_exclusive = false; |
125
|
|
|
$Deal->deal_type = $voucher['type']; |
126
|
|
|
$arrResult[] = $Deal; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$result->deals[]=$arrResult; |
131
|
|
|
|
132
|
|
|
return $result; |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param \DateTime $dateFrom |
138
|
|
|
* @param \DateTime $dateTo |
139
|
|
|
* @param array $arrMerchantID |
140
|
|
|
* @return array of Transaction |
141
|
|
|
* @throws \Exception |
142
|
|
|
*/ |
143
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
|
146
|
|
|
$arrResult = array(); |
147
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
148
|
|
|
foreach($transactionList as $transaction) { |
149
|
|
|
$Transaction = Transaction::createInstance(); |
150
|
|
|
if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
151
|
|
|
$Transaction->currency = $transaction['currency']; |
152
|
|
|
} else { |
153
|
|
|
$Transaction->currency = "EUR"; |
154
|
|
|
} |
155
|
|
|
$Transaction->status = $transaction['status']; |
156
|
|
|
$Transaction->amount = $transaction['amount']; |
157
|
|
|
array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
158
|
|
|
$Transaction->title = ''; |
159
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
160
|
|
|
$Transaction->commission = $transaction['commission']; |
161
|
|
|
$date = new \DateTime($transaction['date']); |
162
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
163
|
|
|
// Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
164
|
|
|
if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
165
|
|
|
$Transaction->click_date = new \DateTime($transaction['click_date']); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
168
|
|
|
$Transaction->update_date = new \DateTime($transaction['update_date']); |
|
|
|
|
169
|
|
|
} |
170
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
171
|
|
|
$Transaction->campaign_name = $transaction['merchantName']; |
172
|
|
|
$Transaction->IP = $transaction['IP']; |
173
|
|
|
$Transaction->approved = false; |
174
|
|
|
if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED){ |
175
|
|
|
$Transaction->approved = true; |
176
|
|
|
} |
177
|
|
|
$arrResult[] = $Transaction; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $arrResult; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param \DateTime $dateFrom |
185
|
|
|
* @param \DateTime $dateTo |
186
|
|
|
* @param int $merchantID |
187
|
|
|
* @return array of Stat |
188
|
|
|
*/ |
189
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
190
|
|
|
{ |
191
|
|
|
// TODO |
192
|
|
|
return array(); |
193
|
|
|
/* |
194
|
|
|
$this->_apiClient->setConnectId($this->_username); |
195
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
196
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
197
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
198
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
199
|
|
|
$arrResponse = json_decode($response, true); |
200
|
|
|
$reportItems = $arrResponse['reportItems']; |
201
|
|
|
$Stat = Stat::createInstance(); |
202
|
|
|
$Stat->reportItems = $reportItems; |
203
|
|
|
|
204
|
|
|
return array($Stat); |
205
|
|
|
*/ |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param array $params |
211
|
|
|
* @return ProductsResultset |
212
|
|
|
* @throws \Exception |
213
|
|
|
*/ |
214
|
|
|
public function getProducts(array $params = []): ProductsResultset |
215
|
|
|
{ |
216
|
|
|
// TODO: Implement getProducts() method. |
217
|
|
|
throw new \Exception("Not implemented yet"); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function getTrackingParameter(){ |
221
|
|
|
return $this->_tracking_parameter; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
|
226
|
|
|
} |
227
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: