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\AdtractionEx; |
13
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
14
|
|
|
|
15
|
|
|
if (!defined('COOKIES_BASE_DIR')){ |
16
|
|
|
define('COOKIES_BASE_DIR',public_path('upload/report')); |
17
|
|
|
} |
18
|
|
|
/** |
19
|
|
|
* Class Adtraction |
20
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
21
|
|
|
*/ |
22
|
|
|
class Adtraction extends AbstractNetwork implements NetworkInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var object |
26
|
|
|
*/ |
27
|
|
|
private $_network = null; |
28
|
|
|
private $_apiClient = null; |
29
|
|
|
private $_username = ''; |
30
|
|
|
private $_password = ''; |
31
|
|
|
private $_idSite = ''; |
32
|
|
|
private $_logged = false; |
33
|
|
|
protected $_tracking_parameter = 'epi'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Adtraction constructor. |
37
|
|
|
* @param string $username |
38
|
|
|
* @param string $password |
39
|
|
|
* @param string $idSite |
40
|
|
|
*/ |
41
|
|
View Code Duplication |
public function __construct(string $username, string $password, string $idSite = '') |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$this->_network = new \Oara\Network\Publisher\Adtraction; |
44
|
|
|
$this->_username = $username; |
45
|
|
|
$this->_password = $password; |
46
|
|
|
$this->_idSite = $idSite; |
47
|
|
|
$this->_apiClient = null; |
48
|
|
|
$this->login( $this->_username, $this->_password, $this->_idSite ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function login(string $username, string $password, string $idSite = ''): bool |
52
|
|
|
{ |
53
|
|
|
$this->_logged = false; |
54
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
55
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
$this->_username = $username; |
59
|
|
|
$this->_password = $password; |
60
|
|
|
$this->_idSite = $idSite; |
61
|
|
|
$credentials = array(); |
62
|
|
|
$credentials["user"] = null; // not used |
63
|
|
|
$credentials["password"] = $this->_password; |
64
|
|
|
$credentials["idSite"] = null; // not used |
65
|
|
|
$this->_network->login( $credentials ); |
66
|
|
|
|
67
|
|
|
if ($this->_network->checkConnection()) { |
68
|
|
|
$this->_logged = true; |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->_logged; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return bool |
77
|
|
|
*/ |
78
|
|
|
public function checkLogin() : bool |
79
|
|
|
{ |
80
|
|
|
return $this->_logged; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return array of Merchants |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function getMerchants() : array |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
if (!$this->checkLogin()) { |
89
|
|
|
return array(); |
90
|
|
|
} |
91
|
|
|
$arrResult = array(); |
92
|
|
|
$merchantList = $this->_network->getMerchantList(); |
93
|
|
|
foreach($merchantList as $merchant) { |
94
|
|
|
$Merchant = Merchant::createInstance(); |
95
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
96
|
|
|
$Merchant->name = $merchant['name']; |
97
|
|
|
$Merchant->status = $merchant['status']; |
98
|
|
|
if (!empty($merchant['launch_date'])) { |
99
|
|
|
$date = new \DateTime($merchant['launch_date']); |
100
|
|
|
$Merchant->launch_date = $date; |
|
|
|
|
101
|
|
|
} |
102
|
|
|
if (!empty($merchant['application_date'])) { |
103
|
|
|
$date = new \DateTime($merchant['application_date']); |
104
|
|
|
$Merchant->application_date = $date; |
|
|
|
|
105
|
|
|
} |
106
|
|
|
$arrResult[] = $Merchant; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $arrResult; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param int|null $merchantID |
114
|
|
|
* @param int $page |
115
|
|
|
* @param int $items_per_page |
116
|
|
|
* |
117
|
|
|
* @return DealsResultset |
118
|
|
|
*/ |
119
|
|
|
public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset |
120
|
|
|
{ |
121
|
|
|
throw new \Exception("Not implemented yet"); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param \DateTime $dateFrom |
126
|
|
|
* @param \DateTime $dateTo |
127
|
|
|
* @param int $merchantID |
|
|
|
|
128
|
|
|
* @return array of Transaction |
129
|
|
|
*/ |
130
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
131
|
|
|
{ |
132
|
|
|
if (!$this->checkLogin()) { |
133
|
|
|
return array(); |
134
|
|
|
} |
135
|
|
|
$arrResult = array(); |
136
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
137
|
|
|
foreach($transactionList as $transaction) { |
138
|
|
|
$Transaction = Transaction::createInstance(); |
139
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
140
|
|
|
$date = new \DateTime($transaction['date']); |
141
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
142
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
143
|
|
|
$Transaction->transaction_ID = $transaction['unique_id']; |
144
|
|
|
array_key_exists_safe( $transaction, |
145
|
|
|
'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
146
|
|
|
$Transaction->status = $transaction['status']; |
147
|
|
|
$Transaction->amount = $transaction['amount']; |
148
|
|
|
$Transaction->commission = $transaction['commission']; |
149
|
|
|
$Transaction->currency = $transaction['currency']; |
150
|
|
|
$arrResult[] = $Transaction; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $arrResult; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param \DateTime $dateFrom |
158
|
|
|
* @param \DateTime $dateTo |
159
|
|
|
* @param int $merchantID |
160
|
|
|
* @return array of Stat |
161
|
|
|
*/ |
162
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
163
|
|
|
{ |
164
|
|
|
return array(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param array $params |
170
|
|
|
* |
171
|
|
|
* @return ProductsResultset |
172
|
|
|
*/ |
173
|
|
|
public function getProducts(array $params = []): ProductsResultset |
174
|
|
|
{ |
175
|
|
|
// TODO: Implement getProducts() method. |
176
|
|
|
throw new \Exception("Not implemented yet"); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function getTrackingParameter(){ |
180
|
|
|
return $this->_tracking_parameter; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.