Ejemplo n.º 1
0
 public function Show()
 {
     if (isset($_GET['action'])) {
         $content = $_GET['action'];
     } elseif (isset($_GET['merchant_return_link']) && $_GET['merchant_return_link']) {
         // PayPal sends it's own query string when the return after payment link is clicked,
         // set our 'checkedout' state if found
         $content = 'checkedout';
     } else {
         $content = '';
     }
     if (Config::GetInstance()->UsePayments() || empty($content)) {
         // session is needed for payments and most submits that have '?action' set
         Config::GetInstance()->InitSession();
         // clear any old sessions when showing a fresh form to clear payment stuff
         if (empty($content)) {
             Config::GetInstance()->ClearSession();
         }
     }
     // check what content to show
     switch ($content) {
         case 'confirmation':
         case 'checkout':
             $this->_PageFromSession();
             break;
         case 'cancel':
             $this->SetErrors(array(array('field' => 'Form', 'err' => _T('Payment transaction cancelled.'))));
             // fall through
         // fall through
         case 'back':
             // show the original page after canceling a payment transaction
             $this->RestorePostFromSession();
             $this->HandleErrors();
             echo $this->source;
             $this->_UpdateCartState('cancelled');
             break;
         case 'checkedout':
             $this->_UpdateCartState('checked-out');
             $this->RestorePostFromSession();
             $ctl = new FormController();
             $ctl->checkedout = true;
             $ctl->ShowUserConfirmation();
             break;
         case 'submitpayment':
             // sent by Javascript when user pushed on a 'Pay' button
             $this->RestorePostFromSession(false);
             // don't clear session, it is needed upon 'checkedout'
             // ensure the merger has access to cart details
             $payment = new CheckoutController();
             MessagePostMerger::GetInstance()->cart = $payment->getCartInstance();
             // send the emails
             $this->SendEmails();
             // prepare feedback
             if (count($this->errors) == 0) {
                 echo 'ok';
             } else {
                 echo json_encode($this->errors);
             }
             break;
         default:
             if ($this->source === false) {
                 $this->ReadSource();
             }
             if ($this->source !== false) {
                 echo $this->source;
             } else {
                 trigger_error('Read the template BEFORE trying to send it to a user.', E_USER_WARNING);
             }
             break;
     }
 }