|
1
|
|
|
<?php |
|
2
|
|
|
namespace Padosoft\AffiliateNetwork; |
|
3
|
|
|
|
|
4
|
|
|
use Oara\Network\Publisher\AffiliNet as AffilinetOara; |
|
5
|
|
|
|
|
6
|
|
|
class AffilinetEx extends AffilinetOara |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* @param null $merchantList |
|
10
|
|
|
* @param \DateTime|null $dStartDate |
|
11
|
|
|
* @param \DateTime|null $dEndDate |
|
12
|
|
|
* @return array |
|
13
|
|
|
* @throws Exception |
|
14
|
|
|
*/ |
|
15
|
|
|
public function getTransactionList($merchantList = null, \DateTime $dStartDate = null, \DateTime $dEndDate = null) |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
$totalTransactions = array(); |
|
18
|
|
|
|
|
19
|
|
|
// Don't need merchant list here |
|
20
|
|
|
// $merchantIdList = \Oara\Utilities::getMerchantIdMapFromMerchantList($merchantList); |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
if (isset($_ENV['AFFILINET_CURRENCY'])) { |
|
24
|
|
|
// 2018-04-16 - <PN> |
|
25
|
|
|
$currency = $_ENV['AFFILINET_CURRENCY']; |
|
26
|
|
|
} |
|
27
|
|
|
else { |
|
28
|
|
|
$currency = 'EUR'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$step = 0; |
|
32
|
|
|
|
|
33
|
|
|
try { |
|
34
|
|
|
$publisherStatisticsServiceUrl = 'https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl'; |
|
35
|
|
|
$publisherStatisticsService = new \SoapClient($publisherStatisticsServiceUrl, array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE, 'soap_version' => SOAP_1_1)); |
|
36
|
|
|
|
|
37
|
|
|
// Handle two steps: 1^ to get registered transactions / 2^ to get confirmed or cancelled transactions - <PN> 2017-06-27 |
|
38
|
|
|
while ($step++ <= 2) { |
|
39
|
|
|
$params = array( |
|
40
|
|
|
'StartDate' => \strtotime($dStartDate->format("Y-m-d")), |
|
|
|
|
|
|
41
|
|
|
'EndDate' => \strtotime($dEndDate->format("Y-m-d")), |
|
|
|
|
|
|
42
|
|
|
'TransactionStatus' => 'All', |
|
43
|
|
|
'ValuationType' => $step == 1 ? 'DateOfRegistration' : 'DateOfConfirmation' |
|
44
|
|
|
); |
|
45
|
|
|
$currentPage = 1; |
|
46
|
|
|
$transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); |
|
47
|
|
|
|
|
48
|
|
|
while (isset($transactionList->TotalRecords) && $transactionList->TotalRecords > 0 && isset($transactionList->TransactionCollection->Transaction)) { |
|
49
|
|
|
$transactionCollection = array(); |
|
50
|
|
|
if (!\is_array($transactionList->TransactionCollection->Transaction)) { |
|
51
|
|
|
$transactionCollection[] = $transactionList->TransactionCollection->Transaction; |
|
52
|
|
|
} else { |
|
53
|
|
|
$transactionCollection = $transactionList->TransactionCollection->Transaction; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
foreach ($transactionCollection as $transactionObject) { |
|
57
|
|
|
|
|
58
|
|
|
$transaction = array(); |
|
59
|
|
|
$transaction["status"] = $transactionObject->TransactionStatus; |
|
60
|
|
|
$transaction["unique_id"] = $transactionObject->TransactionId; |
|
61
|
|
|
$transaction["commission"] = $transactionObject->PublisherCommission; |
|
62
|
|
|
$transaction["currency"] = $currency; // 2018-04-16 - <PN> |
|
63
|
|
|
$transaction["amount"] = $transactionObject->NetPrice; |
|
64
|
|
|
$transaction["date"] = $transactionObject->RegistrationDate; |
|
65
|
|
|
$transaction["click_date"] = $transactionObject->ClickDate; // Future use - <PN> |
|
66
|
|
|
$transaction["udpate_date"] = $transactionObject->CheckDate; // Future use - <PN> |
|
67
|
|
|
$transaction["merchantId"] = $transactionObject->ProgramId; |
|
68
|
|
|
$transaction["custom_id"] = $transactionObject->SubId; |
|
69
|
|
View Code Duplication |
if ($transaction['status'] == 'Confirmed') { |
|
|
|
|
|
|
70
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_CONFIRMED; |
|
71
|
|
|
} else |
|
72
|
|
|
if ($transaction['status'] == 'Open') { |
|
73
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_PENDING; |
|
74
|
|
|
} else |
|
75
|
|
|
if ($transaction['status'] == 'Cancelled') { |
|
76
|
|
|
$transaction['status'] = \Oara\Utilities::STATUS_DECLINED; |
|
77
|
|
|
} |
|
78
|
|
|
$totalTransactions[] = $transaction; |
|
79
|
|
|
} |
|
80
|
|
|
$currentPage++; |
|
81
|
|
|
$transactionList = self::affilinetCall('transaction', $publisherStatisticsService, $params, 0, $currentPage); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} catch (\Exception $e) { |
|
85
|
|
|
// Avoid lost of transactions if one call failed |
|
86
|
|
|
echo PHP_EOL . "AffilinetEx - getTransactionList err: ".$e->getMessage().PHP_EOL; |
|
87
|
|
|
throw new \Exception($e); |
|
88
|
|
|
} |
|
89
|
|
|
echo (New \DateTime())->format("d/m/Y H:i:s") . " - AffilinetEx getTransactionList - return " . count($totalTransactions) . " transactions" . PHP_EOL; |
|
90
|
|
|
return $totalTransactions; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: