Exemple #1
0
 public function post()
 {
     $request = $this->rest->getRequestParams();
     if (!$this->customer->isLoggedWithToken($request['token'])) {
         $this->rest->sendResponse(401, array('error' => 'Not logged in or Login attempt failed!'));
         return;
     }
     //Check if confirmation details were reviewed.
     if (!$this->session->data['confirmed']) {
         $this->rest->sendResponse(400, array('status' => 0, 'error' => 'Need to review confirmation details first!'));
         return;
     }
     $this->session->data['confirmed'] = FALSE;
     //Check if order is created and process payment
     if (!isset($this->session->data['order_id'])) {
         $this->rest->sendResponse(500, array('status' => 2, 'error' => 'Not order data available!'));
         return;
     }
     $order = new AOrder($this->registry);
     $order_data = $order->loadOrderData($this->session->data['order_id'], 'any');
     //Check if order is present and not processed yet
     if (!isset($order_data)) {
         $this->rest->sendResponse(500, array('status' => 3, 'error' => 'No order available. Something went wrong!'));
         return;
     }
     if ($order_data['order_status_id'] > 0) {
         $this->rest->sendResponse(200, array('status' => 4, 'error' => 'Order was already processed!'));
         return;
     }
     //Dispatch the payment send controller process and capture the result
     if (!$this->session->data['process_rt']) {
         $this->rest->sendResponse(500, array('status' => 5, 'error' => 'Something went wrong. Incomplete request!'));
         return;
     }
     //we process only responce type payment extensions
     $payment_controller = $this->dispatch('responses/extension/' . $this->session->data['process_rt']);
     $this->load->library('json');
     $this->data = AJson::decode($payment_controller->dispatchGetOutput(), TRUE);
     if ($this->data['error']) {
         $this->data['status'] = 6;
         $this->rest->sendResponse(200, $this->data);
         return;
     } else {
         if ($this->data['success']) {
             $this->data['status'] = 1;
             //order completed clean up
             if (isset($this->session->data['order_id'])) {
                 $this->cart->clear();
                 unset($this->session->data['shipping_method']);
                 unset($this->session->data['shipping_methods']);
                 unset($this->session->data['payment_method']);
                 unset($this->session->data['payment_methods']);
                 unset($this->session->data['guest']);
                 unset($this->session->data['comment']);
                 unset($this->session->data['order_id']);
                 unset($this->session->data['coupon']);
             }
             $this->rest->setResponseData($this->data);
             $this->rest->sendResponse(200);
         } else {
             $this->data['status'] = 0;
             $this->data['error'] = "Unexpected Error";
             $this->rest->sendResponse(500, $this->data);
         }
     }
 }