| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Dynamic\Foxy\Orders\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Dynamic\Foxy\Model\FoxyHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Dynamic\Foxy\Model\Order; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Control\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Control\HTTPRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\ORM\ValidationException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SilverStripe\Security\Member; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SilverStripe\Security\Security; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class FoxyController extends Controller | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     const URLSEGMENT = 'foxy'; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     private static $allowed_actions = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         'index', | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     public function getURLSegment() | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         return self::URLSEGMENT; | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * @throws ValidationException | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     public function index() | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         $request = $this->getRequest(); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         if ($request->postVar('FoxyData') || $request->postVar('FoxySubscriptionData')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             $this->processFoxyRequest($request); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |             return 'foxy'; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         return 'No FoxyData or FoxySubscriptionData received.'; | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * Process a request after a transaction is completed via Foxy | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * @param HTTPRequest $request | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @throws ValidationException | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     protected function processFoxyRequest(HTTPRequest $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $encryptedData = $request->postVar('FoxyData') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ? urldecode($request->postVar('FoxyData')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             : urldecode($request->postVar('FoxySubscriptionData')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->parseFeedData($encryptedData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |         $this->extend('addIntegrations', $encryptedData); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      * Parse the XML data feed from Foxy to a SimpleXMLElement object | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      * @param $encryptedData | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * @param $decryptedData | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      * @throws ValidationException | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     private function parseFeedData($encryptedData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $decryptedData = $this->decryptFeedData($encryptedData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $orders = new \SimpleXMLElement($decryptedData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         // loop over each transaction to find FoxyCart Order ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         foreach ($orders->transactions->transaction as $transaction) { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 78 |  |  |             $this->processTransaction($transaction, $encryptedData); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |      * @param $transaction | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |      * @return bool | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      * @throws ValidationException | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     private function processTransaction($transaction, $encryptedData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         if (!isset($transaction->id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         if (!$order = Order::get()->filter('OrderID', (int)$transaction->id)->first()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             $order = Order::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $order->OrderID = (int)$transaction->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $order->Response = urlencode($encryptedData); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 97 |  |  |         $order->write(); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |      * Decrypt the XML data feed from Foxy | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |      * @param $data | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      * @throws \SilverStripe\ORM\ValidationException | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     private function decryptFeedData($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $helper = FoxyHelper::create(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 110 |  |  |         return \rc4crypt::decrypt($helper->config()->get('secret'), $data); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 112 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths