Esempio n. 1
0
 /**
  * Place order (for orders with zero balances)
  *
  * @return     void
  */
 public function placeTask()
 {
     // Get the current active transaction
     $cart = new CurrentCart();
     $transaction = $cart->liftTransaction();
     if (!$transaction) {
         App::redirect(Route::url('index.php?option=' . 'com_cart'));
     }
     // get security token (Parameter 0)
     $token = Request::getVar('p0');
     if (!$token || !$cart->verifyToken($token)) {
         die('Error processing your order. Bad security token.');
     }
     // Check if the order total is 0
     if ($transaction->info->tiTotal != 0) {
         die('Cannot process transaction. Order total is not zero.');
     }
     // Check if the transaction's status is pending
     if ($transaction->info->tStatus != 'pending') {
         die('Cannot process transaction. Transaction status is invalid.');
     }
     //print_r($transaction); die;
     if ($this->completeOrder($transaction)) {
         // Get the transaction ID variable name to pull from URL
         $params = Component::params(Request::getVar('option'));
         // Get payment provider
         $paymentGatewayProivder = $params->get('paymentProvider');
         require_once dirname(dirname(__DIR__)) . DS . 'lib' . DS . 'payment' . DS . 'PaymentDispatcher.php';
         $verificationVar = \PaymentDispatcher::getTransactionIdVerificationVarName($paymentGatewayProivder);
         // redirect to thank you page
         $redirect_url = Route::url('index.php?option=' . 'com_cart') . '/order/complete/' . '?' . $verificationVar . '=' . $token . '-' . $transaction->info->tId;
         App::redirect($redirect_url);
     }
 }
Esempio n. 2
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()
 {
     $cart = new CurrentCart();
     $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()->step;
     if ($nextStep != 'summary') {
         $cart->redirect($nextStep);
     }
     // Final step here before payment
     Cart::updateTransactionStatus('awaiting payment', $transaction->info->tId);
     // Generate payment code
     $params = Component::params(Request::getVar('option'));
     $paymentGatewayProivder = $params->get('paymentProvider');
     require_once dirname(dirname(__DIR__)) . 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();
 }