/**
  * This function is likely never returns
  * but anyway handle result and exceptions
  * @return Am_Paysystem_Result
  */
 function process()
 {
     $err = $this->invoice->validate();
     if ($err) {
         throw new Am_Exception_InputError($err[0]);
     }
     $this->invoice->save();
     $plugin = Am_Di::getInstance()->plugins_payment->loadGet($this->invoice->paysys_id);
     $this->result = new Am_Paysystem_Result();
     $plugin->processInvoice($this->invoice, $this->controller->getRequest(), $this->result);
     if ($this->result->isSuccess() || $this->result->isFailure()) {
         if ($transaction = $this->result->getTransaction()) {
             $transaction->setInvoice($this->invoice);
             $transaction->process();
         }
     }
     if ($this->result->isSuccess()) {
         $url = REL_ROOT_URL . "/thanks?id=" . $this->invoice->getSecureId('THANKS');
         $this->callback($this->onSuccess);
         $this->controller->redirectLocation($url, ___("Invoice processed"), ___("Invoice processed successfully"));
         // no return Am_Exception_Redirect
     } elseif ($this->result->isAction()) {
         $this->callback($this->onAction);
         $this->result->getAction()->process($this->controller);
         // no return Am_Exception_Redirect
     } else {
         //  ($result->isFailure()) {
         $this->callback($this->onFailure);
     }
     return $this->result;
 }
Ejemplo n.º 2
0
 /**
  * This function is likely never returns
  * but anyway handle result and exceptions
  * @return Am_Paysystem_Result
  */
 function process()
 {
     Am_Di::getInstance()->hook->call(Am_Event::INVOICE_BEFORE_PAYMENT, array('invoice' => $this->invoice, 'controller' => $this->controller));
     $plugin = Am_Di::getInstance()->plugins_payment->loadGet($this->invoice->paysys_id);
     $this->result = new Am_Paysystem_Result();
     $plugin->processInvoice($this->invoice, $this->controller->getRequest(), $this->result);
     if ($this->result->isSuccess() || $this->result->isFailure()) {
         if ($transaction = $this->result->getTransaction()) {
             $transaction->setInvoice($this->invoice);
             $transaction->process();
         }
     }
     if ($this->result->isSuccess()) {
         if (method_exists($this->controller, 'getForm')) {
             $this->controller->getForm()->getSessionContainer()->destroy();
         }
         $url = REL_ROOT_URL . "/thanks?id=" . $this->invoice->getSecureId('THANKS');
         $this->callback($this->onSuccess);
         $this->controller->redirectLocation($url);
         // no return
         // Am_Exception_Redirect only for APPLICATION_ENV = 'testing'
     } elseif ($this->result->isAction()) {
         if (method_exists($this->controller, 'getForm')) {
             $this->controller->getForm()->getSessionContainer()->destroy();
         }
         $this->callback($this->onAction);
         $this->result->getAction()->process($this->controller);
         // no return
         // Am_Exception_Redirect only for APPLICATION_ENV = 'testing'
     } else {
         //  ($result->isFailure()) {
         $this->callback($this->onFailure);
     }
     return $this->result;
 }
Ejemplo n.º 3
0
 public function onLoadSignupForm(Am_Event $e)
 {
     $type = $this->getDi()->auth->getUserId() ? SavedForm::D_MEMBER : SavedForm::D_SIGNUP;
     if (($r = $e->getReturn()) && $r->isDefault($type) && $this->getConfig('redirect_to_cart')) {
         Am_Controller::redirectLocation(REL_ROOT_URL . '/cart');
     }
 }
Ejemplo n.º 4
0
 function infoTabEcheckAction()
 {
     require_once APPLICATION_PATH . '/default/controllers/AdminUsersController.php';
     $this->setActiveMenu('users-browse');
     $user_id = $this->_request->getInt('user_id');
     if (!$user_id) {
         throw Am_Exception_InputError("Empty [user_id] passsed");
     }
     $echeck = $this->getDi()->echeckRecordTable->findFirstByUserId($user_id);
     $this->view->echeck = $echeck;
     $this->view->addUrl = $this->getUrl(null, null, null, 'user_id', $this->getInt('user_id'), array('add' => 1));
     if ($echeck || $this->_request->getInt('add') || $this->_request->get('_save_')) {
         $form = $this->createEcheckAdminForm((bool) $echeck);
         if ($form) {
             if ($form->isSubmitted() && $form->validate()) {
                 if (!$echeck) {
                     $echeck = $this->getDi()->echeckRecordTable->createRecord();
                 }
                 $form->toEcheckRecord($echeck);
                 $echeck->user_id = $user_id;
                 $echeck->save();
                 Am_Controller::redirectLocation($this->_request->getRequestUri());
             } elseif ($echeck) {
                 $arr = $echeck->toArray();
                 unset($arr['echeck_ban']);
                 $form->addDataSource(new HTML_QuickForm2_DataSource_Array($arr));
             }
             $this->view->form = $form;
             $this->view->form->setAction($this->_request->getRequestUri());
         }
     }
     $this->view->display('admin/echeck/info-tab.phtml');
     // ????
 }
Ejemplo n.º 5
0
 function folderAction()
 {
     $id = $this->_request->getInt('id');
     if (!$id) {
         throw new Am_Exception_InputError("Empty folder#");
     }
     $folder = $this->getDi()->folderTable->load($id);
     if (empty($folder)) {
         throw new Am_Exception_InputError("Folder not found");
     }
     // Check if login cookie exists. If not, user is not logged in and should be redirected to login page.
     $pl = $this->getDi()->plugins_protect->loadGet('new-rewrite');
     // User will be there only if file related to folder doesn't exists.
     // So if main file exists, this means that user is logged in but don't have an access.
     // If main file doesn't exists, redirect user to new-rewrite in order to recreate it.
     // Main file will be created even if user is not active.
     if (is_file($pl->getFilePath($pl->getEscapedCookie()))) {
         $this->view->accessObjectTitle = ___("Folder %s (%s)", $folder->title, $folder->url);
         $this->view->orderUrl = REL_ROOT_URL . '/signup';
         $this->view->display('no-access.phtml');
     } else {
         $url = sprintf("%s/protect/new-rewrite?f=%d&url=%s", REL_ROOT_URL, $id, $this->_request->getParam('url', $folder->getUrl()));
         Am_Controller::redirectLocation($url);
     }
 }
Ejemplo n.º 6
0
 protected function _initSetupForm(Am_Form_Setup $form)
 {
     $url = 'https://auth.aweber.com/1.0/oauth/authorize_app/' . self::APP_ID;
     $el = $form->addTextarea('auth', array('cols' => 80, 'rows' => 4))->setLabel("aWeber App Authorization Code\n" . "get it on <a target='_blank' href='{$url}'>aWeber Website</a>");
     $el->addRule('regex', 'Invalid value', '/^[a-zA-Z0-9]+\\|[a-zA-Z0-9]+\\|[a-zA-Z0-9]+\\|[a-zA-Z0-9]+\\|[a-zA-Z0-9]+\\|\\s*$/');
     if ($this->getConfig('auth') && !$this->getConfig('access.access_token')) {
         if (!empty($_GET['oauth_token'])) {
             $api = $this->getApi();
             $api->user->tokenSecret = $_COOKIE['requestTokenSecret'];
             $api->user->requestToken = $_GET['oauth_token'];
             $api->user->verifier = $_GET['oauth_verifier'];
             list($accessToken, $accessTokenSecret) = $api->getAccessToken();
             $this->getDi()->config->saveValue('newsletter.aweber.access', array('access_token' => $accessToken, 'access_secret' => $accessTokenSecret));
             Am_Controller::redirectLocation(REL_ROOT_URL . "/admin-setup/aweber");
             return;
         } else {
             $api = $this->getApi();
             $callbackUrl = Am_Controller::getFullUrl();
             try {
                 list($requestToken, $requestTokenSecret) = $api->getRequestToken($callbackUrl);
                 Am_Controller::setCookie('requestTokenSecret', $requestTokenSecret);
                 $form->addStatic()->setLabel('Access Tokens')->setContent(sprintf('Access tokens are empty or expired, %sclick this link%s to update', '<a href="' . Am_Controller::escape($api->getAuthorizeUrl()) . '">', '</a>'));
             } catch (Exception $e) {
                 $this->getDi()->errorLogTable->logException($e);
                 $form->addStatic()->setLabel('Access Tokens')->setContent('Plugin configuration error. Got an error from API: ' . $e->getMessage());
             }
         }
     }
     $fields = $this->getDi()->userTable->getFields(true);
     unset($fields['email']);
     unset($fields['name_f']);
     unset($fields['name_l']);
     $ff = $form->addMagicSelect('fields')->setLabel("Pass additional fields to AWeber\nfields must be configured in AWeber with exactly same titles\nelse API calls will fail and users will not be added\n\nBy default the plugin passes \"email\" and \"name\"\nfields to Aweber, so usually you do not need to select \nthat fields to send as additional fields.\n");
     $ff->loadOptions(array_combine($fields, $fields));
 }
Ejemplo n.º 7
0
 public function process(Am_Controller $controller = null)
 {
     if ($controller === null) {
         Am_Controller::redirectLocation($this->getUrl());
     } else {
         $controller->redirectLocation($this->getUrl());
     }
 }
Ejemplo n.º 8
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $user = $this->getDi()->user;
     $id = $this->getDi()->app->reveal($request->getActionName());
     //actualy it is notification_id
     $notification = $this->getDi()->notificationTable->load($id);
     $this->getDi()->notificationClickTable->log($user, $notification);
     Am_Controller::redirectLocation($notification->url);
 }
Ejemplo n.º 9
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     if ('reject' == $request->getActionName()) {
         $invoice = $this->getDi()->invoiceTable->findFirstByPublicId($request->get("orderDescription"));
         $url = $this->getRootUrl() . "/cancel?id=" . $invoice->getSecureId('CANCEL');
         return Am_Controller::redirectLocation($url);
     } else {
         return parent::directAction($request, $response, $invokeArgs);
     }
 }
Ejemplo n.º 10
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $actionName = $request->getActionName();
     if ($actionName == 'fail') {
         $invoice = $this->getDi()->invoiceTable->findFirstByPublicId($request->getParam('m_orderid'));
         if (!$invoice) {
             throw new Am_Exception_InputError();
         }
         return Am_Controller::redirectLocation($this->getRootUrl() . "/cancel?id=" . $invoice->getSecureId('CANCEL'));
     } else {
         return parent::directAction($request, $response, $invokeArgs);
     }
 }
Ejemplo n.º 11
0
 function indexAction()
 {
     if (!$this->getDi()->auth->getUserId()) {
         $this->getDi()->auth->checkExternalLogin($this->getRequest());
     }
     if ($this->getDi()->auth->getUserId() && $this->getDi()->config->get('skip_index_page')) {
         Am_Controller::redirectLocation($this->getUrl('member', 'index'));
     }
     try {
         $p = $this->getDi()->pageTable->load($this->getDi()->config->get('index_page'));
         echo $p->render($this->view, $this->getDi()->auth->getUserId() ? $this->getDi()->auth->getUser() : null);
     } catch (Exception $e) {
         $this->view->display("index.phtml");
     }
 }
Ejemplo n.º 12
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     if ($request->getActionName() == 'ipn') {
         $accessCode = $request->getFiltered('AccessCode');
         $result = new Am_Paysystem_Result();
         $transaction = new Am_Paysystem_Transaction_EwayRapid3($this, $accessCode);
         $transaction->run($result);
         if (!($invoice = $transaction->getInvoice())) {
             throw new Am_Exception_InputError();
         }
         $this->_setInvoice($invoice);
         if ($result->isSuccess()) {
             Am_Controller::redirectLocation($this->getReturnUrl($invoice));
         } else {
             Am_Controller::redirectLocation($this->getCancelUrl($invoice));
         }
     } else {
         parent::directAction($request, $response, $invokeArgs);
     }
 }
