Completed
Push — master ( 5ef326...671329 )
by
unknown
02:55
created

ShareASale::getMerchants()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 ShareASale
16
 * @package Padosoft\AffiliateNetwork\Networks
17
 */
18
class ShareASale 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 = 'afftrack';
28
    private $_idSite = '';
29
30
    /**
31
     * @method __construct
32
     */
33 View Code Duplication
    public function __construct(string $username, string $password, string $idSite='')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
34
    {
35
        $this->_network = new \Oara\Network\Publisher\ShareASale;
36
        $this->_username = $username;
37
        $this->_password = $password;
38
        $this->_idSite = $idSite;
39
40
        $this->login( $this->_username, $this->_password, $idSite );
41
    }
42
43 View Code Duplication
    public function login(string $username, string $password,string $idSite=''): bool{
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
44
45
    	$this->_logged = false;
0 ignored issues
show
Bug introduced by
The property _logged does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
        if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) {
47
48
            return false;
49
        }
50
        $this->_username = $username;
51
        $this->_password = $password;
52
        $this->_idSite = $idSite;
53
        $credentials = array();
54
        $credentials["apiToken"] = $this->_username;
55
        $credentials["apiSecret"] = $this->_password;
56
        $credentials["affiliateId"] = $this->_idSite;
57
        $this->_network->login($credentials);
58
59
	    if ($this->_network->checkConnection()) {
60
            $this->_logged = true;
61
        }
62
63
        return $this->_logged;
64
    }
65
66
    /**
67
     * @return bool
68
     */
69
    public function checkLogin() : bool
70
    {
71
        return $this->_logged;
72
    }
73
74
    /**
75
	 * @return array of Merchants
76
	 * @throws \Exception
77
	 */
78
    public function getMerchants() : array
79
    {
80
        throw new \Exception("Not implemented yet");
81
    }
82
83
    /**
84
	 * @param null $merchantID
85
	 * @param int $page
86
	 * @param int $items_per_page
87
	 * @return DealsResultset  array of Deal
88
	 * @throws \Exception
89
	 */
90
    public function getDeals($merchantID=NULL,int $page=0,int $items_per_page=100 ): DealsResultset
91
    {
92
        throw new \Exception("Not implemented yet");
93
    }
94
95
   	/**
96
	 * @param \DateTime $dateFrom
97
	 * @param \DateTime $dateTo
98
	 * @param array $arrMerchantID
99
	 * @return array of Transaction
100
	 * @throws \Exception
101
	 */
102
    public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array
103
    {
104
105
        $arrResult = array();
106
        $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo);
107
        foreach($transactionList as $transaction) {
108
            $Transaction = Transaction::createInstance();
109
            if (isset($transaction['currency']) && !empty($transaction['currency'])) {
110
                $Transaction->currency = $transaction['currency'];
111
            } else {
112
                $Transaction->currency = "EUR";
113
            }
114
            $Transaction->status = $transaction['status'];
115
            $Transaction->amount = $transaction['amount'];
116
            array_key_exists_safe( $transaction,'custom_id' ) ? $Transaction->custom_ID = $transaction['custom_id'] : $Transaction->custom_ID = '';
117
            $Transaction->unique_ID = $transaction['unique_id'];
118
            $Transaction->commission = $transaction['commission'];
119
            $Transaction->date = $transaction['date'];
120
            // Future use - Only few providers returns these dates values - <PN> - 2017-06-29
121
            if (isset($transaction['click_date']) && !empty($transaction['click_date'])) {
122
                $Transaction->click_date = $transaction['click_date'];
123
            }
124
            if (isset($transaction['update_date']) && !empty($transaction['update_date'])) {
125
                $Transaction->update_date = new \DateTime($transaction['update_date']);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime($transaction['update_date']) of type object<DateTime> is incompatible with the declared type string of property $update_date.

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..

Loading history...
126
            }
127
            $Transaction->merchant_ID = $transaction['merchantId'];
128
            $Transaction->campaign_name =  $transaction['campaign_name'];
129
            $Transaction->approved = false;
130
            if ($Transaction->status == \Oara\Utilities::STATUS_CONFIRMED){
131
                $Transaction->approved = true;
132
            }
133
            $arrResult[] = $Transaction;
134
        }
135
136
        return $arrResult;
137
    }
138
139
    /**
140
     * @param \DateTime $dateFrom
141
     * @param \DateTime $dateTo
142
     * @param int $merchantID
143
     * @return array of Stat
144
     */
145
    public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array
146
    {
147
        return array();
148
    }
149
150
151
    /**
152
	 * @param array $params
153
	 * @return ProductsResultset
154
	 * @throws \Exception
155
	 */
156
    public function getProducts(array $params = []): ProductsResultset
157
    {
158
        throw new \Exception("Not implemented yet");
159
    }
160
161
    public function getTrackingParameter(){
162
        return $this->_tracking_parameter;
163
    }
164
165
166
167
}
168