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
|
|
|
if (isset($merchantIdList[(int)$transactionExportArray[2]])) { |
41
|
|
|
|
42
|
|
|
$transaction = Array(); |
43
|
|
|
$merchantId = (int)$transactionExportArray[2]; |
44
|
|
|
$transaction['merchantId'] = $merchantId; |
45
|
|
|
$transaction['date'] = $transactionExportArray[10]; |
46
|
|
|
$transaction['unique_id'] = $transactionExportArray[0]; |
47
|
|
|
$transaction['custom_id'] = ''; |
48
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
49
|
|
|
if ($transactionExportArray[4] != null) { |
50
|
|
|
$transaction['custom_id'] = $transactionExportArray[4]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($transactionExportArray[9] == 'Valide') { |
54
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
55
|
|
View Code Duplication |
} else |
|
|
|
|
56
|
|
|
if ($transactionExportArray[9] == 'Attente') { |
57
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
58
|
|
|
} else |
59
|
|
|
if ($transactionExportArray[9] == 'Refusé') { |
60
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
61
|
|
|
} |
62
|
|
|
$transaction['amount'] = \Oara\Utilities::parseDouble($transactionExportArray[7]); |
63
|
|
|
$transaction['commission'] = \Oara\Utilities::parseDouble($transactionExportArray[8]); |
64
|
|
|
$totalTransactions[] = $transaction; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} catch (\Exception $e) { |
68
|
|
|
// Avoid lost of transactions if one date failed - <PN> - 2017-06-20 |
69
|
|
|
echo PHP_EOL."EffiliationEx - getTransactionList err: ".$e->getMessage().PHP_EOL; |
70
|
|
|
throw new \Exception($e); |
71
|
|
|
} |
72
|
|
|
echo (New \DateTime())->format("d/m/Y H:i:s") . " - EffiliationEx getTransactionList - return " . count($totalTransactions) . " transactions",PHP_EOL; |
73
|
|
|
return $totalTransactions; |
74
|
|
|
} |
75
|
|
|
} |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: