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