Esempio n. 1
0
 private function newTransaction(PaymentSources &$paymentSource, $params = array())
 {
     if ($paymentSource->hasPaymentProcessor()) {
         $processor = PaymentProcessors::findFirstById($paymentSource->payment_processor_id);
     } else {
         $processor = PaymentProcessors::findFirst();
     }
     if (!$processor) {
         throw new \Phalcon\Exception('You do not have any payment processors.');
     }
     $transaction = $processor->createTransaction($params);
     $transaction->payment_source_id = $paymentSource->id;
     return $transaction;
 }
 /**
  * Loads the processor instance, handles errors and redirects in the case of an error
  *
  * @param string $processor
  * @return PaymentProcessor
  */
 protected function _loadPaymentProcessor($processor)
 {
     try {
         list($plugin, $class) = pluginSplit($processor, true);
         if (substr($class, -9) != 'Processor') {
             $class = $class . 'Processor';
         }
         $sandboxMode = false;
         $config = Configure::read($class);
         if (isset($config['sandboxMode']) && isset($config['sandbox'])) {
             $config = $config['sandbox'];
             $sandboxMode = true;
         } elseif (isset($config['live'])) {
             $config = $config['live'];
         }
         $Processor = PaymentProcessors::load($processor, $config, array('CakeRequest' => $this->request, 'CakeResponse' => $this->response));
         $Processor->sandboxMode($sandboxMode);
         return $Processor;
     } catch (MissingPaymentProcessorException $e) {
         $this->Session->setFlash(__d('cart', 'The payment method does not exist!'));
         $this->redirect(array('action' => 'view'));
     } catch (Exception $e) {
         $this->Session->setFlash($e->getMessage());
         $this->redirect(array('action' => 'view'));
     }
 }