Code Duplication    Length = 161-175 lines in 2 locations

src/Networks/Digidip.php 1 location

@@ 18-192 (lines=175) @@
15
 * Class Digidip
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class Digidip extends AbstractNetwork implements NetworkInterface
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_username = '';
25
    private $_password = '';
26
    private $_apiClient = null;
27
    protected $_tracking_parameter    = '';
28
    private $_idSite = '';
29
30
    /**
31
     * @method __construct
32
     */
33
    public function __construct(string $username, string $password, string $idSite = '')
34
    {
35
        $this->_network = new \Oara\Network\Publisher\Digidip;
36
        $this->_username = $username;
37
        $this->_password = $password;
38
        $this->_idSite = $idSite;
39
40
        $this->login( $this->_username, $this->_password, $this->_idSite );
41
    }
42
43
    public function login(string $username, string $password, string $idSite = ''): bool{
44
        $this->_logged = false;
45
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
46
47
            return false;
48
        }
49
        $this->_username = $username;
50
        $this->_password = $password;
51
        $this->_idSite = $idSite;
52
        $credentials = array();
53
        $credentials["user"] = $this->_username;
54
        $credentials["password"] = $this->_password;
55
        $credentials["idSite"] = $this->_idSite;
56
        $this->_network->login($credentials);
57
        if ($this->_network->checkConnection()) {
58
            $this->_logged = true;
59
        }
60
61
        return $this->_logged;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function checkLogin() : bool
68
    {
69
        return $this->_logged;
70
    }
71
72
    /**
73
	 * @return array of Merchants
74
	 * @throws \Exception
75
	 */
76
    public function getMerchants() : array
77
    {
78
	    throw new \Exception("Not implemented yet");
79
    }
80
81
    /**
82
	 * @param null $merchantID
83
	 * @param int $page
84
	 * @param int $items_per_page
85
	 * @return DealsResultset  array of Deal
86
	 * @throws \Exception
87
	 */
88
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=100 ): DealsResultset
89
    {
90
	    throw new \Exception("Not implemented yet");
91
92
    }
93
94
   	/**
95
	 * @param \DateTime $dateFrom
96
	 * @param \DateTime $dateTo
97
	 * @param array $arrMerchantID
98
	 * @return array of Transaction
99
	 * @throws \Exception
100
	 */
101
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
102
    {
103
	    $arrResult = array();
104
        try{
105
	        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
106
	        foreach($transactionList as $transaction) {
107
		        $Transaction = Transaction::createInstance();
108
		        if (isset($transaction['currency']) && !empty($transaction['currency'])) {
109
			        $Transaction->currency = $transaction['currency'];
110
		        } else {
111
			        $Transaction->currency = "EUR";
112
		        }
113
		        $Transaction->status = $transaction['status'];
114
		        $Transaction->amount = $transaction['amount'];
115
		        array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
116
		        $Transaction->title = '';
117
		        $Transaction->unique_ID = $transaction['unique_id'];
118
		        $Transaction->commission = $transaction['commission'];
119
		        $date = new \DateTime($transaction['date']);
120
		        $Transaction->date = $date;
121
		        // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
122
		        if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
123
			        $Transaction->click_date = new \DateTime($transaction['click_date']);
124
		        }
125
		        if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
126
			        $Transaction->update_date = new \DateTime($transaction['update_date']);
127
		        }
128
		        $Transaction->merchant_ID = $transaction['merchantId'];
129
		        $Transaction->campaign_name =  $transaction['merchantName'];
130
		        $Transaction->IP =  $transaction['IP'];
131
		        $Transaction->approved = false;
132
		        if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED){
133
			        $Transaction->approved = true;
134
		        }
135
		        $arrResult[] = $Transaction;
136
	        }
137
138
        }
139
        catch (\Exception $e){
140
	        echo "[Digidip][Error] " . $e->getMessage() . PHP_EOL;
141
	        var_dump($e->getTraceAsString());
142
	        throw new \Exception($e);
143
        }
144
145
	    return $arrResult;
146
147
    }
148
149
    /**
150
     * @param \DateTime $dateFrom
151
     * @param \DateTime $dateTo
152
     * @param int $merchantID
153
     * @return array of Stat
154
     */
155
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
156
    {
157
        // TODO
158
        return array();
159
        /*
160
        $this->_apiClient->setConnectId($this->_username);
161
        $this->_apiClient->setSecretKey($this->_password);
162
        $dateFromIsoEngFormat = $dateFrom->format('Y-m-d');
163
        $dateToIsoEngFormat = $dateTo->format('Y-m-d');
164
        $response = $this->_apiClient->getReportBasic($dateFromIsoEngFormat, $dateToIsoEngFormat);
165
        $arrResponse = json_decode($response, true);
166
        $reportItems = $arrResponse['reportItems'];
167
        $Stat = Stat::createInstance();
168
        $Stat->reportItems = $reportItems;
169
170
        return array($Stat);
171
        */
172
    }
173
174
175
    /**
176
	 * @param array $params
177
	 * @return ProductsResultset
178
	 * @throws \Exception
179
	 */
180
    public function getProducts(array $params = []): ProductsResultset
