|
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
|
|
|
// require "../vendor/fubralimited/php-oara/Oara/Network/Publisher/Effiliation/Zapi/ApiClient.php"; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Effiliation |
|
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
17
|
|
|
*/ |
|
18
|
|
|
class Effiliation extends AbstractNetwork implements NetworkInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var object |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_network = null; |
|
24
|
|
|
private $_apiClient = null; |
|
25
|
|
|
private $_password = ''; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @method __construct |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(string $password) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->_network = new \Oara\Network\Publisher\Effiliation; |
|
33
|
|
|
$this->_password = $password; |
|
34
|
|
|
$this->_apiClient = null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
public function checkLogin() : bool |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$credentials = array(); |
|
43
|
|
|
$credentials["apipassword"] = $this->_password; |
|
44
|
|
|
$this->_network->login($credentials); |
|
45
|
|
|
if ($this->_network->checkConnection()) { |
|
46
|
|
|
return true; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return array of Merchants |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getMerchants() : array |
|
56
|
|
|
{ |
|
57
|
|
|
$arrResult = array(); |
|
58
|
|
|
$url = 'http://api.effiliation.com/apiv2/programs.xml?key=' . $this->_password . "&filter=all"; |
|
59
|
|
|
$content = @\file_get_contents($url); |
|
60
|
|
|
$xml = \simplexml_load_string($content, null, LIBXML_NOERROR | LIBXML_NOWARNING); |
|
61
|
|
|
foreach ($xml->program as $merchant) { |
|
62
|
|
|
$Merchant = Merchant::createInstance(); |
|
63
|
|
|
$Merchant->merchant_ID = (string)$merchant->id_programme; |
|
|
|
|
|
|
64
|
|
|
$Merchant->name = (string)$merchant->nom; |
|
65
|
|
|
$arrResult[] = $Merchant; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $arrResult; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $merchantID |
|
73
|
|
|
* @return array of Deal |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getDeals(int $merchantID = 0) : array |
|
76
|
|
|
{ |
|
77
|
|
|
$url = 'http://apiv2.effiliation.com/apiv2/programs.json?filter=mines&key='.$this->_password; |
|
78
|
|
|
$json = file_get_contents($url); |
|
79
|
|
|
$arrResult = array(); |
|
80
|
|
|
$arrResponse = json_decode($json, true); |
|
81
|
|
|
if(!is_array($arrResponse) || count($arrResponse) <= 0) { |
|
82
|
|
|
return $arrResult; |
|
83
|
|
|
} |
|
84
|
|
|
$arrPrograms = $arrResponse['programs']; |
|
85
|
|
View Code Duplication |
foreach($arrPrograms as $item) { |
|
|
|
|
|
|
86
|
|
|
$Deal = Deal::createInstance(); |
|
87
|
|
|
$Deal->merchant_ID = $item['id_programme']; |
|
88
|
|
|
$Deal->code = $item['code']; |
|
89
|
|
|
$Deal->name = $item['nom']; |
|
90
|
|
|
$Deal->startDate = $item['date_debut']; |
|
91
|
|
|
$Deal->description = $item['description']; |
|
92
|
|
|
$Deal->url = $item['url_tracke']; |
|
93
|
|
|
if($merchantID > 0) { |
|
94
|
|
|
if($merchantID == $item['id_programme']) { |
|
95
|
|
|
$arrResult[] = $Deal; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
else { |
|
99
|
|
|
$arrResult[] = $Deal; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $arrResult; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param \DateTime $dateFrom |
|
108
|
|
|
* @param \DateTime $dateTo |
|
109
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
110
|
|
|
* @return array of Transaction |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
113
|
|
|
{ |
|
114
|
|
|
$arrResult = array(); |
|
115
|
|
|
$transcationList = $this->_network->getTransactionList($arrMerchantID, $dateTo, $dateFrom); |
|
116
|
|
|
foreach($transcationList as $transaction) { |
|
117
|
|
|
$Transaction = Transaction::createInstance(); |
|
118
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
|
119
|
|
|
$date = new \DateTime($transaction['date']); |
|
|
|
|
|
|
120
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
|
121
|
|
|
$Transaction->custom_ID = $transaction['custom_id']; |
|
122
|
|
|
$Transaction->status = $transaction['status']; |
|
123
|
|
|
$Transaction->amount = $transaction['amount']; |
|
124
|
|
|
$Transaction->commission = $transaction['commission']; |
|
125
|
|
|
$arrResult[] = $Transaction; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $arrResult; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param \DateTime $dateFrom |
|
133
|
|
|
* @param \DateTime $dateTo |
|
134
|
|
|
* @param int $merchantID |
|
135
|
|
|
* @return array of Stat |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
138
|
|
|
{ |
|
139
|
|
|
return array(); |
|
140
|
|
|
/* |
|
|
|
|
|
|
141
|
|
|
$this->_apiClient->setConnectId($this->_username); |
|
142
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
|
143
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
|
144
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
|
145
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
|
146
|
|
|
$arrResponse = json_decode($response, true); |
|
147
|
|
|
$reportItems = $arrResponse['reportItems']; |
|
148
|
|
|
$Stat = Stat::createInstance(); |
|
149
|
|
|
$Stat->reportItems = $reportItems; |
|
150
|
|
|
|
|
151
|
|
|
return array($Stat); |
|
152
|
|
|
*/ |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
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.