1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Padosoft\AffiliateNetwork\Networks; |
4
|
|
|
|
5
|
|
|
use Padosoft\AffiliateNetwork\Transaction; |
6
|
|
|
use Padosoft\AffiliateNetwork\DealsResultset; |
7
|
|
|
use Padosoft\AffiliateNetwork\Merchant; |
8
|
|
|
use Padosoft\AffiliateNetwork\Stat; |
9
|
|
|
use Padosoft\AffiliateNetwork\Deal; |
10
|
|
|
use Padosoft\AffiliateNetwork\AbstractNetwork; |
11
|
|
|
use Padosoft\AffiliateNetwork\NetworkInterface; |
12
|
|
|
use Padosoft\AffiliateNetwork\ProductsResultset; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PepperJamApi |
16
|
|
|
* @package Padosoft\AffiliateNetwork\Networks |
17
|
|
|
*/ |
18
|
|
|
class PepperJamApi extends AbstractNetwork implements NetworkInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var object |
22
|
|
|
*/ |
23
|
|
|
private $_network = null; |
24
|
|
|
protected $_tracking_parameter = 'sid'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @method __construct |
28
|
|
|
*/ |
29
|
|
|
public function __construct(string $username, string $password) |
30
|
|
|
{ |
31
|
|
|
$apiKey = $_ENV["PEPPER_JAM_API_KEY"]; |
32
|
|
|
$this->_network = new \Oara\Network\Publisher\PepperJamApi($apiKey); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function checkLogin() |
36
|
|
|
{ |
37
|
|
|
return true; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array of Merchants |
42
|
|
|
* @throws \Exception |
43
|
|
|
*/ |
44
|
|
|
public function getMerchants() : array |
45
|
|
|
{ |
46
|
|
|
return array_map(function ($rawMerchant) { |
47
|
|
|
$merchant = new Merchant(); |
48
|
|
|
$merchant->merchant_ID = $rawMerchant['cid']; |
49
|
|
|
$merchant->name = $rawMerchant['name']; |
50
|
|
|
$merchant->status = $rawMerchant['status']; |
51
|
|
|
$merchant->url = $rawMerchant['url']; |
52
|
|
|
if (!empty($rawMerchant['application_date'])) { |
53
|
|
|
$merchant->application_date = new \DateTime($rawMerchant['application_date']); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
return $merchant; |
56
|
|
|
}, $this->_network->getMerchantList()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param null $merchantID |
61
|
|
|
* @param int $page |
62
|
|
|
* @param int $items_per_page |
63
|
|
|
* @return DealsResultset array of Deal |
64
|
|
|
* @throws \Exception |
65
|
|
|
*/ |
66
|
|
|
public function getDeals($merchantID = null, int $page = 0, int $items_per_page = 100): DealsResultset |
67
|
|
|
{ |
68
|
|
|
throw new \Exception("Not implemented yet"); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param \DateTime $dateFrom |
73
|
|
|
* @param \DateTime $dateTo |
74
|
|
|
* @param array $arrMerchantID |
75
|
|
|
* @return array of Transaction |
76
|
|
|
* @throws \Exception |
77
|
|
|
*/ |
78
|
|
|
public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
79
|
|
|
{ |
80
|
|
|
return array_map(function ($rawTransaction) { |
81
|
|
|
$transaction = new Transaction(); |
82
|
|
|
$transaction->status = $rawTransaction['status']; |
83
|
|
|
$transaction->unique_ID = $rawTransaction['unique_id']; |
84
|
|
|
$transaction->commission = $rawTransaction['commission']; |
85
|
|
|
$transaction->amount = $rawTransaction['amount']; |
86
|
|
|
$transaction->date = new \DateTime($rawTransaction['date']); |
|
|
|
|
87
|
|
|
$transaction->merchant_ID = $rawTransaction['program_id']; |
88
|
|
|
$transaction->campaign_name = $rawTransaction['program_name']; |
89
|
|
|
$transaction->custom_ID = $rawTransaction['custom_id']; |
90
|
|
|
|
91
|
|
|
$transaction->approved = false; |
92
|
|
|
if ($transaction->status == \Oara\Utilities::STATUS_CONFIRMED) { |
93
|
|
|
$transaction->approved = true; |
94
|
|
|
} |
95
|
|
|
return $transaction; |
96
|
|
|
}, $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo)); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param \DateTime $dateFrom |
101
|
|
|
* @param \DateTime $dateTo |
102
|
|
|
* @param int $merchantID |
103
|
|
|
* @return array of Stat |
104
|
|
|
*/ |
105
|
|
|
public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
106
|
|
|
{ |
107
|
|
|
throw new \Exception("Not implemented yet"); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $params |
113
|
|
|
* @return ProductsResultset |
114
|
|
|
* @throws \Exception |
115
|
|
|
*/ |
116
|
|
|
public function getProducts(array $params = []): ProductsResultset |
117
|
|
|
{ |
118
|
|
|
throw new \Exception("Not implemented yet"); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getTrackingParameter() |
122
|
|
|
{ |
123
|
|
|
return $this->_tracking_parameter; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..