|
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 EasyMarketing |
|
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
17
|
|
|
*/ |
|
18
|
|
|
class EasyMarketing extends AbstractNetwork implements NetworkInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var object |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_network = null; |
|
24
|
|
|
private $_username = ''; |
|
25
|
|
|
private $_password = ''; |
|
26
|
|
|
protected $_tracking_parameter = 'subid'; |
|
27
|
|
|
private $_idSite = ''; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @method __construct |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(string $username, string $password, string $idSite = '') |
|
33
|
|
|
{ |
|
34
|
|
|
$this->_network = new \Oara\Network\Publisher\EasyMarketing; |
|
35
|
|
|
$this->_username = $username; |
|
36
|
|
|
$this->_password = $password; |
|
37
|
|
|
$this->_idSite = $idSite; |
|
38
|
|
|
|
|
39
|
|
|
$this->login($this->_username, $this->_password, $this->_idSite); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function login(string $username, string $password, string $idSite = ''): bool |
|
43
|
|
|
{ |
|
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
|
|
|
throw new \Exception("Not implemented yet"); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param null $merchantID |
|
83
|
|
|
* @param int $page |
|
84
|
|
|
* @param int $items_per_page |
|
85
|
|
|
* @return DealsResultset array of Deal |
|
86
|
|
|
* @throws \Exception |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getDeals($merchantID = NULL, int $page = 0, int $items_per_page = 100): DealsResultset |
|
89
|
|
|
{ |
|
90
|
|
|
throw new \Exception("Not implemented yet"); |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param \DateTime $dateFrom |
|
96
|
|
|
* @param \DateTime $dateTo |
|
97
|
|
|
* @param array $arrMerchantID |
|
98
|
|
|
* @return array of Transaction |
|
99
|
|
|
* @throws \Exception |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()): array |
|
102
|
|
|
{ |
|
103
|
|
|
$arrResult = array(); |
|
104
|
|
|
try { |
|
105
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
|
106
|
|
|
foreach ($transactionList as $transaction) { |
|
107
|
|
|
$Transaction = Transaction::createInstance(); |
|
108
|
|
|
if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
|
109
|
|
|
$Transaction->currency = $transaction['currency']; |
|
110
|
|
|
} else { |
|
111
|
|
|
$Transaction->currency = "EUR"; |
|
112
|
|
|
} |
|
113
|
|
|
$Transaction->status = $transaction['status']; |
|
114
|
|
|
$Transaction->action = $transaction['action']; |
|
|
|
|
|
|
115
|
|
|
$Transaction->amount = $transaction['amount']; |
|
116
|
|
|
array_key_exists_safe($transaction, 'custom_id') ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
|
117
|
|
|
$Transaction->title = $transaction['title']; |
|
118
|
|
|
$Transaction->referrer = $transaction['referrer']; |
|
119
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
|
120
|
|
|
$Transaction->commission = $transaction['commission']; |
|
121
|
|
|
$date = new \DateTime($transaction['date']); |
|
122
|
|
|
$Transaction->date = $date; |
|
|
|
|
|
|
123
|
|
|
// Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
|
124
|
|
|
if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
|
125
|
|
|
$Transaction->click_date = new \DateTime($transaction['click_date']); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
if (isset($transaction['update_date']) && !empty($transaction['update_date'])) { |
|
128
|
|
|
$Transaction->update_date = new \DateTime($transaction['update_date']); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
if (isset($transaction['paid_date']) && !empty($transaction['paid_date'])) { |
|
131
|
|
|
$Transaction->paid_date = new \DateTime($transaction['paid_date']); |
|
|
|
|
|
|
132
|
|
|
$Transaction->paid = true; |
|
133
|
|
|
} |
|
134
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
|
135
|
|
|
$Transaction->campaign_name = $transaction['merchantName']; |
|
136
|
|
|
$Transaction->approved = false; |
|
137
|
|
|
if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED) { |
|
138
|
|
|
$Transaction->approved = true; |
|
139
|
|
|
} |
|
140
|
|
|
$arrResult[] = $Transaction; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
} catch (\Exception $e) { |
|
144
|
|
|
echo "[EasyMarketing][getSales][Exception] " . $e->getMessage() . PHP_EOL; |
|
145
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
|
|
146
|
|
|
throw new \Exception($e); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return $arrResult; |
|
150
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param \DateTime $dateFrom |
|
155
|
|
|
* @param \DateTime $dateTo |
|
156
|
|
|
* @param int $merchantID |
|
157
|
|
|
* @return array of Stat |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0): array |
|
160
|
|
|
{ |
|
161
|
|
|
// TODO |
|
162
|
|
|
return array(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param array $params |
|
168
|
|
|
* @return ProductsResultset |
|
169
|
|
|
* @throws \Exception |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
172
|
|
|
{ |
|
173
|
|
|
// TODO: Implement getProducts() method. |
|
174
|
|
|
throw new \Exception("Not implemented yet"); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function getTrackingParameter() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->_tracking_parameter; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
|
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: