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
|
|
|
// Fixed endpoint to apiv2.effiliation.com <PN> 2020-08-12 |
74
|
|
|
$url = 'http://apiv2.effiliation.com/apiv2/programs.xml?key=' . $this->_password . "&filter=all"; |
75
|
|
|
echo "effiliation getMerchant url ",PHP_EOL; |
76
|
|
|
$content = @\file_get_contents($url); |
77
|
|
|
$xml = \simplexml_load_string($content, null, LIBXML_NOERROR | LIBXML_NOWARNING); |
78
|
|
|
if ($xml !== false) { |
79
|
|
|
foreach ($xml->program as $merchant) { |
80
|
|
|
$Merchant = Merchant::createInstance(); |
81
|
|
|
$Merchant->merchant_ID = (string)$merchant->id_programme; |
|
|
|
|
82
|
|
|
$Merchant->name = (string)$merchant->nom; |
83
|
|
|
// Added more info - 2018-04-23 <PN> |
84
|
|
|
$Merchant->launch_date = (string)$merchant->date_debut; |
85
|
|
|
$Merchant->termination_date = (string)$merchant->date_fin; |
86
|
|
|
$Merchant->status = (string)$merchant->etat; |
87
|
|
|
if (empty($Merchant->status)) { |
88
|
|
|
// Empty means "not applied" |
89
|
|
|
$Merchant->status = 'not-applied'; |
90
|
|
|
} |
91
|
|
|
$Merchant->url = (string)$merchant->url; |
92
|
|
|
$arrResult[] = $Merchant; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
return $arrResult; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param int $merchantID |
100
|
|
|
* @return array of Deal |
101
|
|
|
*/ |
102
|
|
|
public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=10 ): DealsResultset |
103
|
|
|
{ |
104
|
|
|
$result = DealsResultset::createInstance(); |
105
|
|
|
|
106
|
|
|
// Fixed endpoint to apiv2.effiliation.com <PN> 2020-08-12 |
107
|
|
|
$url = 'http://apiv2.effiliation.com/apiv2/commercialtrades.json?filter=mines&key='.$this->_password; |
108
|
|
|
$json = file_get_contents($url); |
109
|
|
|
|
110
|
|
|
$arrResult = array(); |
111
|
|
|
$arrResponse = json_decode($json, true); |
112
|
|
|
if(!is_array($arrResponse) || count($arrResponse) <= 0 || !array_key_exists('supports', $arrResponse)) { |
113
|
|
|
return $arrResult; |
114
|
|
|
} |
115
|
|
|
$arrPrograms = $arrResponse['supports']; |
116
|
|
|
foreach($arrPrograms as $voucher) { |
117
|
|
|
$Deal = Deal::createInstance(); |
118
|
|
|
$Deal->setValues($voucher, [ |
119
|
|
|
'id_lien' => 'deal_ID' , |
120
|
|
|
'id_programme' => 'merchant_ID' , |
121
|
|
|
'date_debut' => 'start_date' , |
122
|
|
|
'date_fin' => 'end_date' , |
123
|
|
|
'nom' => 'name' , |
124
|
|
|
'description' => 'description' , |
125
|
|
|
'intitule' => 'code' , |
126
|
|
|
'url_redir' => 'default_track_uri' , |
127
|
|
|
'exclusivite' => 'is_exclusive' , |
128
|
|
|
'type' => 'deal_type', |
129
|
|
|
]); |
130
|
|
|
switch ($voucher['type']) { |
131
|
|
|
case 'Code de réduction': |
132
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
133
|
|
|
break; |
134
|
|
|
case 'Bon plan': |
135
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
136
|
|
|
break; |
137
|
|
|
default: |
138
|
|
|
$Deal->deal_type = \Oara\Utilities::OFFER_TYPE_DISCOUNT; |
139
|
|
|
break; |
140
|
|
|
} |
141
|
|
|
if($merchantID > 0) { |
142
|
|
|
if($merchantID == $voucher['id_programme']) { |
143
|
|
|
$arrResult[] = $Deal; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
else { |
147
|
|
|
$arrResult[] = $Deal; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$result->deals[]=$arrResult; |
152
|
|
|
return $result; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param \DateTime $dateFrom |
157
|
|
|
* @param \DateTime $dateTo |
158
|
|
|
* @param int $merchantID |
|
|
|
|
159
|
|
|
* @return array of Transaction |
160
|
|
|
*/ |
161
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
162
|
|
|
{ |
163
|
|
|
$arrResult = array(); |
164
|
|
|
try { |
165
|
|
View Code Duplication |
if (count( $arrMerchantID ) < 1) { |
|
|
|
|
166
|
|
|
$merchants = $this->getMerchants(); |
167
|
|
|
foreach ($merchants as $merchant) { |
168
|
|
|
$arrMerchantID[$merchant->merchant_ID] = ['cid' => $merchant->merchant_ID, 'name' => $merchant->name]; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
$transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo); |
172
|
|
|
|
173
|
|
|
foreach($transactionList as $transaction) { |
174
|
|
|
$myTransaction = Transaction::createInstance(); |
175
|
|
|
try { |
176
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
177
|
|
|
$myTransaction->title =''; |
178
|
|
|
$myTransaction->currency ='EUR'; |
179
|
|
|
//echo "txdate: ".$transaction['date']."<br>"; |
180
|
|
|
if (!empty($transaction['date'])) { |
181
|
|
|
$date = new \DateTime($transaction['date']); |
182
|
|
|
$myTransaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
185
|
|
|
$myTransaction->custom_ID = $transaction['custom_id']; |
186
|
|
|
//var_dump($transaction); |
187
|
|
|
$myTransaction->status = $transaction['status']; |
188
|
|
|
$myTransaction->amount = $transaction['amount']; |
189
|
|
|
$myTransaction->commission = $transaction['commission']; |
190
|
|
|
$myTransaction->approved = false; |
191
|
|
|
if ($transaction['status'] == \Oara\Utilities::STATUS_CONFIRMED){ |
192
|
|
|
$myTransaction->approved = true; |
193
|
|
|
} |
194
|
|
|
$arrResult[] = $myTransaction; |
195
|
|
|
} catch (\Exception $e) { |
196
|
|
|
//echo "stepE "; |
197
|
|
|
echo "<br><br>errore transazione effilitation, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; |
198
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
199
|
|
|
//throw new \Exception($e); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
} catch (\Exception $e) { |
203
|
|
|
//echo "stepE "; |
204
|
|
|
echo "<br><br>errore generico transazione effiliation: ".$e->getMessage()."<br><br>"; |
205
|
|
|
var_dump($e->getTraceAsString()); |
206
|
|
|
throw new \Exception($e); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
return $arrResult; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param \DateTime $dateFrom |
214
|
|
|
* @param \DateTime $dateTo |
215
|
|
|
* @param int $merchantID |
216
|
|
|
* @return array of Stat |
217
|
|
|
*/ |
218
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
219
|
|
|
{ |
220
|
|
|
return array(); |
221
|
|
|
/* |
222
|
|
|
$this->_apiClient->setConnectId($this->_username); |
223
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
224
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
225
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
226
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
227
|
|
|
$arrResponse = json_decode($response, true); |
228
|
|
|
$reportItems = $arrResponse['reportItems']; |
229
|
|
|
$Stat = Stat::createInstance(); |
230
|
|
|
$Stat->reportItems = $reportItems; |
231
|
|
|
|
232
|
|
|
return array($Stat); |
233
|
|
|
*/ |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @param array $params |
239
|
|
|
* |
240
|
|
|
* @return ProductsResultset |
241
|
|
|
*/ |
242
|
|
|
public function getProducts(array $params = []): ProductsResultset |
243
|
|
|
{ |
244
|
|
|
// TODO: Implement getProducts() method. |
245
|
|
|
throw new \Exception("Not implemented yet"); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getTrackingParameter(){ |
249
|
|
|
return $this->_tracking_parameter; |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.