Ejemplo n.º 13
0
 public function indexAction()
 {
     $this->_request->setParam('page', 'cart');
     $this->p = filterId($this->_request->getParam('page'));
     $this->initSetupForms();
     $this->form = $this->getForm($this->p, false);
     $this->form->prepare();
     if ($this->form->isSubmitted()) {
         $this->form->setDataSources(array($this->_request));
         if ($this->form->validate() && $this->form->saveConfig()) {
             Am_Controller::redirectLocation($this->getUrl());
         }
     } else {
         $this->form->setDataSources(array(new HTML_QuickForm2_DataSource_Array($this->getConfigValues()), new HTML_QuickForm2_DataSource_Array($this->form->getDefaults())));
     }
     $this->view->assign('p', $this->p);
     $this->form->replaceDotInNames();
     $this->view->assign('pageObj', $this->form);
     $this->view->assign('form', $this->form);
     $this->view->display('admin/cart/config.phtml');
 }
Ejemplo n.º 14
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     if ($url = $request->get('url')) {
         $url = urldecode($url);
     }
     if ($request->get('host') && $request->get('ssl')) {
         $url = (!strcasecmp($request->get('ssl'), 'on') ? 'https://' : 'http://') . $request->get('host') . $url;
         $request->set('url', $url);
     }
     // if user is logged in and went here, something is definitely wrong
     if ($this->getDi()->auth->getUserId()) {
         $this->needRefresh($this->getDi()->auth->getUser());
         if (!parse_url($url, PHP_URL_SCHEME)) {
             $url = sprintf('%s://%s%s', $request->isSecure() ? 'https' : 'http', $request->getHttpHost(), $url);
         }
         Am_Controller::redirectLocation($url);
         return;
     }
     //
     require_once APPLICATION_PATH . '/default/controllers/LoginController.php';
     $c = new LoginController($request, $response, $invokeArgs);
     $c->setRedirectUrl(Am_Controller::escape($url));
     $c->run();
 }
Ejemplo n.º 15
0
 public function process(Am_Controller $controller = null)
 {
     $controller->redirectLocation($this->getUrl());
 }
Ejemplo n.º 16
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $user = $this->getDi()->user;
     switch ($request->getActionName()) {
         case 'c':
             $id = $this->getDi()->app->reveal($request->getFiltered('id'));
             //actualy it is notification_id
             $notification = $this->getDi()->notificationTable->load($id);
             $this->getDi()->notificationClickTable->log($user, $notification);
             Am_Controller::redirectLocation($notification->url);
             break;
         case 'get':
             if (!$user) {
                 Am_Controller::ajaxResponse(array());
             } else {
                 $items = $this->getDi()->notificationTable->getNotificationsForUser($this->getDi()->auth->getUser());
                 $dismiss = $user->data()->getBlob('notification.dismiss');
                 if (!$dismiss) {
                     $dismiss = array();
                 } else {
                     $dismiss = unserialize($dismiss);
                 }
                 $out = array();
                 foreach ($items as $item) {
                     $display = $user->data()->get('notification.display.' . $item->pk());
                     if ($item->limit && $display >= $item->limit) {
                         continue;
                     }
                     if (in_array($item->notification_id, $dismiss)) {
                         continue;
                     }
                     $user->data()->set('notification.display.' . $item->pk(), ++$display);
                     $n = new stdClass();
                     $n->id = $this->getDi()->app->obfuscate($item->notification_id);
                     $n->content = $item->content;
                     $n->is_custom = $item->is_custom ? true : false;
                     $n->is_blank = $item->is_blank ? true : false;
                     $n->link = $item->url;
                     $out[] = $n;
                 }
                 $user->save();
                 Am_Controller::ajaxResponse($out);
             }
             break;
         case 'js':
             $response->setHeader('Content-Type', 'application/x-javascript; charset=utf-8');
             echo $this->getJs();
             break;
         case 'd':
             $id = $this->getDi()->app->reveal($request->getFiltered('id'));
             if ($user && $id) {
                 $dismiss = $user->data()->getBlob('notification.dismiss');
                 if (!$dismiss) {
                     $dismiss = array();
                 } else {
                     $dismiss = unserialize($dismiss);
                 }
                 $dismiss[] = $id;
                 $user->data()->setBlob('notification.dismiss', serialize($dismiss));
                 $user->data()->update();
             }
             break;
         default:
             throw new Am_Exception_InternalError('Unknown Action');
     }
 }
