/**
  * Starts the transaction and gets the token. Afterwards it's passed off to the final transaction method.
  * @param 
  */
 public function paypal_set_ec()
 {
     if ($this->request->is('post')) {
         //Abort if cancel button was pressed
         if (isset($this->request->data['cancel'])) {
             //Pass the user along to an action that will clear the account and the upload
             $this->redirect(array('controller' => 'users', 'action' => 'clear_user_data', $this->request->data['Upload']['user_id']));
             break;
         }
         //Check to make sure that the total codes haven't already been added to this file
         $upload = $this->Upload->read(null, $this->request->data['Upload']['id']);
         if (intval($upload['Upload']['total_codes']) > 0) {
             if (intval($upload['Upload']['total_codes']) == count($upload['Code'])) {
                 $this->Session->setFlash(__('Error! No more codes can be added to this upload. Please re-upload the file.', true), 'message_fail');
                 $this->render('paypal_back_to_add');
                 return;
             }
         }
         //do paypal setECCheckout
         App::import('Model', 'Paypal');
         $paypal = new Paypal();
         $codePrice = $this->Upload->Code->getPrice($this->request->data['Upload']['total_codes']);
         $itemName = $this->Upload->Code->getItemName($this->request->data['Upload']['total_codes']);
         $nvpStr = $paypal->buildNVPString($codePrice, $itemName, $this->request->data['Upload']['user_id'], $this->request->data['Upload']['id'], $this->request->data['Upload']['total_codes']);
         if ($paypal->setExpressCheckout($nvpStr)) {
             $result = $paypal->getPaypalUrl($paypal->token);
         } else {
             $this->log($paypal->errors);
             $result = false;
         }
         //debug($this->request);
         if (false !== $result) {
             //The result should look like the following
             //https://www.sandbox.paypal.com/incontext?token=EC-09N44269CG053064W
             $this->redirect($result);
         } else {
             $this->Session->setFlash(__('Error while connecting to PayPal, Please try again', true));
         }
     }
     $payment_options = $this->Upload->Code->getPaymentOptions();
     //Get the options array for the select list
     $this->set(compact('payment_options'));
 }