public function expressCheckoutAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) { $invoiceLog = $this->_logDirectAction($request, $response, $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}]"); } $invoiceLog->setInvoice($invoice); $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 (!in_array($vars['ACK'], array('Success', 'SuccessWithWarning'))) { $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"); } $invoiceLog->setInvoice($invoice); $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"); } }
function __exception(Exception $e) { if ($e instanceof Zend_Controller_Dispatcher_Exception && preg_match('/^Invalid controller specified/', $e->getMessage())) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } if ($e->getCode() == 404) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } try { static $in_fatal_error; //! $in_fatal_error++; if ($in_fatal_error > 2) { echo nl2br("<b>\n\n" . __METHOD__ . " called twice\n\n</b>"); exit; } if (!$this->initFinished) { $isApiError = false; } else { $request = Zend_Controller_Front::getInstance()->getRequest(); $isApiError = preg_match('#^/api/#', $request->getPathInfo()) && !preg_match('#^/api/admin($|/)#', $request->getPathInfo()); } if (!$isApiError && (defined('AM_DEBUG') && AM_DEBUG || APPLICATION_ENV == 'testing')) { $display_error = "<pre>" . $e . ':' . $e->getMessage() . "</pre>"; } else { if ($e instanceof Am_Exception) { $display_error = $e->getPublicError(); $display_title = $e->getPublicTitle(); } elseif ($e instanceof Zend_Controller_Dispatcher_Exception) { $display_error = ___("Error 404 - Not Found"); header("HTTP/1.0 404 Not Found"); } else { $display_error = ___('An internal error happened in the script, please contact webmaster for details'); } } /// special handling for API errors if ($isApiError) { $format = $request->getParam('_format', 'json'); if (!empty($display_title)) { $display_error = $display_title . ':' . $display_error; } $display_error = trim($display_error, " \t\n\r"); if ($format == 'xml') { $xml = new SimpleXMLElement('<error />'); $xml->ok = 'false'; $xml->message = $display_error; echo (string) $xml; } else { echo json_encode(array('ok' => false, 'error' => true, 'message' => $display_error)); } exit; } if (!$this->initFinished) { amDie($display_error); } // fixes http://bt.amember.com/issues/597 if (($router = Zend_Controller_Front::getInstance()->getRouter()) instanceof Zend_Controller_Router_Rewrite) { $router->addDefaultRoutes(); } // $t = new Am_View(); $t->assign('is_html', true); // must be already escaped here! if (isset($display_title)) { $t->assign('title', $display_title); } $t->assign('error', $display_error); $t->assign('admin_email', $this->di->config->get('admin_email')); if (defined('AM_DEBUG') && AM_DEBUG) { $t->assign('trace', $e->getTraceAsString()); } $t->display("error.phtml"); // log error if (!method_exists($e, 'getLogError') || $e->getLogError()) { $this->di->errorLogTable->logException($e); } } catch (Exception $e) { echo $e . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); } exit; }
function __exception(Exception $e) { if ($e instanceof Zend_Controller_Dispatcher_Exception && preg_match('/^Invalid controller specified/', $e->getMessage())) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } if ($e->getCode() == 404) { return $this->__exception404(Zend_Controller_Front::getInstance()->getResponse()); } try { static $in_fatal_error; //! $in_fatal_error++; if ($in_fatal_error > 2) { echo nl2br("<b>\n\n" . __METHOD__ . " called twice\n\n</b>"); exit; } if (defined('AM_DEBUG') && AM_DEBUG || APPLICATION_ENV == 'testing') { $display_error = "<pre>" . $e . ':' . $e->getMessage() . "</pre>"; } else { if ($e instanceof Am_Exception) { $display_error = $e->getPublicError(); } elseif ($e instanceof Zend_Controller_Dispatcher_Exception) { $display_error = ___("Error 404 - Not Found"); header("HTTP/1.0 404 Not Found"); } else { $display_error = ___('An internal error happened in the script, please contact webmaster for details'); } } $t = new Am_View(); $t->assign('is_html', true); // must be already escaped here! $t->assign('error', $display_error); $t->assign('admin_email', $this->di->config->get('admin_email')); if (defined('AM_DEBUG') && AM_DEBUG) { $t->assign('trace', $e->getTraceAsString()); } $t->display("error.phtml"); // log error if (!method_exists($e, 'getLogError') || $e->getLogError()) { $this->di->errorLogTable->logException($e); } } catch (Exception $e) { echo $e . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine(); } exit; }
public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) { try { $invoiceLog = $this->_logDirectAction($request, $response, $invokeArgs); $transaction = $this->createTransaction($request, $response, $invokeArgs); if (!$transaction) { throw new Am_Exception_InputError("Request not handled - createTransaction() returned null"); } $transaction->setInvoiceLog($invoiceLog); try { $transaction->process(); } catch (Exception $e) { if ($invoiceLog) { $invoiceLog->add($e); } throw $e; } if ($invoiceLog) { $invoiceLog->setProcessed(); } //show thanks page without redirect if ($transaction->isFirst()) { $this->displayThanks($request, $response, $invokeArgs, $transaction->getInvoice()); } } catch (Exception $e) { $message = $e->getMessage(); $view = new Am_View($this->getDi()); $view->assign('error', $e->getMessage()); $view->assign('is_html', false); $view->placeholder("head-start")->prepend(sprintf('<base href="%s://%s" />', empty($_SERVER['HTTPS']) ? 'http' : 'https', Am_Controller::escape($_SERVER['HTTP_HOST']))); $this->invoice = $transaction->getInvoice(); $view->placeholder("head-start")->prepend(sprintf('<meta http-equiv="refresh" content="0;url=%s">', $this->getCancelUrl())); $view->display('error.phtml'); } }
private function getReplyForm($ticket_id, $message = null, $type = 'message') { $content = ''; $hiddens = ''; if (!is_null($message) && $type == 'message') { $content = explode("\n", $message->content); $content = array_map(create_function('$v', 'return \'>\'.$v;'), $content); $content = "\n\n" . implode("\n", $content); } elseif (!is_null($message) && $type == 'comment') { $content = $message->content; $hiddens .= sprintf('<input type="hidden" name="message_id" value="%d" />', $message->message_id); } $t = new Am_View(); $t->assign('content', $content); $t->assign('type', $type); $t->assign('hiddens', $hiddens); $t->assign('ticket_id', $ticket_id); return $t->display($this->strategy->getTemplatePath() . '/_reply-form.phtml'); }