|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
|
4
|
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
|
6
|
|
|
use Padosoft\AffiliateNetwork\Merchant; |
|
7
|
|
|
use Padosoft\AffiliateNetwork\Stat; |
|
8
|
|
|
use Padosoft\AffiliateNetwork\Deal; |
|
9
|
|
|
use Padosoft\AffiliateNetwork\AbstractNetwork; |
|
10
|
|
|
use Padosoft\AffiliateNetwork\NetworkInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class TradeDoubler |
|
14
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
15
|
|
|
*/ |
|
16
|
|
|
class TradeDoubler extends AbstractNetwork implements NetworkInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var object |
|
20
|
|
|
*/ |
|
21
|
|
|
private $_network = null; |
|
22
|
|
|
private $_apiClient = null; |
|
23
|
|
|
private $_username = ''; |
|
24
|
|
|
private $_password = ''; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @method __construct |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(string $username, string $password) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->_network = new \Oara\Network\Publisher\TradeDoubler; |
|
32
|
|
|
$this->_username = $username; |
|
33
|
|
|
$this->_password = $password; |
|
34
|
|
|
$this->_apiClient = null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
|
View Code Duplication |
public function checkLogin() : bool |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
$credentials = array(); |
|
43
|
|
|
$credentials["user"] = $this->_username; |
|
44
|
|
|
$credentials["password"] = $this->_password; |
|
45
|
|
|
$this->_network->login($credentials); |
|
46
|
|
|
if ($this->_network->checkConnection()) { |
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return false; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return array of Merchants |
|
55
|
|
|
*/ |
|
56
|
|
View Code Duplication |
public function getMerchants() : array |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
$arrResult = array(); |
|
59
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
60
|
|
|
foreach($merchantList as $merchant) { |
|
61
|
|
|
$Merchant = Merchant::createInstance(); |
|
62
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
|
63
|
|
|
$Merchant->name = $merchant['name']; |
|
64
|
|
|
$arrResult[] = $Merchant; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $arrResult; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param int $merchantID |
|
72
|
|
|
* @return array of Deal |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getDeals(int $merchantID = 0) : array |
|
75
|
|
|
{ |
|
76
|
|
|
$arrResult = array(); |
|
77
|
|
|
$jsonVouchers = file_get_contents("https://api.tradedoubler.com/1.0/vouchers.json;voucherTypeId=1?token=".$_ENV['TRADEDOUBLER_TOKEN']); |
|
78
|
|
|
$arrVouchers = json_decode($jsonVouchers, true); |
|
79
|
|
|
|
|
80
|
|
|
foreach($arrVouchers as $vouchers) { |
|
81
|
|
|
$Deal = Deal::createInstance(); |
|
82
|
|
|
$Deal->deal_ID = $vouchers['id']; |
|
83
|
|
|
$Deal->merchant_ID = $vouchers['programId']; |
|
84
|
|
|
$Deal->merchant_name = $vouchers['programName']; |
|
85
|
|
|
$Deal->code = $vouchers['code']; |
|
86
|
|
|
$Deal->name = $vouchers['title']; |
|
87
|
|
|
$Deal->short_description = $vouchers['shortDescription']; |
|
88
|
|
|
$Deal->description = $vouchers['description']; |
|
89
|
|
|
$Deal->deal_type = $vouchers['voucherTypeId']; |
|
90
|
|
|
$Deal->default_track_uri = $vouchers['defaultTrackUri']; |
|
91
|
|
|
$Deal->default_track_uri = $vouchers['landingUrl']; |
|
92
|
|
|
$Deal->discount_amount = $vouchers['discountAmount']; |
|
93
|
|
|
$Deal->is_percentage = $vouchers['isPercentage']; |
|
94
|
|
|
$Deal->currency_initial = $vouchers['currencyId']; |
|
95
|
|
|
$Deal->logo_path = $vouchers['logoPath']; |
|
96
|
|
|
if($merchantID > 0) { |
|
97
|
|
|
if($vouchers['programId'] == $merchantID) { |
|
98
|
|
|
$arrResult[] = $Deal; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
else { |
|
102
|
|
|
$arrResult[] = $Deal; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $arrResult; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param \DateTime $dateFrom |
|
111
|
|
|
* @param \DateTime $dateTo |
|
112
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
113
|
|
|
* @return array of Transaction |
|
114
|
|
|
*/ |
|
115
|
|
View Code Duplication |
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchant = array()) : array |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
$arrResult = array(); |
|
118
|
|
|
$transcationList = $this->_network->getTransactionList($arrMerchant, $dateFrom, $dateTo); |
|
119
|
|
|
foreach($transcationList as $transaction) { |
|
120
|
|
|
$Transaction = Transaction::createInstance(); |
|
121
|
|
|
$Transaction->merchant_ID = $transaction['merchantId']; |
|
122
|
|
|
$date = new \DateTime($transaction['date']); |
|
123
|
|
|
$Transaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
124
|
|
|
$Transaction->unique_ID = $transaction['unique_id']; |
|
125
|
|
|
$Transaction->custom_ID = $transaction['custom_id']; |
|
126
|
|
|
$Transaction->status = $transaction['status']; |
|
127
|
|
|
$Transaction->amount = $transaction['amount']; |
|
128
|
|
|
$Transaction->commission = $transaction['commission']; |
|
129
|
|
|
$arrResult[] = $Transaction; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return $arrResult; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param \DateTime $dateFrom |
|
137
|
|
|
* @param \DateTime $dateTo |
|
138
|
|
|
* @param int $merchantID |
|
139
|
|
|
* @return array of Stat |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
142
|
|
|
{ |
|
143
|
|
|
return array(); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
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.