Пример #1
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;
 }
 /**
  * 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;
 }
Пример #3
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     $log->add($this->request);
     $this->response = $this->request->send();
     $log->add($this->response);
     $this->validateResponseStatus($this->result);
     if ($this->result->isFailure()) {
         return;
     }
     try {
         $this->parseResponse();
         // validate function must set success status
         $this->validate();
         if ($this->result->isSuccess()) {
             $this->processValidated();
         }
     } catch (Exception $e) {
         if ($e instanceof PHPUnit_Framework_Error) {
             throw $e;
         }
         if ($e instanceof PHPUnit_Framework_Asser) {
             throw $e;
         }
         if (!$result->isFailure()) {
             $result->setFailed(___("Payment failed"));
         }
         $log->add($e);
     }
 }
Пример #4
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     $request = $this->getRequest();
     $log->add($request);
     $this->paysystemResponse = $this->submitTransaction($request);
     $log->add($this->paysystemResponse);
     if ($this->paysystemResponse->success) {
         try {
             $result->setSuccess($this);
             $this->processValidated();
         } catch (Exception $e) {
             if ($e instanceof PHPUnit_Framework_Error) {
                 throw $e;
             }
             if ($e instanceof PHPUnit_Framework_Asser) {
                 throw $e;
             }
             if (!$result->isFailure()) {
                 $result->setFailed(___("Payment failed"));
             }
             $log->add($e);
         }
     } else {
         if ($errors = $this->paysystemResponse->errors->deepAll()) {
             if (!is_array($errors)) {
                 $errors = array($errors);
             }
             foreach ($errors as $error) {
                 $error_text .= $error->message;
             }
             $result->setFailed("Error: " . $errors);
         } else {
             if ($this->paysystemResponse->transaction->status == 'processor_declined') {
                 $result->setFailed("Declined: " . $this->paysystemResponse->transaction->processorResponseText);
             } else {
                 $result->setFailed("Gateway Rejected: " . $this->paysystemResponse->transaction->gatewayRejectionReason);
             }
         }
     }
 }
Пример #5
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     try {
         $soapClient = new SoapClient_Cybersource($this->getPlugin());
     } catch (Exception $ex) {
         throw new Am_Exception_InternalError("Cannot create soapclient object: " . $ex->getMessage());
     }
     $soapResult = $soapClient->runTransaction($this->soapData);
     $this->response = json_decode(json_encode($soapResult), true);
     $log->add($this->response);
     $this->validateResponseStatus($this->result);
     if ($this->result->isFailure()) {
         return;
     }
     try {
         $this->parseResponse();
         $this->validate();
         if ($this->result->isSuccess()) {
             $this->processValidated();
         }
     } catch (Exception $e) {
         if ($e instanceof PHPUnit_Framework_Error) {
             throw $e;
         }
         if ($e instanceof PHPUnit_Framework_Asser) {
             throw $e;
         }
         if (!$result->isFailure()) {
             $result->setFailed(___("Payment failed"));
         }
         $log->add($e);
     }
 }