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
|
|
|
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
|
|
View Code Duplication |
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_date = null; |
85
|
|
|
} |
86
|
|
|
else { |
87
|
|
|
$date = new \DateTime($merchant['start_date']); |
|
|
|
|
88
|
|
|
//TODO check date format |
89
|
|
|
//$Merchant->launch_date = $date; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
View Code Duplication |
if (!empty($merchant['end_date'])) { |
|
|
|
|
93
|
|
|
if ($merchant['end_date'] == '0000-00-00') { |
94
|
|
|
$Merchant->termination_date = null; |
95
|
|
|
} |
96
|
|
|
else { |
97
|
|
|
$date = new \DateTime($merchant['end_date']); |
98
|
|
|
$Merchant->termination_date = $date; |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
$arrResult[] = $Merchant; |
102
|
|
|
} |
103
|
|
|
return $arrResult; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param int $merchantID |
108
|
|
|
* @return array of Deal |
109
|
|
|
*/ |
110
|
|
|
public function getDeals($merchantID = null,int $page = 0,int $items_per_page = 100 ): DealsResultset |
111
|
|
|
{ |
112
|
|
|
$arrResult = array(); |
113
|
|
|
|
114
|
|
|
$result = DealsResultset::createInstance(); |
115
|
|
|
|
116
|
|
|
$arrVouchers = $this->_network->getVouchers(); |
117
|
|
|
|
118
|
|
|
foreach($arrVouchers as $voucher) { |
119
|
|
|
if (!empty($voucher['promotioncode']) && !empty($voucher['program_id'])) { |
120
|
|
|
$Deal = Deal::createInstance(); |
121
|
|
|
$Deal->deal_ID = md5($voucher['program_id'] . $voucher['id']); // generate a unique deal ID |
|
|
|
|
122
|
|
|
$Deal->merchant_ID = $voucher['program_id']; |
123
|
|
|
$Deal->code = $voucher['promotioncode']; |
124
|
|
|
$Deal->name = $voucher['name']; |
125
|
|
|
$Deal->description = $voucher['description']; |
126
|
|
|
$Deal->start_date = $Deal->convertDate($voucher['start_date']); |
|
|
|
|
127
|
|
|
$Deal->start_date->setTime(0, 0, 0); |
128
|
|
|
$Deal->end_date = $Deal->convertDate($voucher['end_date']); |
|
|
|
|
129
|
|
|
$Deal->end_date->setTime(23, 59, 59); |
130
|
|
|
$Deal->default_track_uri = $voucher['click_url']; |
131
|
|
|
if (substr($Deal->default_track_uri,0,2) == '//') { |
132
|
|
|
// Special case... add https: |
133
|
|
|
$Deal->default_track_uri = 'https:' . $Deal->default_track_uri; |
134
|
|
|
} |
135
|
|
|
$Deal->is_exclusive = false; |
136
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
137
|
|
|
if ($voucher['measure'] == 'percentage') { |
138
|
|
|
$Deal->is_percentage = true; |
139
|
|
|
} |
140
|
|
|
else { |
141
|
|
|
$Deal->is_percentage = false; |
142
|
|
|
} |
143
|
|
|
$Deal->discount_amount = $voucher['amount']; |
144
|
|
|
$arrResult[] = $Deal; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
$result->deals[]=$arrResult; |
148
|
|
|
return $result; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param \DateTime $dateFrom |
153
|
|
|
* @param \DateTime $dateTo |
154
|
|
|
* @param int $merchantID |
|
|
|
|
155
|
|
|
* @return array of Transaction |
156
|
|
|
*/ |
157
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
$arrResult = array(); |
160
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
161
|
|
|
foreach($transactionList as $transaction) { |
162
|
|
|
$Transaction = Transaction::createInstance(); |
163
|
|
|
if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
164
|
|
|
$Transaction->currency = $transaction['currency']; |
165
|
|
|
} else { |
166
|
|
|
$Transaction->currency = "EUR"; |
167
|
|
|
} |
168
|
|
|
$Transaction->status = $transaction['status']; |
169
|
|
|
$Transaction->amount = $transaction['amount']; |
170
|
|
|
array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
171
|
|
|
$Transaction->title = ''; |
172
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
173
|
|
|
$Transaction->commission = $transaction['commission']; |
174
|
|
|
$date = new \DateTime($transaction['date']); |
175
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
176
|
|
|
// Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
177
|
|
|
if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
178
|
|
|
$Transaction->click_date = new \DateTime($transaction['click_date']); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
181
|
|
|
$Transaction->update_date = new \DateTime($transaction['update_date']); |
|
|
|
|
182
|
|
|
} |
183
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
184
|
|
|
$Transaction->campaign_name = $transaction['merchantName']; |
185
|
|
|
$Transaction->IP = $transaction['IP']; |
186
|
|
|
$Transaction->approved = false; |
187
|
|
|
if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){ |
188
|
|
|
$Transaction->approved = true; |
189
|
|
|
} |
190
|
|
|
$arrResult[] = $Transaction; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $arrResult; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param \DateTime $dateFrom |
198
|
|
|
* @param \DateTime $dateTo |
199
|
|
|
* @param int $merchantID |
200
|
|
|
* @return array of Stat |
201
|
|
|
*/ |
202
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
203
|
|
|
{ |
204
|
|
|
throw new \Exception("Not implemented yet"); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param array $params |
210
|
|
|
* |
211
|
|
|
* @return ProductsResultset |
212
|
|
|
*/ |
213
|
|
|
public function getProducts(array $params = []): ProductsResultset |
214
|
|
|
{ |
215
|
|
|
// TODO: Implement getProducts() method. |
216
|
|
|
throw new \Exception("Not implemented yet"); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function getTrackingParameter(){ |
220
|
|
|
return $this->_tracking_parameter; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.