Exemplo n.º 1
0
 /**
  * Authorizes specified amount
  *
  * @param InfoInterface $payment
  * @param float $amount
  * @param bool $capture
  * @param string $token
  * @return $this
  * @throws LocalizedException
  */
 protected function braintreeAuthorize(InfoInterface $payment, $amount, $capture, $token = null)
 {
     try {
         $transactionParams = $this->populateAuthorizeRequest($payment, $token);
         if ($capture) {
             $transactionParams['options']['submitForSettlement'] = true;
         }
         $transactionParams['amount'] = $amount;
         $this->_debug($transactionParams);
         try {
             $result = $this->braintreeTransaction->sale($transactionParams);
             $this->_debug($this->_convertObjToArray($result));
         } catch (\Exception $e) {
             $this->_logger->critical($e);
             throw new LocalizedException(__('Please try again later'));
         }
         if ($result->success) {
             $this->setStore($payment->getOrder()->getStoreId());
             $this->processSuccessResult($payment, $result, $amount);
         } else {
             throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
         }
     } catch (LocalizedException $e) {
         $this->_registry->unregister(self::REGISTER_NAME);
         throw $e;
     }
     return $this;
 }