|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) Padosoft.com 2017. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
namespace Padosoft\AffiliateNetwork; |
|
8
|
|
|
use Oara\Network\Publisher\NetAffiliation as NetAffiliationOara; |
|
9
|
|
|
|
|
10
|
|
|
class NetAffiliationEx extends NetAffiliationOara |
|
11
|
|
|
{ |
|
12
|
|
|
protected $_serverNumber = 6; |
|
13
|
|
|
/** |
|
14
|
|
|
* Call protected/private method of a class. |
|
15
|
|
|
* |
|
16
|
|
|
* @param object &$object Instantiated object that we will run method on. |
|
17
|
|
|
* @param string $methodName Method name to call |
|
18
|
|
|
* @param array $parameters Array of parameters to pass into method. |
|
19
|
|
|
* |
|
20
|
|
|
* @return mixed Method return. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function invokeMethod(&$object,$methodName, array $parameters = array()) |
|
23
|
|
|
{ |
|
24
|
|
|
$reflection = new \ReflectionClass(get_class($object)); |
|
25
|
|
|
$method = $reflection->getMethod($methodName); |
|
26
|
|
|
$method->setAccessible(true); |
|
27
|
|
|
return $method->invokeArgs($object, $parameters); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Call protected/private property of a class. |
|
32
|
|
|
* @param $object |
|
33
|
|
|
* @param $propertyName |
|
34
|
|
|
* |
|
35
|
|
|
* @return mixed |
|
36
|
|
|
*/ |
|
37
|
|
View Code Duplication |
public function invokeProperty(&$object,$propertyName) |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
$reflection = new \ReflectionClass(get_class($object)); |
|
40
|
|
|
$property = $reflection->getProperty($propertyName); |
|
41
|
|
|
$property->setAccessible(true); |
|
42
|
|
|
return $property->getValue($object); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param $credentials |
|
47
|
|
|
* @throws \Exception |
|
48
|
|
|
* @throws \Oara\Curl\Exception |
|
49
|
|
|
*/ |
|
50
|
|
|
/*public function login($credentials){ |
|
|
|
|
|
|
51
|
|
|
$this->_credentials = $credentials; |
|
52
|
|
|
$this->_client = new \Oara\Curl\Access($credentials); |
|
53
|
|
|
|
|
54
|
|
|
}*/ |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
/*public function checkConnection() |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$connection = false; |
|
62
|
|
|
|
|
63
|
|
|
try{ |
|
64
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]); |
|
65
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apiPassword"]); |
|
66
|
|
|
$urls = array(); |
|
67
|
|
|
$urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport); |
|
68
|
|
|
|
|
69
|
|
|
$exportReport = $this->_client->get($urls); |
|
70
|
|
|
$exportData = str_getcsv($exportReport[0], "\n"); |
|
71
|
|
|
if (substr($exportData[0],0,2)=='OK'){ |
|
72
|
|
|
$connection=true; |
|
73
|
|
|
} |
|
74
|
|
|
}catch (\Exception $exception){ |
|
75
|
|
|
|
|
76
|
|
|
}finally{ |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
return $connection; |
|
82
|
|
|
}*/ |
|
83
|
|
|
/** |
|
84
|
|
|
* @param string $idSite |
|
85
|
|
|
*/ |
|
86
|
|
|
public function addAllowedSite(string $idSite){ |
|
87
|
|
|
$this->_sitesAllowed[]=$idSite; |
|
88
|
|
|
} |
|
89
|
|
|
/** |
|
90
|
|
|
* @param null $merchantList |
|
91
|
|
|
* @param \DateTime|null $dStartDate |
|
92
|
|
|
* @param \DateTime|null $dEndDate |
|
93
|
|
|
* @return array |
|
94
|
|
|
* @throws Exception |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
|
97
|
|
|
{ |
|
98
|
|
|
$totalTransactions = array(); |
|
99
|
|
|
$merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
|
100
|
|
|
|
|
101
|
|
|
$valuesFormExport = array(); |
|
102
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('authl', $this->_credentials["user"]); |
|
103
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('authv', $this->_credentials["apiPassword"]); |
|
104
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('champs', 'idprogramme,date,etat,argsite,montant,gains,monnaie,idsite,id'); |
|
105
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('debut', $dStartDate->format("Y-m-d")); |
|
|
|
|
|
|
106
|
|
|
$valuesFormExport[] = new \Oara\Curl\Parameter('fin', $dEndDate->format("Y-m-d")); |
|
|
|
|
|
|
107
|
|
|
$urls = array(); |
|
108
|
|
|
$urls[] = new \Oara\Curl\Request('https://stat.netaffiliation.com/requete.php?', $valuesFormExport); |
|
109
|
|
|
|
|
110
|
|
|
$exportReport = $this->_client->get($urls); |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
//sales |
|
115
|
|
|
$exportData = str_getcsv($exportReport[0], "\n"); |
|
116
|
|
|
$num = count($exportData); |
|
117
|
|
|
for ($i = 1; $i < $num; $i++) { |
|
118
|
|
|
$transactionExportArray = str_getcsv($exportData[$i], ";"); |
|
119
|
|
|
if (\count($this->_sitesAllowed) == 0 || \in_array($transactionExportArray[7], $this->_sitesAllowed)) { |
|
120
|
|
|
if (count($merchantIdList)<1 || isset($merchantIdList[$transactionExportArray[0]])) { |
|
121
|
|
|
$transaction = Array(); |
|
122
|
|
|
$transaction['merchantId'] = $transactionExportArray[0]; |
|
123
|
|
|
//$transactionDate = \DateTime::createFromFormat("d/m/Y H:i:s", $transactionExportArray[1]); |
|
|
|
|
|
|
124
|
|
|
$transaction['date'] = $transactionExportArray[1]; |
|
125
|
|
|
$transaction['title'] = ''; |
|
126
|
|
|
|
|
127
|
|
|
if ($transactionExportArray[3] != null) { |
|
128
|
|
|
$transaction['custom_id'] = $transactionExportArray[3]; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
if (\strstr($transactionExportArray[2], 'v')) { |
|
132
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
|
133
|
|
|
} else |
|
134
|
|
|
if (\strstr($transactionExportArray[2], 'r')) { |
|
135
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
|
136
|
|
|
} else if (\strstr($transactionExportArray[2], 'a')) { |
|
137
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
|
138
|
|
|
} else { |
|
139
|
|
|
throw new \Exception ("Status not found"); |
|
140
|
|
|
} |
|
141
|
|
|
$transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[4]); |
|
142
|
|
|
$transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[5]); |
|
143
|
|
|
|
|
144
|
|
|
$transaction['currency'] = $transactionExportArray[6]; |
|
145
|
|
|
$transaction['unique_id'] = $transactionExportArray[8]; |
|
146
|
|
|
$totalTransactions[] = $transaction; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
return $totalTransactions; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
} |
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.