|
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 Daisycon |
|
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
17
|
|
|
*/ |
|
18
|
|
|
class Daisycon 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 = 'ws'; |
|
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\Daisycon; |
|
36
|
|
|
$this->_username = $username; |
|
37
|
|
|
$this->_password = $password; |
|
38
|
|
|
$idSite = $this->_idSite; |
|
39
|
|
|
$this->login( $this->_username, $this->_password, $idSite ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function login(string $username, string $password,string $idSite=''): bool{ |
|
43
|
|
|
$this->_logged = false; |
|
|
|
|
|
|
44
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
|
45
|
|
|
|
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
$this->_username = $username; |
|
49
|
|
|
$this->_password = $password; |
|
50
|
|
|
$credentials = array(); |
|
51
|
|
|
$credentials["user"] = $this->_username; |
|
52
|
|
|
$credentials["password"] = $this->_password; |
|
53
|
|
|
$credentials["idSite"] = $idSite; |
|
54
|
|
|
$this->_network->login($credentials); |
|
55
|
|
|
if ($this->_network->checkConnection()) { |
|
56
|
|
|
$this->_logged = true; |
|
57
|
|
|
} |
|
58
|
|
|
return $this->_logged; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return bool |
|
63
|
|
|
*/ |
|
64
|
|
|
public function checkLogin() : bool |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->_logged; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return array of Merchants |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getMerchants() : array |
|
73
|
|
|
{ |
|
74
|
|
|
$arrResult = array(); |
|
75
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
76
|
|
|
foreach($merchantList as $merchant) { |
|
77
|
|
|
$Merchant = Merchant::createInstance(); |
|
78
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
|
79
|
|
|
$Merchant->name = $merchant['name']; |
|
80
|
|
|
$Merchant->url = $merchant['display_url']; |
|
81
|
|
|
$Merchant->status = $merchant['status']; |
|
82
|
|
View Code Duplication |
if (!empty($merchant['start_date'])) { |
|
|
|
|
|
|
83
|
|
|
if ($merchant['start_date'] == '0000-00-00') { |
|
84
|
|
|
$Merchant->launch_dates = null; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
else { |
|
87
|
|
|
$date = new \DateTime($merchant['start_date']); |
|
88
|
|
|
$Merchant->launch_dates = $date; |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
View Code Duplication |
if (!empty($merchant['end_date'])) { |
|
|
|
|
|
|
92
|
|
|
if ($merchant['end_date'] == '0000-00-00') { |
|
93
|
|
|
$Merchant->termination_date = null; |
|
94
|
|
|
} |
|
95
|
|
|
else { |
|
96
|
|
|
$date = new \DateTime($merchant['end_date']); |
|
97
|
|
|
$Merchant->termination_date = $date; |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
$arrResult[] = $Merchant; |
|
101
|
|
|
} |
|
102
|
|
|
return $arrResult; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param int $merchantID |
|
107
|
|
|
* @return array of Deal |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getDeals($merchantID = null,int $page = 0,int $items_per_page = 100 ): DealsResultset |
|
110
|
|
|
{ |
|
111
|
|
|
$arrResult = array(); |
|
112
|
|
|
|
|
113
|
|
|
$result = DealsResultset::createInstance(); |
|
114
|
|
|
|
|
115
|
|
|
$arrVouchers = $this->_network->getVouchers(); |
|
116
|
|
|
|
|
117
|
|
|
foreach($arrVouchers as $voucher) { |
|
118
|
|
|
if (!empty($voucher['promotioncode']) && !empty($voucher['program_id'])) { |
|
119
|
|
|
$Deal = Deal::createInstance(); |
|
120
|
|
|
$Deal->deal_ID = md5($voucher['program_id'] . $voucher['id']); // generate a unique deal ID |
|
|
|
|
|
|
121
|
|
|
$Deal->merchant_ID = $voucher['program_id']; |
|
122
|
|
|
$Deal->code = $voucher['promotioncode']; |
|
123
|
|
|
$Deal->name = $voucher['name']; |
|
124
|
|
|
$Deal->description = $voucher['description']; |
|
125
|
|
|
$Deal->start_date = $Deal->convertDate($voucher['start_date']); |
|
|
|
|
|
|
126
|
|
|
$Deal->start_date->setTime(0, 0, 0); |
|
127
|
|
|
$Deal->end_date = $Deal->convertDate($voucher['end_date']); |
|
|
|
|
|
|
128
|
|
|
$Deal->end_date->setTime(23, 59, 59); |
|
129
|
|
|
$Deal->default_track_uri = $voucher['click_url']; |
|
130
|
|
|
if (substr($Deal->default_track_uri,0,2) == '//') { |
|
131
|
|
|
// Special case... add https: |
|
132
|
|
|
$Deal->default_track_uri = 'https:' . $Deal->default_track_uri; |
|
133
|
|
|
} |
|
134
|
|
|
$Deal->is_exclusive = false; |
|
135
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
|
136
|
|
|
if ($voucher['measure'] == 'percentage') { |
|
137
|
|
|
$Deal->is_percentage = true; |
|
138
|
|
|
} |
|
139
|
|
|
else { |
|
140
|
|
|
$Deal->is_percentage = false; |
|
141
|
|
|
} |
|
142
|
|
|
$Deal->discount_amount = $voucher['amount']; |
|
143
|
|
|
$arrResult[] = $Deal; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
$result->deals[]=$arrResult; |
|
147
|
|
|
return $result; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param \DateTime $dateFrom |
|
152
|
|
|
* @param \DateTime $dateTo |
|
153
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
154
|
|
|
* @return array of Transaction |
|
155
|
|
|
*/ |
|
156
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
|
|
|
|
|
157
|
|
|
{ |
|
158
|
|
|
$arrResult = array(); |
|
159
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
|
160
|
|
|
foreach($transactionList as $transaction) { |
|
161
|
|
|
$Transaction = Transaction::createInstance(); |
|
162
|
|
|
if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
|
163
|
|
|
$Transaction->currency = $transaction['currency']; |
|
164
|
|
|
} else { |
|
165
|
|
|
$Transaction->currency = "EUR"; |
|
166
|
|
|
} |
|
167
|
|
|
$Transaction->status = $transaction['status']; |
|
168
|
|
|
$Transaction->amount = $transaction['amount']; |
|
169
|
|
|
array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
|
170
|
|
|
$Transaction->title = ''; |
|
171
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
|
172
|
|
|
$Transaction->commission = $transaction['commission']; |
|
173
|
|
|
$date = new \DateTime($transaction['date']); |
|
174
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
175
|
|
|
// Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
|
176
|
|
|
if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
|
177
|
|
|
$Transaction->click_date = new \DateTime($transaction['click_date']); |
|
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
|
180
|
|
|
$Transaction->update_date = new \DateTime($transaction['update_date']); |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
|
183
|
|
|
$Transaction->campaign_name = $transaction['merchantName']; |
|
184
|
|
|
$Transaction->IP = $transaction['IP']; |
|
185
|
|
|
$Transaction->approved = false; |
|
186
|
|
|
if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){ |
|
187
|
|
|
$Transaction->approved = true; |
|
188
|
|
|
} |
|
189
|
|
|
$arrResult[] = $Transaction; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
return $arrResult; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param \DateTime $dateFrom |
|
197
|
|
|
* @param \DateTime $dateTo |
|
198
|
|
|
* @param int $merchantID |
|
199
|
|
|
* @return array of Stat |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
202
|
|
|
{ |
|
203
|
|
|
throw new \Exception("Not implemented yet"); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @param array $params |
|
209
|
|
|
* |
|
210
|
|
|
* @return ProductsResultset |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
213
|
|
|
{ |
|
214
|
|
|
// TODO: Implement getProducts() method. |
|
215
|
|
|
throw new \Exception("Not implemented yet"); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function getTrackingParameter(){ |
|
219
|
|
|
return $this->_tracking_parameter; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.