|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
|
4
|
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\Deal; |
|
6
|
|
|
use Padosoft\AffiliateNetwork\Stat; |
|
7
|
|
|
use Padosoft\AffiliateNetwork\Merchant; |
|
8
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
|
9
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
|
10
|
|
|
use Padosoft\AffiliateNetwork\AbstractNetwork; |
|
11
|
|
|
use Padosoft\AffiliateNetwork\NetworkInterface; |
|
12
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Belboon |
|
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
|
17
|
|
|
*/ |
|
18
|
|
|
class Belboon extends AbstractNetwork implements NetworkInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var object |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_network = null; |
|
24
|
|
|
protected $_tracking_parameter = 'scm1'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @method __construct |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(string $username, string $password, string $idSite='') |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$apiKey = $_ENV["BELBOON_API_KEY"]; |
|
32
|
|
|
$userId = $_ENV["BELBOON_USER_ID"]; |
|
33
|
|
|
$this->_network = new \Oara\Network\Publisher\Belboon($apiKey, $userId); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return bool |
|
38
|
|
|
*/ |
|
39
|
|
|
public function checkLogin() : bool |
|
40
|
|
|
{ |
|
41
|
|
|
return true; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return array of Merchants |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public function getMerchants() : array |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
if (!$this->checkLogin()) { |
|
50
|
|
|
return array(); |
|
51
|
|
|
} |
|
52
|
|
|
$arrResult = array(); |
|
53
|
|
|
$merchantList = $this->_network->getMerchantList(); |
|
54
|
|
|
foreach ($merchantList as $merchant) { |
|
55
|
|
|
$Merchant = Merchant::createInstance(); |
|
56
|
|
|
$Merchant->merchant_ID = $merchant['cid']; |
|
57
|
|
|
$Merchant->name = $merchant['name']; |
|
58
|
|
|
$arrResult[] = $Merchant; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $arrResult; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param int $merchantID |
|
66
|
|
|
* @return array of Deal |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getDeals($merchantID=null, int $page=0, int $items_per_page=10): DealsResultset |
|
69
|
|
|
{ |
|
70
|
|
|
$dealList = $this->_network->getVouchers(); |
|
71
|
|
|
|
|
72
|
|
|
// only the type voucher is imported |
|
73
|
|
|
// possible types: |
|
74
|
|
|
// discount_all, discount_single, free_ship, freebie, misc, '' |
|
75
|
|
|
$onlyVouchersDeals = array_filter( |
|
76
|
|
|
$dealList, |
|
77
|
|
|
function ($deal) { |
|
78
|
|
|
// the deal types can be multiple... |
|
79
|
|
|
$dealTypes = $deal["voucher_type"]; |
|
80
|
|
|
$isDiscountAll = strpos($dealTypes, 'discount_all') != false; |
|
|
|
|
|
|
81
|
|
|
$isDiscountSingle = strpos($dealTypes, 'discount_single') != false; |
|
|
|
|
|
|
82
|
|
|
$isEmpty = $dealTypes == ''; |
|
83
|
|
|
|
|
84
|
|
|
return $isDiscountAll || $isDiscountSingle || $isEmpty; |
|
85
|
|
|
} |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$result = DealsResultset::createInstance(); |
|
89
|
|
|
|
|
90
|
|
|
$deals = array_map(function ($rawDeal) { |
|
91
|
|
|
$deal = new Deal(); |
|
92
|
|
|
$deal->deal_ID = $rawDeal["vcid"]; |
|
93
|
|
|
$deal->merchant_ID = $rawDeal["mid"]; |
|
94
|
|
|
$deal->code = $rawDeal["codes"]; |
|
95
|
|
|
$deal->description = $rawDeal["description"]; |
|
96
|
|
|
$deal->start_date = $deal->convertDate($rawDeal["date_from"]); |
|
|
|
|
|
|
97
|
|
|
$deal->end_date = $deal->convertDate($rawDeal["date_to"]); |
|
|
|
|
|
|
98
|
|
|
$deal->landing_url = $rawDeal["landingpage"]; |
|
99
|
|
|
$deal->discount_amount = $rawDeal["discount_amount"]; |
|
100
|
|
|
$deal->minimum_order_value = $rawDeal["min_order_value"]; |
|
101
|
|
|
$deal->deal_type = \Oara\Utilities::OFFER_TYPE_VOUCHER; |
|
102
|
|
|
return $deal; |
|
103
|
|
|
}, $onlyVouchersDeals); |
|
104
|
|
|
|
|
105
|
|
|
$result->deals[] = $deals; |
|
106
|
|
|
|
|
107
|
|
|
return $result; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param \DateTime $dateFrom |
|
112
|
|
|
* @param \DateTime $dateTo |
|
113
|
|
|
* @param int $merchantID |
|
|
|
|
|
|
114
|
|
|
* @return array of Transaction |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
|
117
|
|
|
{ |
|
118
|
|
|
$arrResult = array(); |
|
119
|
|
|
try { |
|
120
|
|
|
$transactionList = $this->_network->getTransactionList(null, $dateFrom, $dateTo); |
|
121
|
|
|
|
|
122
|
|
|
foreach ($transactionList as $transaction) { |
|
123
|
|
|
$myTransaction = Transaction::createInstance(); |
|
124
|
|
|
try { |
|
125
|
|
|
$myTransaction->merchant_ID = $transaction['merchantId']; |
|
126
|
|
|
$myTransaction->title =''; |
|
127
|
|
|
$myTransaction->currency ='EUR'; |
|
128
|
|
|
if (!empty($transaction['date'])) { |
|
129
|
|
|
$date = new \DateTime($transaction['date']); |
|
130
|
|
|
$myTransaction->date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
if (!empty($transaction['click_date'])) { |
|
133
|
|
|
$date = new \DateTime($transaction['click_date']); |
|
134
|
|
|
$myTransaction->click_date = $date; // $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
if (!empty($transaction['lastchangedate'])) { |
|
137
|
|
|
$date = new \DateTime($transaction['lastchangedate']); |
|
138
|
|
|
$myTransaction->update_date = $date; |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
$myTransaction->unique_ID = $transaction['unique_id']; |
|
141
|
|
|
$myTransaction->custom_ID = array_key_exists('custom_id', $transaction) ? $transaction['custom_id'] : ''; |
|
142
|
|
|
$myTransaction->status = $transaction['status']; |
|
143
|
|
|
$myTransaction->amount = $transaction['amount']; |
|
144
|
|
|
$myTransaction->commission = $transaction['commission']; |
|
145
|
|
|
|
|
146
|
|
|
$myTransaction->approved = false; |
|
147
|
|
|
if ($transaction['status'] == \Oara\Utilities::STATUS_CONFIRMED) { |
|
148
|
|
|
$myTransaction->approved = true; |
|
149
|
|
|
} |
|
150
|
|
|
$arrResult[] = $myTransaction; |
|
151
|
|
|
} catch (\Exception $e) { |
|
152
|
|
|
echo "<br><br>errore transazione Belboon, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; |
|
153
|
|
|
var_dump($e->getTraceAsString()); |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
} catch (\Exception $e) { |
|
157
|
|
|
echo "<br><br>errore generico transazione Belboon: ".$e->getMessage()."<br><br>"; |
|
158
|
|
|
var_dump($e->getTraceAsString()); |
|
159
|
|
|
throw new \Exception($e); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $arrResult; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param \DateTime $dateFrom |
|
167
|
|
|
* @param \DateTime $dateTo |
|
168
|
|
|
* @param int $merchantID |
|
169
|
|
|
* @return array of Stat |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
|
172
|
|
|
{ |
|
173
|
|
|
return array(); |
|
174
|
|
|
/* |
|
175
|
|
|
$this->_apiClient->setConnectId($this->_username); |
|
176
|
|
|
$this->_apiClient->setSecretKey($this->_password); |
|
177
|
|
|
$dateFromIsoEngFormat = $dateFrom->format('Y-m-d'); |
|
178
|
|
|
$dateToIsoEngFormat = $dateTo->format('Y-m-d'); |
|
179
|
|
|
$response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat); |
|
180
|
|
|
$arrResponse = json_decode($response, true); |
|
181
|
|
|
$reportItems = $arrResponse['reportItems']; |
|
182
|
|
|
$Stat = Stat::createInstance(); |
|
183
|
|
|
$Stat->reportItems = $reportItems; |
|
184
|
|
|
|
|
185
|
|
|
return array($Stat); |
|
186
|
|
|
*/ |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @param array $params |
|
192
|
|
|
* |
|
193
|
|
|
* @return ProductsResultset |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getProducts(array $params = []): ProductsResultset |
|
196
|
|
|
{ |
|
197
|
|
|
// TODO: Implement getProducts() method. |
|
198
|
|
|
throw new \Exception("Not implemented yet"); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function getTrackingParameter() |
|
202
|
|
|
{ |
|
203
|
|
|
return $this->_tracking_parameter; |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.