/** @return int the same as get param but with intval(...) applied */ function getInt($key, $default = 0) { return $this->_request->getInt($key, $default); }
public function expressCheckoutAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) { $token = $request->getFiltered('token'); if (!$token) { throw new Am_Exception_InputError("No required [token] provided, internal error"); } $log = $this->getDi()->invoiceLogRecord; $log->title = ""; $log->paysys_id = $this->getId(); if ($request->getInt('do')) { $invoice = current($this->getDi()->invoiceTable->findByData(self::PAYPAL_EXPRESS_TOKEN, $token)); if (!$invoice) { throw new Am_Exception_InternalError("Could not find invoice by token [{$token}]"); } $this->_setInvoice($invoice); $log->setInvoice($invoice); if ($invoice->first_total > 0) { // bill initial amount @todo free trial $log->title .= " doExpressCheckout"; $apireq = new Am_Paysystem_PaypalApiRequest($this); $apireq->doExpressCheckout($invoice, $token, $request->getFiltered('PayerID')); $vars = $apireq->sendRequest($log); $transaction = new Am_Paysystem_Transaction_PayPalExpress_DoExpressCheckout($this, $vars); $transaction->setInvoice($invoice); $transaction->process(); } if ($invoice->rebill_times) { $log->title .= " createRecurringPaymentProfile"; $apireq = new Am_Paysystem_PaypalApiRequest($this); $apireq->createRecurringPaymentProfile($invoice, null, $token, $request->getFiltered('PayerID')); $vars = $apireq->sendRequest($log); if ($vars['ACK'] != 'Success') { $this->logError("Not Success response to CreateRecurringPaymentProfile request", $vars); } else { $invoice->data()->set(self::PAYPAL_PROFILE_ID, $vars['PROFILEID'])->update(); if ($invoice->first_total <= 0) { $transaction = new Am_Paysystem_Transaction_PayPalExpress_CreateRecurringPaymentProfile($this, $vars); $transaction->setInvoice($invoice); $transaction->process(); } } } return Am_Controller::redirectLocation($this->getReturnUrl()); } else { $log->title .= " getExpressCheckoutDetails"; $apireq = new Am_Paysystem_PaypalApiRequest($this); $apireq->getExpressCheckoutDetails($token); $vars = $apireq->sendRequest($log); $invoiceId = filterId(get_first(@$vars['INVNUM'], @$vars['L_PAYMENTREQUEST_0_INVNUM'], $this->getDi()->session->paypal_invoice_id)); if (!$invoiceId || !($invoice = $this->getDi()->invoiceTable->findBySecureId($invoiceId, 'paypal'))) { throw new Am_Exception_InputError("Could not find invoice related to given payment. Internal error. Your account was not billed, please try again"); } $log->setInvoice($invoice); $log->update(); $this->_setInvoice($invoice); /* @var $invoice Invoice */ if ($invoice->isPaid()) { return Am_Controller::redirectLocation($this->getReturnUrl()); } $invoice->data()->set(self::PAYPAL_EXPRESS_TOKEN, $token)->update(); $view = new Am_View(); $view->invoice = $invoice; $view->url = $this->getPluginUrl(self::PAYPAL_EXPRESS_CHECKOUT); $view->hidden = array('do' => '1', 'token' => $request->getFiltered('token'), 'PayerID' => $request->getFiltered('PayerID')); $view->display("payment-confirm.phtml"); } }
public function setFromRequest(Am_Request $request) { if (is_string($search = $request->get('search'))) { $this->query->unserialize($search); } else { if ($id = $request->getInt('_u_search_load')) { $this->query->load($id); } else { $this->query->setFromRequest($request); } } }
public function adminCancelAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) { if (!$this->getDi()->authAdmin->getUserId()) { throw new Am_Exception_AccessDenied("Only admin access allowed"); } $invoice_id = $request->getInt('invoice_id'); $invoice = $this->getDi()->invoiceTable->load($invoice_id); if ($invoice->paysys_id != $this->getId()) { throw new Am_Exception_InternalError("Trying to cancel transaction - not 2CO one"); } $result = new Am_Paysystem_Result(); $payment = current($invoice->getPaymentRecords()); try { $this->cancelInvoice($payment, $result); } catch (Exception $e) { $result->setFailed($e->getMessage()); } $view = $this->getDi()->view; $view->title = ___("Subscription Cancelled"); $view->content = $result->isSuccess() ? ___("Success") : implode("<br />\n", $result->getErrorMessages()); $response->setBody($view->render('admin/layout.phtml')); }