public function newAction()
 {
     $this->logger->entering();
     $this->logger->info('Loading user');
     $users = new User();
     $user = $users->find($this->session->user_id)->current();
     $this->logger->info('Finding line items of the user');
     $lineItemTable = new LineItem();
     $where = $this->db->quoteInto('user_id = ?', $user->id);
     $lineItems = $lineItemTable->fetchAll($where);
     $items = array();
     $swapbucksTotal = 0;
     $transactionTotal = 0;
     foreach ($lineItems as $lineItem) {
         $item = $lineItem->findParentRow('Item');
         if (1 == $lineItem->shipping) {
             $shippingCharge = Item::shippingCharge($item->weight);
         } else {
             $shippingCharge = 0;
         }
         $items[$item->name] = array('quantity' => 1, 'transFee' => 1, 'item_id' => $item->id, 'title' => $item->name, 'price' => $item->points, 'line_item_id' => $lineItem->id, 'user_id' => $lineItem->user_id, 'shipping_method' => $lineItem->shipping, 'shipping_charge' => $shippingCharge, 'total' => $item->points + $shippingCharge);
         $swapbucksTotal += $items[$item->name]['total'];
         $transactionTotal += $items[$item->name]['transFee'];
     }
     $this->logger->info('Determine swapbucks to be bought');
     $swapbucksToBuy = null;
     if ($swapbucksTotal > $user->balance) {
         $swapbucksToBuy = $swapbucksTotal - $user->balance;
         $items['Swapbucks'] = array('title' => 'Swapbucks', 'quantity' => $swapbucksToBuy, 'price' => 0, 'shipping_charge' => 0, 'total' => 0, 'transFee' => $swapbucksToBuy);
         $transactionTotal += $swapbucksToBuy;
         $finalBalance = 0;
     } else {
         $finalBalance = $user->balance - $swapbucksTotal;
     }
     $paypalParams = array('cmd' => '_xclick', 'business' => '*****@*****.**', 'return' => 'http://swaplady.com/transactions/create', 'cancel_return' => 'http://swaplady.com/', 'currency_code' => 'USD', 'item_name' => 'Swaplady', 'amount' => $transactionTotal, 'no_shipping' => '1');
     $paypal = new PayPalEWP();
     $paypal->setTempFileDirectory('../tmp');
     //path to temp file
     $paypal->setCertificate('../config/pubcert.pem', '../config/prvkey.pem');
     //path to your public certificate, private key
     $paypal->setCertificateID('KF4WJNF89QEN6');
     //certificate id generated by PayPal when you uploaded your public certificate to your PayPal account
     $paypal->setPayPalCertificate('../config/sandbox_pubcert.pem');
     //PayPal public certificate
     $encryptedButton = $paypal->encryptButton($paypalParams);
     $this->logger->info('Populating the View');
     $this->view->assign(array('title' => 'Shopping Bag', 'user' => $user, 'swapbucksTotal' => $swapbucksTotal, 'transactionTotal' => $transactionTotal, 'swapbucksToBuy' => $swapbucksToBuy, 'finalBalance' => $finalBalance, 'items' => $items, 'paypalParams' => $paypalParams, 'encryptedButton' => $encryptedButton));
     $this->render();
     $this->logger->exiting();
 }
 public function showAction()
 {
     $this->logger->entering();
     $this->logger->info('Loading the item by id');
     $items = new Item();
     $item = $items->find($this->_getParam('id'))->current();
     if ($item == null) {
         $this->logger->warn('Tried to show an non-existant item');
         $this->flash->notice = 'Invalid Action';
         $this->_redirect('/');
     }
     $this->logger->info('Find all the tags for the item');
     $tags = $items->findTags($item->id);
     $this->logger->info('Find owner');
     $users = new User();
     $owner = $item->findParentUser();
     $user = $users->find($this->session->user_id)->current();
     $this->logger->info('Calculating price total');
     $shipping = Item::shippingCharge($item->weight);
     $total = $item->points + $shipping;
     $this->logger->info('Loading existing conversations');
     $conversation = null;
     $conversations = null;
     if (isset($user)) {
         $conversationTable = new Conversation();
         if ($owner->id == $user->id) {
             $conversationRows = $conversationTable->findAllByItem($item);
             foreach ($conversationRows as $conversationRow) {
                 $convo = $conversationRow->toArray();
                 $convo['user'] = $conversationRow->findParentUser()->toArray();
                 $conversations[] = $convo;
             }
         } else {
             $conversation = $conversationTable->findByUserAndItem($user, $item);
         }
     }
     $this->logger->info('Loading the view parameters');
     $this->view->assign(array('title' => "Item: {$item->name}", 'item' => $item, 'owner' => $owner, 'tags' => $tags, 'shipping' => $shipping, 'total' => $total, 'conversations' => $conversations, 'conversation' => $conversation));
     $this->logger->info('Rendering the application template');
     $this->render();
     $this->logger->exiting();
 }
Example #3
0
 public function swapItem($transactionId, $purchaser, $item)
 {
     Zend_Registry::get('logger')->entering();
     $users = new User();
     $owner = $users->find($item->owner_id)->current();
     Zend_Registry::get('logger')->debug('Transfer swapbuck value from purchaser to owner');
     SwapbuckEntry::transfer($transactionId, $purchaser, $owner, $item->points + Item::shippingCharge($item->weight));
     Zend_Registry::get('logger')->debug('transfer item from owner to purchaser');
     ItemEntry::transfer($transactionId, $owner, $purchaser, $item);
     Zend_Registry::get('logger')->exiting();
     return $transactionId;
 }