| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Padosoft\AffiliateNetwork\Networks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Padosoft\AffiliateNetwork\Transaction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Padosoft\AffiliateNetwork\DealsResultset; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  | use Padosoft\AffiliateNetwork\ProductsResultset; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use \Oara\Network\Publisher\ImpactRadius as OaraImpactRadius; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Class ImpactRadius | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @package Padosoft\AffiliateNetwork\Networks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class ImpactRadius extends AbstractNetwork implements NetworkInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private $_network = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private $_apiClient = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $_username = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $_password = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private $_logged    = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected $_tracking_parameter    = 'subId1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @method __construct | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public function __construct(string $username, string $password) | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $this->_network = new OaraImpactRadius; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         $this->_username = $username; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         $this->_password = $password; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         $this->_apiClient = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $this->login( $this->_username, $this->_password ); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function login(string $username, string $password): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->_logged = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         if (isNullOrEmpty( $username ) || isNullOrEmpty( $password )) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->_username = $username; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->_password = $password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $credentials = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $credentials["user"] = $this->_username; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $credentials["password"] = $this->_password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->_network->login( $credentials ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         if ($this->_network->checkConnection()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $this->_logged = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return $this->_logged; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function checkLogin() : bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return $this->_logged; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @return array of Merchants | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 73 |  | View Code Duplication |     public function getMerchants() : array | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         if (!$this->checkLogin()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $arrResult = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $merchantList = $this->_network->getMerchantList(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         foreach($merchantList as $merchant) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $Merchant = Merchant::createInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             $Merchant->merchant_ID = $merchant['cid']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $Merchant->name = $merchant['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $Merchant->url = $merchant['url']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $Merchant->status = $merchant['status']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             $arrResult[] = $Merchant; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         return $arrResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param int|null $merchantID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param int $page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param int $items_per_page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @return DealsResultset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $result = DealsResultset::createInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $arrResult = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         // TODO | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $result->deals[]=$arrResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @param \DateTime $dateFrom | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @param \DateTime $dateTo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @param int $merchantID | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @return array of Transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $arrResult = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             // Added timezone parameter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             $transactionList = $this->_network->getTransactionList($arrMerchantID, $dateFrom, $dateTo, 'UTC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             if (is_array($transactionList)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 foreach ($transactionList as $transaction) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                     try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                         $myTransaction = Transaction::createInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                         $myTransaction->merchant_ID = $transaction['merchantId']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                         $myTransaction->unique_ID = $transaction['unique_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                         $myTransaction->date = $transaction['date']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                         $myTransaction->custom_ID = $transaction['custom_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                         $myTransaction->amount = $transaction['amount']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                         $myTransaction->commission = $transaction['commission']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                         $myTransaction->currency = $transaction['currency']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                         $myTransaction->status = $transaction['status']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                         $arrResult[] = $myTransaction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                     } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |                         echo "<br><br>Transaction Error Impact Radius, id: ".$myTransaction->unique_ID." msg: ".$e->getMessage()."<br><br>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                         var_dump($e->getTraceAsString()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             echo "<br><br>Generic Error Impact Radius: ".$e->getMessage()."<br><br>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             var_dump($e->getTraceAsString()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             throw new \Exception($e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         return $arrResult; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |         throw new \Exception("Not implemented yet"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @param  array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @return ProductsResultset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |     public function getProducts(array $params = []): ProductsResultset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         // TODO: Implement getProducts() method. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         throw new \Exception("Not implemented yet"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     public function getTrackingParameter(){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         return $this->_tracking_parameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 179 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 180 |  |  |  | 
            
                        
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.