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