1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) Padosoft.com 2017. |
4
|
|
|
* Created by Paolo Nardini - 2017-08-31 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
namespace Padosoft\AffiliateNetwork; |
9
|
|
|
use Oara\Network\Publisher\Ebay as EbayOara; |
10
|
|
|
|
11
|
|
|
class EbayEx extends EbayOara |
12
|
|
|
{ |
13
|
|
|
protected $_serverNumber = 6; |
14
|
|
|
protected $_merchantIdList = array(); // To avoid repeated calls to \Oara\Utilities::getMerchantIdMapFromMerchantList |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param $credentials |
18
|
|
|
*/ |
19
|
|
|
public function login($credentials) |
20
|
|
|
{ |
21
|
|
|
$this->_credentials = $credentials; |
|
|
|
|
22
|
|
|
$this->_client = new \Oara\Curl\Access($credentials); |
23
|
|
|
|
24
|
|
|
/* |
25
|
|
|
$valuesLogin = array( |
26
|
|
|
new \Oara\Curl\Parameter('login_username', $this->_credentials['user']), |
27
|
|
|
new \Oara\Curl\Parameter('login_password', $this->_credentials['password']), |
28
|
|
|
new \Oara\Curl\Parameter('submit_btn', 'GO'), |
29
|
|
|
new \Oara\Curl\Parameter('hubpage', 'y') |
30
|
|
|
); |
31
|
|
|
$loginUrl = 'https://ebaypartnernetwork.com/PublisherLogin?hubpage=y&lang=en-US?'; |
32
|
|
|
|
33
|
|
|
$urls = array(); |
34
|
|
|
$urls[] = new \Oara\Curl\Request($loginUrl, $valuesLogin); |
35
|
|
|
$this->_client->post($urls); |
36
|
|
|
*/ |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function getNeededCredentials() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$credentials = array(); |
45
|
|
|
|
46
|
|
|
$parameter = array(); |
47
|
|
|
$parameter["description"] = "User Log in"; |
48
|
|
|
$parameter["required"] = true; |
49
|
|
|
$parameter["name"] = "User"; |
50
|
|
|
$credentials["user"] = $parameter; |
51
|
|
|
|
52
|
|
|
$parameter = array(); |
53
|
|
|
$parameter["description"] = "Password to Log in"; |
54
|
|
|
$parameter["required"] = true; |
55
|
|
|
$parameter["name"] = "Password"; |
56
|
|
|
$credentials["password"] = $parameter; |
57
|
|
|
|
58
|
|
|
return $credentials; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
public function checkConnection() |
65
|
|
|
{ |
66
|
|
|
//If not login properly the construct launch an exception |
67
|
|
|
$connection = true; |
68
|
|
|
/* |
69
|
|
|
$yesterday = new \DateTime(); |
70
|
|
|
$yesterday->sub(new \DateInterval('P2D')); |
71
|
|
|
|
72
|
|
|
$urls = array(); |
73
|
|
|
$urls[] = new \Oara\Curl\Request("https://publisher.ebaypartnernetwork.com/PublisherReportsTx?pt=2&start_date={$yesterday->format("n/j/Y")}&end_date={$yesterday->format("n/j/Y")}&user_name={$this->_credentials['user']}&user_password={$this->_credentials['password']}&advIdProgIdCombo=&tx_fmt=2&submit_tx=Download", array()); |
74
|
|
|
$exportReport = $this->_client->get($urls); |
75
|
|
|
|
76
|
|
|
if (\preg_match("/DOCTYPE html PUBLIC/", $exportReport[0])) { |
77
|
|
|
$connection = false; |
78
|
|
|
} |
79
|
|
|
*/ |
80
|
|
|
return $connection; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $idSite |
85
|
|
|
*/ |
86
|
|
|
public function addAllowedSite(string $idSite){ |
87
|
|
|
$this->_sitesAllowed[]=$idSite; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function getMerchantList() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$merchants = array(); |
96
|
|
|
|
97
|
|
|
$obj = array(); |
98
|
|
|
$obj['cid'] = "1"; |
99
|
|
|
$obj['name'] = "Ebay"; |
100
|
|
|
$obj['url'] = "https://publisher.ebaypartnernetwork.com"; |
101
|
|
|
$merchants[] = $obj; |
102
|
|
|
|
103
|
|
|
return $merchants; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param null $merchantList |
108
|
|
|
* @param \DateTime|null $dStartDate |
109
|
|
|
* @param \DateTime|null $dEndDate |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
|
|
public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
113
|
|
|
{ |
114
|
|
|
$totalTransactions = array(); |
115
|
|
|
|
116
|
|
|
$urls = array(); |
117
|
|
|
|
118
|
|
|
$postParams = array( |
119
|
|
|
new \Oara\Curl\Parameter('username', $this->_credentials['user']), |
120
|
|
|
new \Oara\Curl\Parameter('password', $this->_credentials['password']), |
121
|
|
|
new \Oara\Curl\Parameter('isEnc', 'false'), |
122
|
|
|
new \Oara\Curl\Parameter('fileFormat', 'txt'), |
123
|
|
|
new \Oara\Curl\Parameter('eventType', 'earnings'), // use 'all' to download all events |
124
|
|
|
new \Oara\Curl\Parameter('startPostDate', $dStartDate->format('Y-m-d')), |
|
|
|
|
125
|
|
|
new \Oara\Curl\Parameter('endPostDate', $dEndDate->format('Y-m-d')), |
|
|
|
|
126
|
|
|
); |
127
|
|
|
$url = new \Oara\Curl\Request("https://api.epn.ebay.com/rpt/events/v1/detail/tdr", $postParams ); |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
$urls[] = $url; |
131
|
|
|
$exportData = array(); |
132
|
|
|
|
133
|
|
|
try { |
134
|
|
|
$exportReport = $this->_client->post($urls, 0); |
135
|
|
|
$exportData = \str_getcsv($exportReport[0], "\n"); |
136
|
|
|
} catch (\Exception $e) { |
137
|
|
|
// ignore any error |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// OLD Version - URL Doesn't work anymore - 2017-08-31 <PN> |
141
|
|
|
/* |
142
|
|
|
$urls = array(); |
143
|
|
|
$urls[] = new \Oara\Curl\Request("https://publisher.ebaypartnernetwork.com/PublisherReportsTx?pt=2&start_date={$dStartDate->format("n/j/Y")}&end_date={$dEndDate->format("n/j/Y")}&user_name={$this->_credentials['user']}&user_password={$this->_credentials['password']}&advIdProgIdCombo=&tx_fmt=3&submit_tx=Download", array()); |
144
|
|
|
$exportData = array(); |
145
|
|
|
try { |
146
|
|
|
$exportReport = $this->_client->get($urls, 'content', 5); |
147
|
|
|
$exportData = \str_getcsv($exportReport[0], "\n"); |
148
|
|
|
} catch (\Exception $e) { |
149
|
|
|
|
150
|
|
|
*/ |
151
|
|
|
$num = \count($exportData); |
152
|
|
|
for ($i = 1; $i < $num; $i++) { |
153
|
|
|
$transactionExportArray = \str_getcsv($exportData[$i], "\t"); |
154
|
|
|
|
155
|
|
|
if ($transactionExportArray[2] == "Winning Bid (Revenue)" && (empty($this->_sitesAllowed) || \in_array($transactionExportArray[5], $this->_sitesAllowed))) { |
156
|
|
|
$transaction = Array(); |
157
|
|
|
$transaction['merchantId'] = 0; |
158
|
|
|
$transaction['merchantName'] = ''; |
159
|
|
|
$transaction['unique_id'] = $transactionExportArray[18]; |
160
|
|
|
$transactionDate = \DateTime::createFromFormat("Y-m-d", $transactionExportArray[0]); |
161
|
|
|
$transaction['date'] = $transactionDate->format("Y-m-d") . ' 00:00:00'; |
162
|
|
|
$postDate = \DateTime::createFromFormat("Y-m-d", $transactionExportArray[1]); |
163
|
|
|
$transaction['post_date'] = $postDate->format("Y-m-d") . ' 00:00:00'; |
164
|
|
|
if ($transactionExportArray[10] != null) { |
165
|
|
|
$transaction['custom_id'] = $transactionExportArray[10]; |
166
|
|
|
} |
167
|
|
|
$transaction['click_date'] = $transactionExportArray[11]; |
168
|
|
|
$transaction['ebay_amount'] = (float) $transactionExportArray[3]; |
169
|
|
|
$transaction['amount'] = (float) $transactionExportArray[15]; |
170
|
|
|
$transaction['commission'] = (float) $transactionExportArray[20]; |
171
|
|
|
// Set status as Pending |
172
|
|
|
// ... real status (approved / denied) must be calculated by summing all negative/positive records |
173
|
|
|
// ... and checking final amount for a positive or zero value |
174
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
175
|
|
|
$totalTransactions[] = $transaction; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
return $totalTransactions; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
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: