Exemple #1
0
 /**
  * Captures specified amount, override the method in Braintree CC method as transaction through PayPal does not
  * can't be cloned
  *
  * @param InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws LocalizedException
  */
 public function capture(InfoInterface $payment, $amount)
 {
     try {
         /** @var \Magento\Sales\Model\Order\Payment $payment */
         if ($payment->getCcTransId()) {
             $result = $this->braintreeTransaction->submitForSettlement($payment->getCcTransId(), $amount);
             $this->_debug([$payment->getCcTransId() . ' - ' . $amount]);
             $this->_debug($this->_convertObjToArray($result));
             if ($result->success) {
                 $payment->setIsTransactionClosed(false)->setShouldCloseParentTransaction(true);
             } else {
                 throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
             }
         } else {
             $this->braintreeAuthorize($payment, $amount, true);
         }
     } catch (\Exception $e) {
         $this->_logger->critical($e);
         throw new LocalizedException(__('There was an error capturing the transaction: %1.', $e->getMessage()));
     }
     return $this;
 }
 /**
  * Perform the payment review
  *
  * @param InfoInterface $payment
  * @param string $action
  * @return bool
  */
 public function reviewPayment(InfoInterface $payment, $action)
 {
     $request = $this->buildBasicRequest();
     $transactionId = $payment->getCcTransId() ? $payment->getCcTransId() : $payment->getLastTransId();
     $request->setTrxtype(self::TRXTYPE_ACCEPT_DENY);
     $request->setOrigid($transactionId);
     $request->setUpdateaction($action);
     $response = $this->postRequest($request, $this->getConfig());
     $payment->setAdditionalInformation((array) $response->getData());
     $this->processErrors($response);
     if (!$this->_isTransactionUnderReview($response->getOrigresult())) {
         $payment->setTransactionId($response->getOrigpnref())->setIsTransactionClosed(0);
         if ($response->getOrigresult() == self::RESPONSE_CODE_APPROVED) {
             $payment->setIsTransactionApproved(true);
         } elseif ($response->getOrigresult() == self::RESPONSE_CODE_DECLINED_BY_MERCHANT) {
             $payment->setIsTransactionDenied(true);
         }
     }
     $rawData = $response->getData();
     return $rawData ? $rawData : [];
 }
Exemple #3
0
 /**
  * @param InfoInterface $payment
  * @param string $transactionId
  * @return DataObject
  * @throws LocalizedException
  */
 protected function transactionInquiryRequest(InfoInterface $payment, $transactionId)
 {
     $request = $this->buildBasicRequest();
     $request->setTrxtype(self::TRXTYPE_DELAYED_INQUIRY);
     $transactionId = $payment->getCcTransId() ? $payment->getCcTransId() : $transactionId;
     $request->setOrigid($transactionId);
     $response = $this->postRequest($request, $this->getConfig());
     return $response;
 }
 /**
  * Refunds specified amount
  *
  * @param InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws LocalizedException
  */
 public function refund(InfoInterface $payment, $amount)
 {
     $transactionId = $this->braintreeHelper->clearTransactionId($payment->getRefundTransactionId());
     try {
         $transaction = $this->braintreeTransaction->find($transactionId);
         $this->_debug([$payment->getCcTransId()]);
         $this->_debug($this->_convertObjToArray($transaction));
         if ($transaction->status === \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             if ($transaction->amount != $amount) {
                 $message = __('This refund is for a partial amount but the Transaction has not settled.')->getText();
                 $message .= ' ';
                 $message .= __('Please wait 24 hours before trying to issue a partial refund.')->getText();
                 throw new LocalizedException(__($message));
             }
         }
         $canVoid = $transaction->status === \Braintree_Transaction::AUTHORIZED || $transaction->status === \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT;
         $result = $canVoid ? $this->braintreeTransaction->void($transactionId) : $this->braintreeTransaction->refund($transactionId, $amount);
         $this->_debug($this->_convertObjToArray($result));
         if ($result->success) {
             $payment->setIsTransactionClosed(true);
         } else {
             throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
         }
     } catch (\Exception $e) {
         $message = $e->getMessage();
         throw new LocalizedException(__('There was an error refunding the transaction: %1.', $message));
     }
     return $this;
 }