Ejemplo n.º 17
0
 function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $actionName = $request->getActionName();
     if ($actionName == 'cancel') {
         $invoice = $this->getDi()->invoiceTable->findFirstBy(array('public_id' => $request->getFiltered('merchant_unique_id')));
         if (!$invoice) {
             throw new Am_Exception_InputError("No invoice found [{$id}]");
         }
         Am_Controller::redirectLocation($this->getRootUrl() . "/cancel?id=" . $invoice->getSecureId('CANCEL'));
     } else {
         parent::directAction($request, $response, $invokeArgs);
     }
 }
Ejemplo n.º 18
0
 public function disableAutoLockAction()
 {
     $this->getDi()->authAdmin->getUser()->checkPermission('grid_u', 'edit');
     $id = $this->getParam('id');
     $user = $this->getDi()->userTable->load($id);
     if (!$user) {
         throw new Am_Exception_InputError();
     }
     $user->updateQuick('disable_lock_until', sqlTime('+1 day'));
     $b = $this->getParam('b', $this->view->userUrl($user->pk()));
     Am_Controller::redirectLocation($b);
 }
Ejemplo n.º 19
0
 /**
  * By default this method handles request as IPN
  * If actionName=='thanks', it is handled by thanksAction() handler (override createThanksTransaction for that)
  * @param Am_Request $request
  * @param Zend_Controller_Response_Http $response
  * @param array $invokeArgs
  */
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $actionName = $request->getActionName();
     switch ($actionName) {
         case 'thanks':
             $this->thanksAction($request, $response, $invokeArgs);
             break;
         case 'cancel':
             $invoice = $this->getDi()->invoiceTable->findBySecureId($request->getFiltered('id'), 'STOP' . $this->getId());
             if (!$invoice) {
                 throw new Am_Exception_InputError("No invoice found [{$id}]");
             }
             $result = new Am_Paysystem_Result();
             $result->setSuccess();
             $this->cancelAction($invoice, $request->getActionName(), $result);
             if ($result->isSuccess()) {
                 $invoice->setCancelled(true);
                 Am_Controller::redirectLocation(REL_ROOT_URL . '/member/payment-history');
             } elseif ($result->isAction()) {
                 $action = $result->getAction();
                 $action->process();
                 // I cannot imaginge anything but redirect here... yet? :)
             } else {
                 throw new Am_Exception_InputError(___("Unable to cancel subscription: " . $result->getLastError()));
             }
             break;
         default:
             // standard action handling via transactions
             $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();
             }
     }
 }
Ejemplo n.º 20
0
 public function processValidated()
 {
     $this->invoice->addPayment($this);
     Am_Controller::redirectLocation($this->getPlugin()->getReturnUrl($invoice));
 }
Ejemplo n.º 21
0
 public function validateStatus()
 {
     if ($this->request->get("intStatus") != 1) {
         Am_Controller::redirectLocation($this->plugin->getRootUrl() . "/cancel?id=" . $this->invoice->getSecureId('CANCEL'));
     }
     return true;
 }
