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(); }