/**
  * 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;
 }
예제 #2
0
 function repeatAction()
 {
     if (!$this->invoice) {
         throw new Am_Exception_InputError('No invoice found, cannot repeat');
     }
     if ($this->invoice->isPaid()) {
         throw new Am_Exception_InputError("Invoice #{$id} is already paid");
     }
     $found = false;
     foreach ($this->view->paysystems as $ps) {
         if ($ps['paysys_id'] == $this->getFiltered('paysys_id')) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         return $this->indexAction();
     }
     $this->invoice->updateQuick('paysys_id', $this->getFiltered('paysys_id'));
     if ($err = $this->invoice->validate()) {
         throw new Am_Exception_InputError($err[0]);
     }
     $payProcess = new Am_Paysystem_PayProcessMediator($this, $this->invoice);
     $result = $payProcess->process();
     if ($result->isFailure()) {
         $this->view->error = $result->getErrorMessages();
         return $this->indexAction();
     }
 }
예제 #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $model = new Invoice($this->action->id);
     if (isset($_POST['Invoice'])) {
         // collect user input data
         $model->attributes = $_POST['Invoice'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The new invoice record number "{invoiceNumber}" has been successfully created.', array('{invoiceNumber}' => MHtml::wrapInTag($model->id, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     } else {
         // pre-assigned attributes (default values for a new record)
         if (isset($_GET['companyId'])) {
             // company is known
             $model->companyId = $_GET['companyId'];
         }
     }
     $this->render($this->action->id, array('model' => $model));
 }
 protected function _addPendingInvoiceAndSend(Invoice $invoice, Am_Form $form, $vars)
 {
     if ($vars['paysys_id']) {
         try {
             $invoice->setPaysystem($vars['paysys_id'], false);
         } catch (Am_Exception_InputError $e) {
             $form->setError($e->getMessage());
             return false;
         }
     }
     $errors = $invoice->validate();
     if ($errors) {
         $form->setError(current($errors));
         return false;
     }
     $invoice->data()->set('added-by-admin', $this->getDi()->authAdmin->getUserId());
     $invoice->due_date = $vars['tm_due'];
     $invoice->save();
     $et = Am_Mail_Template::load('invoice_pay_link', $invoice->getUser()->lang ? $invoice->getUser()->lang : null);
     $et->setUser($invoice->getUser());
     $et->setUrl(ROOT_SURL . sprintf('/pay/%s', $invoice->getSecureId('payment-link')));
     $et->setMessage($vars['message']);
     $et->setInvoice($invoice);
     $et->setInvoice_text($invoice->render());
     $et->send($invoice->getUser());
     return true;
 }
예제 #5
0
파일: page.php 프로젝트: 0x0049/invoicer
 /**
  * Update or create an invoice.
  *
  * @param bool       $creating
  * @param array      $new_data Data to update or create the invoice with.
  */
 private function save_invoice($creating, $new_data)
 {
     // Validate the invoice, find what needs to be updated.
     // $this->invoice will also be updated so if we display it
     // it will have the latest user-submitted data.
     $result = Invoice::validate($creating, $new_data, $this->invoice, $this->current_user[InvoicerDB::USER_ID]);
     // Database error.
     if ($result === null) {
         $this->set_page_to_error();
         return;
     }
     // Validation error.
     if (!empty($result['errors'])) {
         $this->field_errors = $result['errors'];
         return;
     }
     // Nothing changed.
     if (empty($result['update'])) {
         $this->success_message = 'Nothing changed';
         return;
     }
     // Try updating/inserting.
     $database = InvoicerDB::instance();
     $update_result = $database->update_invoice($creating ? null : $this->invoice[InvoicerDB::INVOICE_ID], $result['update'], $result['insert_rows'], $result['update_rows']);
     // Database error.
     if ($update_result === null || $update_result === false) {
         $this->set_page_to_error();
         return;
     }
     // Saved successfully - redirect if any slugs or the title changed (always true when creating).
     if (isset($result['update'][InvoicerDB::INVOICE_SLUG]) || isset($result['update'][InvoicerDB::COMPANY_ID]) || isset($result['update'][InvoicerDB::INVOICE_TITLE])) {
         $reason = $creating ? 'created' : 'updated';
         $company = $database->get_company_by(InvoicerDB::COMPANY_ID, $new_data[InvoicerDB::COMPANY_ID]);
         if (empty($company)) {
             $this->set_page_to_error();
             return;
         }
         header('Location: ' . $this->url . '/' . $company[InvoicerDB::COMPANY_SLUG] . '/' . $this->invoice[InvoicerDB::INVOICE_SLUG] . '/?reason=' . $reason);
         exit;
     } else {
         $this->success_message = 'Invoice updated';
     }
 }