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
|
|
|
use Padosoft\AffiliateNetwork\EbayEx; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Ebay |
17
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
18
|
|
|
*/ |
19
|
|
|
class Ebay extends AbstractNetwork implements NetworkInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var object |
23
|
|
|
*/ |
24
|
|
|
private $_network = null; |
25
|
|
|
private $_username = ''; |
26
|
|
|
private $_password = ''; |
27
|
|
|
protected $_apiClient = null; |
28
|
|
|
protected $_tracking_parameter = 'clickref'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @method __construct |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function __construct(string $username, string $password, string $idSite='') |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$this->_network = new EbayEx; |
36
|
|
|
$this->_username = $username; |
37
|
|
|
$this->_password = $password; |
38
|
|
|
if (trim($idSite)!=''){ |
39
|
|
|
// Ebay needs Site to filter countries |
40
|
|
|
$this->addAllowedSite($idSite); |
41
|
|
|
} |
42
|
|
|
/* |
|
|
|
|
43
|
|
|
$apiUrl = 'http://ws.webgains.com/aws.php'; |
44
|
|
|
$this->_apiClient = new \SoapClient($apiUrl, |
45
|
|
|
array('login' => $this->_username, |
46
|
|
|
'encoding' => 'UTF-8', |
47
|
|
|
'password' => $this->_password, |
48
|
|
|
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, |
49
|
|
|
'soap_version' => SOAP_1_1) |
50
|
|
|
); |
51
|
|
|
*/ |
52
|
|
|
$this->login( $this->_username, $this->_password ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function addAllowedSite($idSite){ |
56
|
|
|
if (trim($idSite)!=''){ |
57
|
|
|
$this->_network->addAllowedSite($idSite); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function login(string $username, string $password,string $idSite=''): bool{ |
|
|
|
|
62
|
|
|
$this->_logged = false; |
|
|
|
|
63
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
64
|
|
|
|
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
$this->_username = $username; |
68
|
|
|
$this->_password = $password; |
69
|
|
|
if (trim($idSite)!=''){ |
70
|
|
|
// Ebay needs Site to filter countries |
71
|
|
|
$this->addAllowedSite($idSite); |
72
|
|
|
} |
73
|
|
|
$credentials = array(); |
74
|
|
|
$credentials["user"] = $this->_username; |
75
|
|
|
$credentials["password"] = $this->_password; |
76
|
|
|
$this->_network->login($credentials); |
77
|
|
|
if ($this->_network->checkConnection()) { |
78
|
|
|
$this->_logged = true; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this->_logged; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
public function checkLogin() : bool |
88
|
|
|
{ |
89
|
|
|
return $this->_logged; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return array of Merchants |
94
|
|
|
*/ |
95
|
|
|
public function getMerchants() : array |
96
|
|
|
{ |
97
|
|
|
$arrResult = array(); |
98
|
|
|
return $arrResult; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param int $merchantID |
103
|
|
|
* @return array of Deal |
104
|
|
|
*/ |
105
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
106
|
|
|
{ |
107
|
|
|
$arrResult = array(); |
108
|
|
|
return $arrResult; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param \DateTime $dateFrom |
113
|
|
|
* @param \DateTime $dateTo |
114
|
|
|
* @param int $merchantID |
|
|
|
|
115
|
|
|
* @return array of Transaction |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
$arrResult = array(); |
120
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
121
|
|
|
foreach($transactionList as $transaction) { |
122
|
|
|
$Transaction = Transaction::createInstance(); |
123
|
|
|
|
124
|
|
|
if (isset($transaction['currency']) && !empty($transaction['currency'])) { |
125
|
|
|
$Transaction->currency = $transaction['currency']; |
126
|
|
|
} else { |
127
|
|
|
$Transaction->currency = "EUR"; |
128
|
|
|
} |
129
|
|
|
$Transaction->status = $transaction['status']; |
130
|
|
|
$Transaction->amount = $transaction['amount']; |
131
|
|
|
array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = ''; |
132
|
|
|
$Transaction->title = ''; |
133
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
134
|
|
|
$Transaction->commission = $transaction['commission']; |
135
|
|
|
$date = new \DateTime($transaction['date']); |
136
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
137
|
|
|
// Future use - Only few providers returns these dates values - <PN> - 2017-06-29 |
138
|
|
|
if (isset($transaction['click_date']) && !empty($transaction['click_date'])) { |
139
|
|
|
$Transaction->click_date = new \DateTime($transaction['click_date']); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
if (isset($transaction['post_date']) && !empty($transaction['post_date'])) { |
142
|
|
|
$Transaction->update_date = new \DateTime($transaction['post_date']); |
|
|
|
|
143
|
|
|
} |
144
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
145
|
|
|
$Transaction->campaign_name = $transaction['merchantName']; |
146
|
|
|
// $Transaction->IP = $transaction['IP']; |
|
|
|
|
147
|
|
|
$Transaction->approved = false; |
148
|
|
|
if ($Transaction->status==\Oara\Utilities::STATUS_CONFIRMED){ |
149
|
|
|
$Transaction->approved = true; |
150
|
|
|
} |
151
|
|
|
$arrResult[] = $Transaction; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $arrResult; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param \DateTime $dateFrom |
159
|
|
|
* @param \DateTime $dateTo |
160
|
|
|
* @param int $merchantID |
161
|
|
|
* @return array of Stat |
162
|
|
|
*/ |
163
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
164
|
|
|
{ |
165
|
|
|
// TODO |
166
|
|
|
return array(); |
167
|
|
|
/* |
|
|
|
|
168
|
|
|
$this->_apiClient->setConnectId($this->_username); |
169
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
170
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
171
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
172
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
173
|
|
|
$arrResponse = json_decode($response, true); |
174
|
|
|
$reportItems = $arrResponse['reportItems']; |
175
|
|
|
$Stat = Stat::createInstance(); |
176
|
|
|
$Stat->reportItems = $reportItems; |
177
|
|
|
|
178
|
|
|
return array($Stat); |
179
|
|
|
*/ |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param array $params |
185
|
|
|
* |
186
|
|
|
* @return ProductsResultset |
187
|
|
|
*/ |
188
|
|
|
public function getProducts(array $params = []): ProductsResultset |
189
|
|
|
{ |
190
|
|
|
// TODO: Implement getProducts() method. |
191
|
|
|
throw new \Exception("Not implemented yet"); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function getTrackingParameter(){ |
195
|
|
|
return $this->_tracking_parameter; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
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.