public function getLastNotPayedTransaction($type) { $payment = Doctrine_Query::create()->from('PaymentTransaction')->where('user_id = ? AND type = ?', array($this->id, '"' . $type . '"'))->andWhere('is_payed = ?', false)->andWhere('date_payed IS NULL')->orderBy('id DESC')->fetchOne(); if (!$payment) { $payment = new PaymentTransaction(); $payment->user_id = $this->id; $payment->type = $type; $payment->save(); } $price_list = PaymentTransaction::getPriceList(); $payment->amount = $price_list[$type]; return $payment; }
public function executePaypalSet(sfWebRequest $request) { $payment_type = $request->getParameter('payment_type'); $price_list = PaymentTransaction::getPriceList(); $payPalURL = ''; if (array_key_exists($payment_type, $price_list)) { /** @var sfGuardUser $user */ $user = $this->getUser()->getGuardUser(); $user->getLastNotPayedTransaction($payment_type); $gtw = new PaypalGateway(array('payer_id' => $user->id, 'amount' => $price_list[$payment_type], 'success_url' => $this->generateUrl('payment\\success', array('type' => $payment_type), true), 'cancel_url' => $this->generateUrl('payment\\cancel', array(), true))); $payPalURL = $gtw->setExpessCheckout(); } if ($payPalURL) { $this->redirect($payPalURL); } else { $this->getUser()->setFlash('error', 'PayPal connection error'); $this->redirect('/project/user/account'); } }