Ejemplo n.º 22
0
 public function initFilter(Am_Grid_ReadOnly $grid)
 {
     parent::initFilter($grid);
     $query = $grid->getDataSource();
     $query->setPrefix('_u_search');
     /* @var $query Am_Query_User */
     if ($id = $grid->getCompleteRequest()->getInt('_search_del')) {
         $query->deleteSaved($id);
         Am_Controller::redirectLocation(REL_ROOT_URL . '/admin-users');
         exit;
     } elseif ($id = $grid->getRequest()->getInt('search_load')) {
         $query->load($id);
     } elseif (is_string($this->vars['filter']) && $this->vars['filter']) {
         $cond = new Am_Query_User_Condition_Filter();
         $cond->setFromRequest(array('filter' => array('val' => $this->vars['filter'])));
         $event = new Am_Event(Am_Event::ADMIN_USERS_FILTER_INIT, array('query' => $query, 'filter' => $this->vars['filter']));
         $event->setReturn($cond);
         Am_Di::getInstance()->hook->call($event);
         $query->add($event->getReturn());
     } else {
         $query->setFromRequest($grid->getCompleteRequest());
     }
 }
Ejemplo n.º 23
0
 function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     if (!$this->getDi()->auth->getUserId() || !($invoice_id = $this->getDi()->auth->getUser()->data()->get(self::NEED_SHOW_OTO))) {
         throw new Am_Exception_InternalError();
     }
     $user = $this->getDi()->auth->getUser();
     $invoice = $this->getDi()->invoiceTable->load($invoice_id);
     $controller = new Am_Controller($request, $response, $invokeArgs);
     // find first matching upsell
     $oto = $this->getDi()->otoTable->findUpsell($invoice->getProducts());
     if ($controller->getRequest()->get('oto') == 'no') {
         $oto = $this->getDi()->otoTable->findDownsell($invoice->data()->get(self::LAST_OTO_SHOWN));
     }
     if (!$oto) {
         $user->data()->set(self::NEED_SHOW_OTO, null)->update();
         Am_Controller::redirectLocation(REL_ROOT_URL);
     }
     if ($controller->getRequest()->get('oto') == 'yes') {
         $user->data()->set(self::NEED_SHOW_OTO, null)->update();
         return $this->yesOto($controller, $invoice, $this->getDi()->otoTable->load($invoice->data()->get(self::LAST_OTO_SHOWN)));
     }
     $invoice->data()->set(self::LAST_OTO_SHOWN, $oto->pk())->update();
     $html = $oto->render();
     $controller->getResponse()->setBody($html);
     throw new Am_Exception_Redirect();
 }
Ejemplo n.º 24
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     if ($request->getActionName() == 'thanks') {
         return $this->thanksAction($request, $response, $invokeArgs);
     } elseif ($request->getActionName() == 'admin-cancel') {
         return $this->adminCancelAction($request, $response, $invokeArgs);
     } elseif ($request->getActionName() == 'cancel') {
         $invoice = $this->getDi()->invoiceTable->findBySecureId($request->getFiltered('id'), 'STOP' . $this->getId());
         if (!$invoice) {
             throw new Am_Exception_InputError("No invoice found [{$id}]");
         }
         $result = new Am_Paysystem_Result();
         $payment = current($invoice->getPaymentRecords());
         $this->cancelInvoice($payment, $result);
         $invoice->setCancelled(true);
         Am_Controller::redirectLocation(REL_ROOT_URL . '/member/payment-history');
     } else {
         return parent::directAction($request, $response, $invokeArgs);
     }
 }
Ejemplo n.º 25
0
 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");
     }
 }
Ejemplo n.º 26
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     // if user is logged in and went here, something is definitely wrong
     if ($this->getDi()->auth->getUserId()) {
         $this->needRefresh($this->getDi()->auth->getUser());
         if (parse_url($request->getParam('url'), PHP_URL_SCHEME)) {
             $url = $request->getParam('url');
         } else {
             $url = sprintf('%s://%s%s', $request->isSecure() ? 'https' : 'http', $request->getHttpHost(), $request->getParam('url'));
         }
         Am_Controller::redirectLocation($url);
         return;
     }
     //
     require_once APPLICATION_PATH . '/default/controllers/LoginController.php';
     $c = new LoginController($request, $response, $invokeArgs);
     $c->setRedirectUrl($request->getEscaped('url'));
     $c->run();
 }