/**
  * Fetch transaction details info
  *
  * Update transaction info if there is one placing transaction only
  *
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param string $transactionId
  * @return array
  */
 public function fetchTransactionInfo(\Magento\Payment\Model\InfoInterface $payment, $transactionId)
 {
     $transaction = $this->transactionRepository->getByTransactionId($transactionId, $payment->getId(), $payment->getOrder()->getId());
     $response = $this->getTransactionResponse($transactionId);
     if ($response->getXResponseCode() == self::RESPONSE_CODE_APPROVED) {
         if ($response->getTransactionStatus() == 'voided') {
             $payment->setIsTransactionDenied(true);
             $payment->setIsTransactionClosed(true);
             $transaction->close();
         } else {
             $transaction->setAdditionalInformation(self::TRANSACTION_FRAUD_STATE_KEY, false);
             $payment->setIsTransactionApproved(true);
         }
     } elseif ($response->getXResponseReasonCode() == self::RESPONSE_REASON_CODE_PENDING_REVIEW_DECLINED) {
         $payment->setIsTransactionDenied(true);
     }
     $this->addStatusCommentOnUpdate($payment, $response, $transactionId);
     return [];
 }
 /**
  * Captures specified amount
  *
  * @param InfoInterface $payment
  * @param string $amount
  * @return $this
  * @throws LocalizedException
  */
 public function capture(InfoInterface $payment, $amount)
 {
     try {
         /** @var \Magento\Sales\Model\Order\Payment $payment */
         if ($payment->getCcTransId()) {
             $collection = $this->salesTransactionCollectionFactory->create()->addFieldToFilter('payment_id', $payment->getId())->addFieldToFilter('txn_type', PaymentTransaction::TYPE_CAPTURE);
             if ($collection->getSize() > 0) {
                 $this->partialCapture($payment, $amount);
             } else {
                 $result = $this->braintreeTransaction->submitForSettlement($payment->getCcTransId(), $amount);
                 $this->_debug([$payment->getCcTransId() . ' - ' . $amount]);
                 $this->_debug($this->_convertObjToArray($result));
                 if ($result->success) {
                     $payment->setIsTransactionClosed(false)->setShouldCloseParentTransaction(false);
                     if ($this->isFinalCapture($payment->getParentId(), $amount)) {
                         $payment->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;
 }
示例#3
0
 /**
  * Void payment
  * Void is in regards to the payment on the order invoice - to void the authorization, for instance - so that
  * the funds aren't subsequently captured. Payments have to be refunded after capture and cannot be voided.
  *
  * map this operation to APPROVEREVERSAL
  *
  * @param \Magento\Framework\DataObject|InfoInterface|\Magento\Sales\Model\Order\Payment $payment
  *
  * @return $this
  * @throws \Exception
  * @api
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function void(\Magento\Payment\Model\InfoInterface $payment)
 {
     if (!$this->_dataHelper->isBackendAvailable()) {
         return $this;
     }
     $orderNumber = $payment->getAdditionalInformation('orderNumber');
     if (!strlen($orderNumber)) {
         /* dont throw an exception here, might be a pending payment */
         $this->_logger->debug(__METHOD__ . ':No order number found.');
         return $this;
     }
     $orderDetails = $this->getOrderDetails($orderNumber);
     $backendClient = $this->_dataHelper->getBackendClient();
     $approveDone = false;
     foreach ($orderDetails->getOrder()->getPayments() as $wdPayment) {
         /** @var \WirecardCEE_QPay_Response_Toolkit_Order_Payment $wdPayment */
         $this->_logger->debug(__METHOD__ . ':operations allowed:' . implode(',', $wdPayment->getOperationsAllowed()));
         if (in_array('APPROVEREVERSAL', $wdPayment->getOperationsAllowed())) {
             $this->_logger->debug(__METHOD__ . ":{$orderNumber}");
             $ret = $backendClient->approveReversal($orderNumber);
             if ($ret->hasFailed()) {
                 throw new \Exception($ret->getError()->getMessage());
             }
             $approveDone = true;
             $orderTransaction = $this->_transactionRepository->getByTransactionType(Transaction::TYPE_ORDER, $payment->getId(), $payment->getOrder()->getId());
             if ($orderTransaction) {
                 $payment->setParentTransactionId($orderTransaction->getTxnId());
                 $payment->setTransactionId($orderTransaction->getTxnId() . '-void');
             }
             $payment->addTransactionCommentsToOrder($orderTransaction, 'approveReversal');
         }
     }
     if (!$approveDone) {
         throw new \Exception($this->_dataHelper->__('Void not possible anymore for this payment, please try cancel instead!'));
     }
     return $this;
 }