| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | require_once 'ShopController.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class ShopTransactionController extends ShopController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     public function view() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         Ajde::app()->getDocument()->setTitle(trans('Your order')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         // Get from ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         if ($this->hasNotEmpty('id')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |             if ($transaction->loadByField('secret', $this->getId()) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |                 $this->getView()->assign('source', 'id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             // Get existing transaction / user details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |             $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |                 $this->getView()->assign('source', 'session'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->getView()->assign('transaction', $transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function export() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         // Get from ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if (!($this->hasNotEmpty('id') && $transaction->loadByField('secret', $this->getId()) !== false)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             Ajde::app()->getResponse()->redirectNotFound(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         /** @var Ajde_Document_Format_Generated $doc */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $doc = Ajde::app()->getDocument(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $url = config('app.rootUrl').'shop/transaction:view/'.$this->getId().'.html'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $filename = $transaction->getOrderId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         if ($this->getFormat() === 'pdf') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             $pdf = $doc->generate([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 'url'      => $url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 'filename' => $filename, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $doc->setContentType('application/pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             Ajde::app()->getResponse()->addHeader('Content-Disposition', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 'attachment; filename="'.$filename.'.pdf"'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             return $pdf; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public function setup() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         // Get existing transaction / user details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $user = UserModel::getLoggedIn(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             $name = $transaction->name; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             $email = $transaction->email; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             $address = $transaction->shipment_address; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             $zipcode = $transaction->shipment_zipcode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             $city = $transaction->shipment_city; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $region = $transaction->shipment_region; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             $country = $transaction->shipment_country; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $comment = $transaction->comment; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         } elseif ($user !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             // Insert intermediate transaction to save country and present user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             // with shipping options, ignore response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $this->setupJson($user); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $name = $user->fullname; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $email = $user->email; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $address = $user->address; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             $zipcode = $user->zipcode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $city = $user->city; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $region = $user->region; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $country = $user->country; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             $comment = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             // Insert intermediate transaction to save cart and allow user to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             // see shipping options when country is choosen | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             $this->setupJson(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             $name = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             $email = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $address = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $zipcode = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $city = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             $region = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             $country = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $comment = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $view = $this->getView(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $view->assign('name', $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $view->assign('email', $email); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $view->assign('address', $address); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $view->assign('zipcode', $zipcode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $view->assign('city', $city); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $view->assign('region', $region); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $view->assign('country', $country); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $view->assign('comment', $comment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $view->assign('user', $user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     public function shipment() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             if (Ajde::app()->getRequest()->has('country')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 $transaction->shipment_country = Ajde::app()->getRequest()->getParam('country'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 $transaction->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             $shipment = new ShippingModel($transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             $method = $transaction->shipment_method; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             if (empty($method) || !$shipment->isAvailable($method)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 $method = $shipment->getFirstMethod()->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             $shipment = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             $method = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             $transaction = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $this->getView()->assign('method', $method); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $this->getView()->assign('shipment', $shipment); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $this->getView()->assign('transaction', $transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     public function setupJson($source = false) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         $request = Ajde::app()->getRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         // Init vars | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $name = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         $email = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $address = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $zipcode = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $city = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         $region = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $country = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         $shipmentMethod = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $comment = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         if ($source === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             // Read request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |             $name = $request->getPostParam('name', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             $email = $request->getPostParam('email', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             $address = $request->getPostParam('shipment_address', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             $zipcode = $request->getPostParam('shipment_zipcode', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $city = $request->getPostParam('shipment_city', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             $region = $request->getPostParam('shipment_region', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             $country = $request->getPostParam('shipment_country', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $shipmentMethod = $request->getPostParam('shipment_method', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |             $comment = $request->getPostParam('comment', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             if ($source instanceof Ajde_User) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                 // Read user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                 $name = $source->fullname; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                 $email = $source->email; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 $address = $source->address; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                 $zipcode = $source->zipcode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                 $city = $source->city; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                 $region = $source->region; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |                 $country = $source->country; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |                 $shipmentMethod = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                 $comment = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         // Return when fields are not complete | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         if ($source === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             if ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                 empty($name) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 empty($email) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |                 empty($address) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |                 empty($zipcode) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |                 empty($city) || | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |                 empty($country) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |                     'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |                     'message' => trans('Not all your details are filled out'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             if (Ajde_Component_String::validEmail($email) === false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                     'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                     'message' => trans('Please provide a valid e-mail address'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             if (empty($shipmentMethod)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |                     'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |                     'message' => trans('Please choose a shipment method'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         // Check for current transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |             // Edit existing transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             $method = 'save'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             // Insert new transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |             $method = 'insert'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |         // Update transaction info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         $transaction->name = $name; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         $transaction->email = $email; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         $transaction->shipment_address = $address; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         $transaction->shipment_zipcode = $zipcode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         $transaction->shipment_city = $city; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         $transaction->shipment_region = $region; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         $transaction->shipment_country = $country; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         $transaction->shipment_method = $shipmentMethod; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         $transaction->comment = $comment; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         // Save info to user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         if ($user = $this->getLoggedInUser()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |             if ($request->hasPostParam('save_details', false)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |                 $user->address = $address; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |                 $user->zipcode = $zipcode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 $user->city = $city; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |                 $user->region = $region; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |                 $user->country = $country; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |                 $user->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |                 $user->login(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |             $transaction->user = $user->getPK(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         // Update shipping total | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $shipping = new ShippingModel($transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         $transaction->shipment_cost = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         if (!empty($shipmentMethod) && $shipping->isAvailable($shipmentMethod)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |             $transaction->shipment_cost = $shipping->getMethod($shipmentMethod)->getTotal(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         // Insert new transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         if ($method === 'insert') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |             if ($transaction->insert()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |                 $this->updateFromCart($transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |                 $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |                 $session->set('currentTransaction', $transaction->getPK()); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 263 |  | View Code Duplication |                 if (!$transaction->shipment_itemsqty > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |                     return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |                         'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |                         'message' => trans('No items added to current order'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |                     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |                     'success' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |             return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |                 'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |                 'message' => trans('Something went wrong'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         $transaction->payment_amount = $transaction->shipment_itemstotal + $transaction->shipment_cost; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         // Update current transaction | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 284 |  | View Code Duplication |         if ($transaction->save()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |             if (!$transaction->shipment_itemsqty > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |                     'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |                     'message' => trans('No items added to current transaction'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |             return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |                 'success' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         // Everything else failed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |             'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |             'message' => trans('Something went wrong'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |     public function updateFromCart(Ajde_Shop_Transaction $transaction) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |         $cart = new CartModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         $cart->loadCurrent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         if ($cart->countItems() > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |             $transaction->shipment_description = $cart->getHtmlSummaryTable(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |             $transaction->shipment_itemsqty = $cart->countQty(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |             $transaction->shipment_itemsvatamount = $cart->getItems()->getVATAmount(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |             $transaction->shipment_itemstotal = $cart->getItems()->getTotal(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |             $transaction->payment_amount = $transaction->shipment_itemstotal + $transaction->shipment_cost; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |             $transaction->shipment_description = ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |             $transaction->shipment_itemsqty = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |             $transaction->shipment_itemsvatamount = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |             $transaction->shipment_itemstotal = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |             $transaction->payment_amount = 0; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         $transaction->setItemsFromCart($cart); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |         $transaction->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 327 |  | View Code Duplication |     public function update() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |         // Check for current transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |             $this->updateFromCart($transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |         Ajde_Session_Flash::alert(trans('Your order has been updated', 'shop')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |         $this->redirect('shop/transaction:setup'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |         //		$this->setAction('view'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |         //		return $this->view(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 341 |  | View Code Duplication |     public function cancel() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |         // Edit existing transaction? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |             $transaction->payment_status = 'cancelled'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |             $transaction->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |             $session->destroy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |         Ajde_Session_Flash::alert(trans('Your order has been cancelled', 'shop')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |         $this->redirect('shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |     public function payment() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |             if (!$transaction->shipment_itemsqty > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |                 $this->redirect('shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |         $this->getView()->assign('transaction', $transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |     public function resetPayment() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |         // Get transaction from ID if available | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |         if ($this->hasNotEmpty('id')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |             if ($transaction->loadByField('secret', $this->getId()) !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |                 $session->set('currentTransaction', $transaction->getPK()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |             $transaction->payment_provider = null; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |             $transaction->payment_status = 'pending'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |             $transaction->secret_archive = $transaction->secret_archive.$transaction->secret.PHP_EOL; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |             $transaction->secret = $transaction->generateSecret(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |             $transaction->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |         $this->redirect('shop/transaction:payment'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |     public function paymentJson() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |         $request = Ajde::app()->getRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |         $provider = $request->getPostParam('provider', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |         if (empty($provider)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |             return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |                 'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |                 'message' => trans('Please choose a payment provider'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |         // Check for current transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |         if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |             if ($transaction->payment_status !== 'pending') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |                     'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |                     'message' => trans('Payment already initiated, please refresh this page'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |             return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |                 'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |                 'message' => trans('No current order found'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         $transaction->payment_provider = $provider; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |         $provider = $transaction->getProvider(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |         $redirectUrl = $provider->getRedirectUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |         if ($redirectUrl !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |             $transaction->payment_status = 'requested'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |             $transaction->save(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |             if ($provider->usePostProxy()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |                 $this->setAction('postproxy'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |                 $proxy = $this->getView(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |                 $proxy->assign('provider', $provider); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |                 return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |                     'success'   => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |                     'postproxy' => $proxy->render(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |             return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |                 'success'  => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |                 'redirect' => $redirectUrl, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |             'success' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |             'message' => 'Could not contact the payment provider, please try again', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 454 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 455 |  |  |     public function complete() | 
            
                                                                        
                            
            
                                    
            
            
                | 456 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 457 |  |  |         $cart = new CartModel(); | 
            
                                                                        
                            
            
                                    
            
            
                | 458 |  |  |         $cart->loadCurrent(); | 
            
                                                                        
                            
            
                                    
            
            
                | 459 |  |  |         $cart->emptyItems(); | 
            
                                                                        
                            
            
                                    
            
            
                | 460 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 461 |  |  |         // Get existing transaction | 
            
                                                                        
                            
            
                                    
            
            
                | 462 |  |  |         $transaction = new TransactionModel(); | 
            
                                                                        
                            
            
                                    
            
            
                | 463 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                        
                            
            
                                    
            
            
                | 464 |  |  |         if ($session->has('currentTransaction')) { | 
            
                                                                        
                            
            
                                    
            
            
                | 465 |  |  |             $transaction->loadByPK($session->get('currentTransaction')); | 
            
                                                                        
                            
            
                                    
            
            
                | 466 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 467 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 468 |  |  |         $session->destroy(); | 
            
                                                                        
                            
            
                                    
            
            
                | 469 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 470 |  |  |         $this->getView()->assign('transaction', $transaction); | 
            
                                                                        
                            
            
                                    
            
            
                | 471 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 472 |  |  |         return $this->render(); | 
            
                                                                        
                            
            
                                    
            
            
                | 473 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |     public function refused() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |     public function callback() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |         $providerName = $this->getId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |         $provider = Ajde_Shop_Transaction_Provider::getProvider($providerName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |         $status = $provider->updatePayment(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |         if ($status['success'] === true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |             $transaction = $status['transaction']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |             if (isset($transaction)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |                 $this->mailUser($transaction); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |                 $this->mailUpdateAdmin($transaction, 'Order completed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |             $this->redirect('shop/transaction:complete'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |             $transaction = $status['transaction']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |             if (isset($transaction)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |                 $this->mailUpdateAdmin($transaction, 'Order refused'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |             $this->redirect('shop/transaction:refused'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |     public function startNew() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |         $session = new Ajde_Session('AC.Shop'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |         $session->destroy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |         return $this->redirect('shop/cart'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |     public function mailUpdateAdmin(TransactionModel $transaction, $subject = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |         $recipient = config('app.email'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |         $mailer = new Ajde_Mailer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |         $mailer->SendQuickMail($recipient, $recipient, config('app.title'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |             isset($subject) ? $subject : 'Order update', $transaction->getOverviewHtml()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |     public function mailUser(TransactionModel $transaction) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |         $viewLink = config('app.rootUrl').'shop/transaction:view/'.$transaction->secret.'.html'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |         $mailer = new Ajde_Mailer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |         $mailer->sendUsingModel('your_order', $transaction->email, $transaction->name, [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |             'viewlink' => $viewLink, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |      * @param TransactionItemModel $transaction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |      * @deprecated use mailUser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |      * @throws Ajde_Core_Exception_Deprecated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |      * @throws Ajde_Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |      * @throws phpmailerException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |     public function mailUserDeprecated(TransactionItemModel $transaction) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |         throw new Ajde_Core_Exception_Deprecated(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |         $mailer = new Ajde_Mailer(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |         $mailer->IsMail(); // use php mail() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |         $mailer->AddAddress($transaction->email, $transaction->name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |         $mailer->From = config('app.email'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |         $mailer->FromName = config('app.title'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |         $mailer->Subject = 'Your order'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |         $mailer->Body = '<h2>Your order on '.config('app.title').'</h2>'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |             '<p>Thank you for shopping with us. We will ship your items as soon as possible if you chose for delivery.<br/>'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |             'To view the status of your order, please click this link:</p>'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |             '<p><a href=\''.config('app.rootUrl').'shop/transaction:view/'.$transaction->secret.'.html\'>View your order status</a></p>'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |             '<p>Hope to welcome you again soon on <a href=\''.config('app.rootUrl').'\'>'.config('app.title').'</a></p>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |         $mailer->IsHTML(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |         if (!$mailer->Send()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |             Ajde_Log::log('Mail to '.$transaction->email.' failed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |     public function test() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |         $this->setAction('test/confirm'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |     public function iban() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  |         $this->setAction('iban/confirm'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |         return $this->render(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 573 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 574 |  |  |  | 
            
                        
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.