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