public static function transfer($transaction_id, $fromUser, $toUser, $ammount) { Zend_Registry::get('logger')->entering(); $paypalEntry = new PaypalEntry(); // record to debitor's paypal account $credit = array('transaction_id' => $transaction_id, 'user_id' => $toUser->id, 'ammount' => -1 * $ammount); $paypalEntry->insert($credit); // record to creditor's paypal account $debit = array('transaction_id' => $transaction_id, 'user_id' => $fromUser->id, 'ammount' => $ammount); $paypalEntry->insert($debit); Zend_Registry::get('logger')->exiting(); }
public function swapCart($user) { Zend_Registry::get('logger')->entering(); Zend_Registry::get('logger')->debug('Instantiate transaction'); $transactionId = $this->create(); Zend_Registry::get('logger')->debug('Find items to buy'); $lineItemTable = new LineItem(); $items = $lineItemTable->findItems($user->id); $lineItems = $user->findLineItem(); Zend_Registry::get('logger')->debug('Calculate charges & fees'); $totalCharges = 0; $totalFees = 0; /* foreach ($items as $item) { $totalCharges += $item->points + Item::shippingCharge($item->weight); $totalFees += self::TRANSACTION_CHARGE; } */ foreach ($lineItems as $lineItem) { $item = $lineItem->findParentItem(); $totalCharges += $item->points; if (1 == $lineItem->shipping) { $totalCharges += Item::shippingCharge($item->weight); } $totalFees += self::TRANSACTION_CHARGE; } Zend_Registry::get('logger')->debug('Calculate swapbucks to buy'); $swapbucksToBuy = $totalCharges - $user->balance; if ($swapbucksToBuy < 0) { $swapbucksToBuy = 0; } Zend_Registry::get('logger')->debug('Find the swaplady user'); $users = new User(); $swaplady = $users->fetchRow('username = "******"'); Zend_Registry::get('logger')->debug('Transfer charges & fees from paypal'); $totalPaypalTransfer = $totalCharges + $totalFees; PaypalEntry::transfer($transactionId, $user, $swaplady, $totalPaypalTransfer); Zend_Registry::get('logger')->debug('Transfer bought swapbucks'); SwapbuckEntry::transfer($transactionId, $swaplady, $user, $swapbucksToBuy); Zend_Registry::get('logger')->debug('Transfer items'); foreach ($items as $item) { $this->swapItem($transactionId, $user, $item); } Zend_Registry::get('logger')->exiting(); }