Exemple #1
0
 /**
  * Confirm step of the checkout. Should be a pass-through page for JS-enabled browsers, requires a form submission to the payment gateway
  *
  * @return     void
  */
 public function confirmTask()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'CurrentCart.php';
     $cart = new CartModelCurrentCart();
     $transaction = $cart->liftTransaction();
     if (!$transaction) {
         $cart->redirect('home');
     }
     // Get security token
     $transaction->token = $cart->getToken();
     // Check if there are any steps missing. Redirect if needed
     $nextStep = $cart->getNextCheckoutStep();
     if ($nextStep != 'summary') {
         $cart->redirect($nextStep);
     }
     // Final step here before payment
     CartModelCart::updateTransactionStatus('awaiting payment', $transaction->info->tId);
     // Generate payment code
     $params = Component::params(Request::getVar('option'));
     $paymentGatewayProivder = $params->get('paymentProvider');
     include_once JPATH_COMPONENT . DS . 'lib' . DS . 'payment' . DS . 'PaymentDispatcher.php';
     $paymentDispatcher = new PaymentDispatcher($paymentGatewayProivder);
     $pay = $paymentDispatcher->getPaymentProvider();
     $pay->setTransactionDetails($transaction);
     $error = false;
     try {
         $paymentCode = $pay->getPaymentCode();
         $this->view->paymentCode = $paymentCode;
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     if (!empty($error)) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
 /**
  * Attempts to rebuild a transaction if there is enough inventory and prices have not changed
  *
  * @param void
  * @return bool Success or failure
  */
 private function rebuildTransaction()
 {
     // Go through each item in the transaction and see if it is available in quantity needed and if price has not changed
     $tItems = $this->getTransactionItems($this->cart->tId);
     foreach ($tItems as $item) {
         // Check price
         if ($item['info']->sPrice != $item['transactionInfo']->tiPrice) {
             // price changed
             return false;
         }
         // Check inventory
         if ($item['info']->sInventory < $item['transactionInfo']->qty) {
             // Not enough inventory
             return false;
         }
     }
     // lock transaction items
     include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     foreach ($tItems as $sId => $item) {
         $warehouse->updateInventory($sId, $item['transactionInfo']->qty, 'subtract');
     }
     parent::updateTransactionStatus('pending', $this->cart->tId);
     return true;
 }