|
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
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class WebGains |
|
15
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
16
|
|
|
*/ |
|
17
|
|
|
class WebGains extends AbstractNetwork implements NetworkInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var object |
|
21
|
|
|
*/ |
|
22
|
|
|
private $_network = null; |
|
23
|
|
|
private $_username = ''; |
|
24
|
|
|
private $_password = ''; |
|
25
|
|
|
private $_apiClient = null; |
|
26
|
|
|
protected $_tracking_parameter = 'clickref'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @method __construct |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(string $username, string $password) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->_network = new \Oara\Network\Publisher\WebGains; |
|
34
|
|
|
$this->_username = $username; |
|
35
|
|
|
$this->_password = $password; |
|
36
|
|
|
$apiUrl = 'http://ws.webgains.com/aws.php'; |
|
37
|
|
|
$this->_apiClient = new \SoapClient($apiUrl, |
|
38
|
|
|
array('login' => $this->_username, |
|
39
|
|
|
'encoding' => 'UTF-8', |
|
40
|
|
|
'password' => $this->_password, |
|
41
|
|
|
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, |
|
42
|
|
|
'soap_version' => SOAP_1_1) |
|
43
|
|
|
); |
|
44
|
|
|
$this->login( $this->_username, $this->_password ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
public function login(string $username, string $password): bool{ |
|
|
|
|
|
|
48
|
|
|
$this->_logged = false; |
|
|
|
|
|
|
49
|
|
|
if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { |
|
50
|
|
|
|
|
51
|
|
|
return false; |
|
52
|
|
|
} |
|
53
|
|
|
$this->_username = $username; |
|
54
|
|
|
$this->_password = $password; |
|
55
|
|
|
$credentials = array(); |
|
56
|
|
|
$credentials["user"] = $this->_username; |
|
57
|
|
|
$credentials["password"] = $this->_password; |
|
58
|
|
|
$this->_network->login($credentials); |
|
59
|
|
|
if ($this->_network->checkConnection()) { |
|
60
|
|
|
$this->_logged = true; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $this->_logged; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public function checkLogin() : bool |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->_logged; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return array of Merchants |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getMerchants() : array |
|
78
|
|
|
{ |
|
79
|
|
|
$arrResult = array(); |
|
80
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
81
|
|
|
foreach($merchantList as $merchant) { |
|
82
|
|
|
$Merchant = Merchant::createInstance(); |
|
83
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
|
84
|
|
|
$Merchant->name = $merchant['name']; |
|
85
|
|
|
$arrResult[] = $Merchant; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $arrResult; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param int $merchantID |
|
93
|
|
|
* @return array of Deal |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
|
96
|
|
|
{ |
|
97
|
|
|
$arrResult = array(); |
|
98
|
|
|
$arrResponse = $this->_apiClient->getFullEarnings(null, null, null, $this->_username, $this->_password); |
|
99
|
|
|
foreach($arrResponse as $response) { |
|
100
|
|
|
$Deal = Deal::createInstance(); |
|
101
|
|
|
$Deal->transaction_ID = $response->transactionID; |
|
|
|
|
|
|
102
|
|
|
$Deal->affiliate_ID = $response->affiliate_ID; |
|
|
|
|
|
|
103
|
|
|
$Deal->campaign_name = $response->campaignName; |
|
|
|
|
|
|
104
|
|
|
$Deal->campaign_ID = $response->campaignID; |
|
|
|
|
|
|
105
|
|
|
$date = new \DateTime($response->date); |
|
|
|
|
|
|
106
|
|
|
$Deal->date = $response->date; |
|
|
|
|
|
|
107
|
|
|
$Deal->programName = $response->program_name; |
|
|
|
|
|
|
108
|
|
|
$Deal->merchant_ID = $response->programID; |
|
109
|
|
|
$Deal->commission = $response->commission; |
|
|
|
|
|
|
110
|
|
|
$Deal->amount = $response->saleValue; |
|
|
|
|
|
|
111
|
|
|
$Deal->status = $response->status; |
|
|
|
|
|
|
112
|
|
|
$Deal->referrer = $response->referrer; |
|
|
|
|
|
|
113
|
|
|
if($merchantID > 0) { |
|
114
|
|
|
if($merchantID == $response->programID) { |
|
115
|
|
|
$arrResult[] = $Deal; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
else { |
|
119
|
|
|
$arrResult[] = $Deal; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $arrResult; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param \DateTime $dateFrom |
|
128
|
|
|
* @param \DateTime $dateTo |
|
129
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
130
|
|
|
* @return array of Transaction |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
133
|
|
|
{ |
|
134
|
|
|
if (count( $arrMerchantID ) < 1) { |
|
135
|
|
|
$merchants = $this->getMerchants(); |
|
136
|
|
|
foreach ($merchants as $merchant) { |
|
137
|
|
|
$arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name]; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
$arrResult = array(); |
|
141
|
|
|
$transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom); |
|
142
|
|
|
foreach($transcationList as $transaction) { |
|
143
|
|
|
$Transaction = Transaction::createInstance(); |
|
144
|
|
|
$Transaction->currency = $transaction['currency']; |
|
145
|
|
|
$Transaction->status = $transaction['status']; |
|
146
|
|
|
$Transaction->amount = $transaction['amount']; |
|
147
|
|
|
$Transaction->custom_ID = $transaction['custom_id']; |
|
148
|
|
|
$Transaction->title = $transaction['title']; |
|
149
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
|
150
|
|
|
$Transaction->commission = $transaction['commission']; |
|
151
|
|
|
$date = new \DateTime($transaction['date']); |
|
152
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
153
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
|
154
|
|
|
$Transaction->approved = $transaction['approved']; |
|
155
|
|
|
$arrResult[] = $Transaction; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return $arrResult; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @param \DateTime $dateFrom |
|
163
|
|
|
* @param \DateTime $dateTo |
|
164
|
|
|
* @param int $merchantID |
|
165
|
|
|
* @return array of Stat |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
168
|
|
|
{ |
|
169
|
|
|
return array(); |
|
170
|
|
|
/* |
|
|
|
|
|
|
171
|
|
|
$this->_apiClient->setConnectId($this->_username); |
|
172
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
|
173
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
|
174
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
|
175
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
|
176
|
|
|
$arrResponse = json_decode($response, true); |
|
177
|
|
|
$reportItems = $arrResponse['reportItems']; |
|
178
|
|
|
$Stat = Stat::createInstance(); |
|
179
|
|
|
$Stat->reportItems = $reportItems; |
|
180
|
|
|
|
|
181
|
|
|
return array($Stat); |
|
182
|
|
|
*/ |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function getTrackingParameter(){ |
|
186
|
|
|
return $this->_tracking_parameter; |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
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.