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
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
12
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
13
|
|
|
|
14
|
|
|
// require "../vendor/fubralimited/php-oara/Oara/Network/Publisher/Effiliation/Zapi/ApiClient.php"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Effiliation |
18
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
19
|
|
|
*/ |
20
|
|
|
class Effiliation extends AbstractNetwork implements NetworkInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var object |
24
|
|
|
*/ |
25
|
|
|
private $_network = null; |
26
|
|
|
private $_apiClient = null; |
27
|
|
|
private $_password = ''; |
28
|
|
|
protected $_tracking_parameter = 'effi_id'; |
29
|
|
|
/** |
30
|
|
|
* @method __construct |
31
|
|
|
*/ |
32
|
|
|
public function __construct(string $username, string $password,string $idSite='') |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$this->_network = new \Padosoft\AffiliateNetwork\EffiliationEx; |
35
|
|
|
$this->_username = $username; |
|
|
|
|
36
|
|
|
$this->_password = $password; |
37
|
|
|
$this->login( $this->_username, $this->_password ); |
|
|
|
|
38
|
|
|
$this->_apiClient = null; |
39
|
|
|
} |
40
|
|
|
public function login(string $username, string $password,string $idSite=''): bool{ |
|
|
|
|
41
|
|
|
$this->_logged = false; |
|
|
|
|
42
|
|
|
if (isNullOrEmpty( $password )) { |
43
|
|
|
|
44
|
|
|
return false; |
45
|
|
|
} |
46
|
|
|
$this->_username = $username; |
|
|
|
|
47
|
|
|
$this->_password = $password; |
48
|
|
|
$credentials = array(); |
49
|
|
|
$credentials["apiPassword"] = $this->_password; |
50
|
|
|
$this->_network->login($credentials); |
51
|
|
|
if ($this->_network->checkConnection()) { |
52
|
|
|
$this->_logged = true; |
53
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->_logged; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
|
|
public function checkLogin() : bool |
63
|
|
|
{ |
64
|
|
|
return $this->_logged; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array of Merchants |
69
|
|
|
*/ |
70
|
|
|
public function getMerchants() : array |
71
|
|
|
{ |
72
|
|
|
$arrResult = array(); |
73
|
|
|
$url = 'http://api.effiliation.com/apiv2/programs.xml?key=' . $this->_password . "&filter=all"; |
74
|
|
|
$content = @\file_get_contents($url); |
75
|
|
|
$xml = \simplexml_load_string($content, null, LIBXML_NOERROR | LIBXML_NOWARNING); |
76
|
|
|
foreach ($xml->program as $merchant) { |
77
|
|
|
$Merchant = Merchant::createInstance(); |
78
|
|
|
$Merchant->merchant_ID = (string)$merchant->id_programme; |
|
|
|
|
79
|
|
|
$Merchant->name = (string)$merchant->nom; |
80
|
|
|
$arrResult[] = $Merchant; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $arrResult; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param int $merchantID |
88
|
|
|
* @return array of Deal |
89
|
|
|
*/ |
90
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
91
|
|
|
{ |
92
|
|
|
$url = 'http://apiv2.effiliation.com/apiv2/programs.json?filter=mines&key='.$this->_password; |
93
|
|
|
$json = file_get_contents($url); |
94
|
|
|
$arrResult = array(); |
95
|
|
|
$arrResponse = json_decode($json, true); |
96
|
|
|
if(!is_array($arrResponse) || count($arrResponse) <= 0) { |
97
|
|
|
return $arrResult; |
98
|
|
|
} |
99
|
|
|
$arrPrograms = $arrResponse['programs']; |
100
|
|
View Code Duplication |
foreach($arrPrograms as $item) { |
|
|
|
|
101
|
|
|
$Deal = Deal::createInstance(); |
102
|
|
|
$Deal->merchant_ID = $item['id_programme']; |
103
|
|
|
$Deal->code = $item['code']; |
104
|
|
|
$Deal->name = $item['nom']; |
105
|
|
|
$Deal->startDate = $item['date_debut']; |
106
|
|
|
$Deal->description = $item['description']; |
107
|
|
|
$Deal->url = $item['url_tracke']; |
108
|
|
|
if($merchantID > 0) { |
109
|
|
|
if($merchantID == $item['id_programme']) { |
110
|
|
|
$arrResult[] = $Deal; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
else { |
114
|
|
|
$arrResult[] = $Deal; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $arrResult; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param \DateTime $dateFrom |
123
|
|
|
* @param \DateTime $dateTo |
124
|
|
|
* @param int $merchantID |
|
|
|
|
125
|
|
|
* @return array of Transaction |
126
|
|
|
*/ |
127
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
128
|
|
|
{ |
129
|
|
|
$arrResult = array(); |
130
|
|
|
try { |
131
|
|
View Code Duplication |
if (count( $arrMerchantID ) < 1) { |
|
|
|
|
132
|
|
|
$merchants = $this->getMerchants(); |
133
|
|
|
foreach ($merchants as $merchant) { |
134
|
|
|
$arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name]; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
$transcationList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
138
|
|
|
|
139
|
|
|
foreach($transcationList as $transaction) { |
140
|
|
|
$myTransaction = Transaction::createInstance(); |
141
|
|
|
try { |
142
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
143
|
|
|
$myTransaction->title =''; |
144
|
|
|
$myTransaction->currency ='EUR'; |
145
|
|
|
$date = new \DateTime($transaction['date']); |
146
|
|
|
$myTransaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
147
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
148
|
|
|
$myTransaction->custom_ID = $transaction['custom_id']; |
149
|
|
|
//var_dump($transaction); |
150
|
|
|
$myTransaction->status = $transaction['status']; |
151
|
|
|
$myTransaction->amount = $transaction['amount']; |
152
|
|
|
$myTransaction->commission = $transaction['commission']; |
153
|
|
|
$myTransaction->approved = false; |
154
|
|
|
if ($transaction['status'] == \Oara\Utilities::STATUS_CONFIRMED){ |
155
|
|
|
$myTransaction->approved = true; |
156
|
|
|
} |
157
|
|
|
$arrResult[] = $myTransaction; |
158
|
|
|
} catch (\Exception $e) { |
159
|
|
|
//echo "stepE "; |
160
|
|
|
echo "<br><br>errore transazione effilitation, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; |
161
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
162
|
|
|
//throw new \Exception($e); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} catch (\Exception $e) { |
166
|
|
|
//echo "stepE "; |
167
|
|
|
echo "<br><br>errore generico transazione effiliation: ".$e->getMessage()."<br><br>"; |
168
|
|
|
var_dump($e->getTraceAsString()); |
169
|
|
|
throw new \Exception($e); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return $arrResult; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param \DateTime $dateFrom |
177
|
|
|
* @param \DateTime $dateTo |
178
|
|
|
* @param int $merchantID |
179
|
|
|
* @return array of Stat |
180
|
|
|
*/ |
181
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
182
|
|
|
{ |
183
|
|
|
return array(); |
184
|
|
|
/* |
|
|
|
|
185
|
|
|
$this->_apiClient->setConnectId($this->_username); |
186
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
187
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
188
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
189
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
190
|
|
|
$arrResponse = json_decode($response, true); |
191
|
|
|
$reportItems = $arrResponse['reportItems']; |
192
|
|
|
$Stat = Stat::createInstance(); |
193
|
|
|
$Stat->reportItems = $reportItems; |
194
|
|
|
|
195
|
|
|
return array($Stat); |
196
|
|
|
*/ |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param array $params |
202
|
|
|
* |
203
|
|
|
* @return ProductsResultset |
204
|
|
|
*/ |
205
|
|
|
public function getProducts(array $params = []): ProductsResultset |
206
|
|
|
{ |
207
|
|
|
// TODO: Implement getProducts() method. |
208
|
|
|
throw new \Exception("Not implemented yet"); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function getTrackingParameter(){ |
212
|
|
|
return $this->_tracking_parameter; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.