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