|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) Padosoft.com 2017. |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Padosoft\AffiliateNetwork; |
|
6
|
|
|
use Oara\Network\Publisher\Effiliation as EffiliationOara; |
|
7
|
|
|
|
|
8
|
|
|
class EffiliationEx extends EffiliationOara{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param null $merchantList |
|
11
|
|
|
* @param \DateTime|null $dStartDate |
|
12
|
|
|
* @param \DateTime|null $dEndDate |
|
13
|
|
|
* @return array |
|
14
|
|
|
*/ |
|
15
|
|
|
public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
|
16
|
|
|
{ |
|
17
|
|
|
try { |
|
18
|
|
|
|
|
19
|
|
|
$totalTransactions = array(); |
|
20
|
|
|
|
|
21
|
|
|
$merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
$url = 'http://api.effiliation.com/apiv2/transaction.csv?key=' . $this->_credentials["apiPassword"] . '&start=' . $dStartDate->format("d/m/Y") . '&end=' . $dEndDate->format("d/m/Y") . '&type=date&all=yes'; |
|
|
|
|
|
|
24
|
|
|
// Set timeout to 300 secs. due to api delays - <PN> 2017-06-20 |
|
25
|
|
|
$ctx = stream_context_create(array( |
|
26
|
|
|
'http' => array( |
|
27
|
|
|
'timeout' => 300 |
|
28
|
|
|
) |
|
29
|
|
|
) |
|
30
|
|
|
); |
|
31
|
|
|
// Log Debug info |
|
32
|
|
|
echo (New \DateTime())->format("d/m/Y H:i:s") . " - EffiliationEx getTransactionList from " . $dStartDate->format("d/m/Y") . " to " . $dEndDate->format("d/m/Y"),PHP_EOL; |
|
33
|
|
|
|
|
34
|
|
|
$content = \utf8_encode(\file_get_contents($url, 0, $ctx)); |
|
35
|
|
|
$exportData = \str_getcsv($content, "\n"); |
|
36
|
|
|
$num = \count($exportData); |
|
37
|
|
|
|
|
38
|
|
|
for ($i = 1; $i < $num; $i++) { |
|
39
|
|
|
$transactionExportArray = \str_getcsv($exportData[$i], "|"); |
|
40
|
|
|
// We don't need to check whether the merchant id is valid or not ... |
|
41
|
|
|
// ... for old transactions may be expired and not included in current merchant list |
|
42
|
|
|
// <PN> 2017-06-22 |
|
43
|
|
|
// if (isset($merchantIdList[(int)$transactionExportArray[2]])) { |
|
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
$transaction = Array(); |
|
46
|
|
|
$merchantId = (int)$transactionExportArray[2]; |
|
47
|
|
|
$transaction['merchantId'] = $merchantId; |
|
48
|
|
|
$transaction['date'] = $transactionExportArray[10]; |
|
49
|
|
|
$transaction['unique_id'] = $transactionExportArray[0]; |
|
50
|
|
|
$transaction['custom_id'] = ''; |
|
51
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
|
52
|
|
|
if ($transactionExportArray[4] != null) { |
|
53
|
|
|
$transaction['custom_id'] = $transactionExportArray[4]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
switch ($transactionExportArray[9]) { |
|
57
|
|
|
case 'Valide': |
|
58
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
|
59
|
|
|
break; |
|
60
|
|
|
case 'Attente': |
|
61
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
|
62
|
|
|
break; |
|
63
|
|
|
case 'Refusé': |
|
64
|
|
|
case 'Refuse': |
|
65
|
|
|
// Handle both variations - <PN> - 2017-06-21 |
|
66
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
|
67
|
|
|
break; |
|
68
|
|
|
default: |
|
69
|
|
|
// Invalid status |
|
70
|
|
|
echo PHP_EOL."EffiliationEx - Invalid transaction status: " . $transactionExportArray[9] . " (transaction id = " . $transactionExportArray[0] . ")"; |
|
71
|
|
|
break; |
|
72
|
|
|
} |
|
73
|
|
|
$transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[7]); |
|
74
|
|
|
$transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[8]); |
|
75
|
|
|
$totalTransactions[] = $transaction; |
|
76
|
|
|
// } |
|
77
|
|
|
} |
|
78
|
|
|
} catch (\Exception $e) { |
|
79
|
|
|
// Avoid lost of transactions if one date failed - <PN> - 2017-06-20 |
|
80
|
|
|
echo PHP_EOL."EffiliationEx - getTransactionList err: ".$e->getMessage().PHP_EOL; |
|
81
|
|
|
throw new \Exception($e); |
|
82
|
|
|
} |
|
83
|
|
|
echo (New \DateTime())->format("d/m/Y H:i:s") . " - EffiliationEx getTransactionList - return " . count($totalTransactions) . " transactions",PHP_EOL; |
|
84
|
|
|
return $totalTransactions; |
|
85
|
|
|
} |
|
86
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.