181
    {
182
        // TODO: Implement getProducts() method.
183
        throw new \Exception("Not implemented yet");
184
    }
185
186
    public function getTrackingParameter(){
187
        return $this->_tracking_parameter;
188
    }
189
190
191
192
}

src/Networks/VerticalAds.php 1 location

@@ 18-178 (lines=161) @@
15
 * Class VerticalAds
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class VerticalAds extends AbstractNetwork implements NetworkInterface
19
{
20
    /**
21
     * @var object
22
     */
23
    private $_network = null;
24
    private $_username = '';
25
    private $_password = '';
26
    protected $_tracking_parameter = 'subid';
27
    private $_idSite = '';
28
29
    /**
30
     * @method __construct
31
     */
32
    public function __construct(string $username, string $password, string $idSite = '')
33
    {
34
        $this->_network = new \Oara\Network\Publisher\VerticalAds;
35
        $this->_username = $username;
36
        $this->_password = $password;
37
        $this->_idSite = $idSite;
38
39
        $this->login($this->_username, $this->_password, $this->_idSite);
40
    }
41
42
    public function login(string $username, string $password, string $idSite = ''): bool
43
    {
44
        $this->_logged = false;
45
        if (isNullOrEmpty($username) || isNullOrEmpty($password)) {
46
47
            return false;
48
        }
49
        $this->_username = $username;
50
        $this->_password = $password;
51
        $this->_idSite = $idSite;
52
        $credentials = array();
53
        $credentials["user"] = $this->_username;
54
        $credentials["password"] = $this->_password;
55
        $credentials["idSite"] = $this->_idSite;
56
        $this->_network->login($credentials);
57
        if ($this->_network->checkConnection()) {
58
            $this->_logged = true;
59
        }
60
61
        return $this->_logged;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function checkLogin(): bool
68
    {
69
        return $this->_logged;
70
    }
71
72
    /**
73
     * @return array of Merchants
74
     * @throws \Exception
75
     */
76
    public function getMerchants(): array
77
    {
78
        throw new \Exception("Not implemented yet");
79
    }
80
81
    /**
82
     * @param null $merchantID
83
     * @param int $page
84
     * @param int $items_per_page
85
     * @return DealsResultset  array of Deal
86
     * @throws \Exception
87
     */
88
    public function getDeals($merchantID = NULL, int $page = 0, int $items_per_page = 100): DealsResultset
89
    {
90
        throw new \Exception("Not implemented yet");
91
92
    }
93
94
    /**
95
     * @param \DateTime $dateFrom
96
     * @param \DateTime $dateTo
97
     * @param array $arrMerchantID
98
     * @return array of Transaction
99
     * @throws \Exception
100
     */
101
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()): array
102
    {
103
        $arrResult = array();
104
        try {
105
            $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
106
            foreach ($transactionList as $transaction) {
107
                $Transaction = Transaction::createInstance();
108
                if (isset($transaction['currency']) && !empty($transaction['currency'])) {
109
                    $Transaction->currency = $transaction['currency'];
110
                } else {
111
                    $Transaction->currency = "EUR";
112
                }
113
                $Transaction->status = $transaction['status'];
114
                $Transaction->action = $transaction['action'];
115
                $Transaction->amount = $transaction['amount'];
116
                array_key_exists_safe($transaction, 'custom_id') ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
117
                $Transaction->title = $transaction['title'];
118
                $Transaction->unique_ID = $transaction['unique_id'];
119
                $Transaction->commission = $transaction['commission'];
120
                $date = new \DateTime($transaction['date']);
121
                $Transaction->date = $date;
122
                // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
123
                if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
124
                    $Transaction->click_date = new \DateTime($transaction['click_date']);
125
                }
126
                if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
127
                    $Transaction->update_date = new \DateTime($transaction['update_date']);
128
                }
129
                $Transaction->merchant_ID = $transaction['merchantId'];
130
                $Transaction->campaign_name = $transaction['merchantName'];
131
                $Transaction->approved = false;
132
                if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED) {
133
                    $Transaction->approved = true;
134
                }
135
                $arrResult[] = $Transaction;
136
            }
137
138
        } catch (\Exception $e) {
139
            echo "[VerticalAds][getSales][Exception] " . $e->getMessage() . PHP_EOL;
140
            var_dump($e->getTraceAsString());
141
            throw new \Exception($e);
142
        }
143
144
        return $arrResult;
145
146
    }
147
148
    /**
149
     * @param \DateTime $dateFrom
150
     * @param \DateTime $dateTo
151
     * @param int $merchantID
152
     * @return array of Stat
153
     */
154
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0): array
155
    {
156
        // TODO
157
        return array();
158
    }
159
160
161
    /**
162
     * @param array $params
163
     * @return ProductsResultset
164
     * @throws \Exception
165
     */
166
    public function getProducts(array $params = []): ProductsResultset
167
    {
168
        // TODO: Implement getProducts() method.
169
        throw new \Exception("Not implemented yet");
170
    }
171
172
    public function getTrackingParameter()
173
    {
174
        return $this->_tracking_parameter;
175
    }
176
177
178
}
179