示例#1
0
 /**
  * Magento will consider a transaction for voiding only if it is an authorization
  * Braintree allows voiding captures too
  *
  * Lookup an authorization transaction using parent transaction id, if set
  *
  * @param Payment $subject
  * @param callable $proceed
  *
  * @return \Magento\Sales\Model\Order\Payment\Transaction|false
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundGetAuthorizationTransaction(Payment $subject, \Closure $proceed)
 {
     if ($subject->getMethodInstance()->getCode() != PaymentMethod::METHOD_CODE) {
         return $proceed();
     }
     $invoice = $this->registry->registry('current_invoice');
     if ($invoice && $invoice->getId()) {
         $transactionId = $this->paymentHelper->clearTransactionId($invoice->getTransactionId());
         $collection = $this->salesTransactionCollectionFactory->create()->addFieldToFilter('txn_id', ['eq' => $transactionId]);
         if ($collection->getSize() < 1) {
             return $proceed();
         } else {
             return $collection->getFirstItem();
         }
     }
     return $proceed();
 }
示例#2
0
 public function testClearTransactionId()
 {
     $result = $this->model->clearTransactionId(1);
     $this->assertEquals(1, $result);
     $result = $this->model->clearTransactionId("1-" . \Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
     $this->assertEquals(1, $result);
     $result = $this->model->clearTransactionId("1-" . \Magento\Sales\Model\Order\Payment\Transaction::TYPE_VOID);
     $this->assertEquals(1, $result);
 }
 /**
  * @param InfoInterface $payment
  * @return array
  */
 protected function getTransactionsToVoid(InfoInterface $payment)
 {
     $transactionIds = [];
     $invoice = $this->_registry->registry('current_invoice');
     if ($invoice && $invoice->getId() && $invoice->getTransactionId()) {
         $transactionIds[] = $this->braintreeHelper->clearTransactionId($invoice->getTransactionId());
     } else {
         $collection = $this->salesTransactionCollectionFactory->create()->addFieldToSelect('txn_id')->addOrderIdFilter($payment->getOrder()->getId())->addTxnTypeFilter([PaymentTransaction::TYPE_AUTH, PaymentTransaction::TYPE_CAPTURE]);
         $fetchedIds = $collection->getColumnValues('txn_id');
         foreach ($fetchedIds as $transactionId) {
             $txnId = $this->braintreeHelper->clearTransactionId($transactionId);
             if (!in_array($txnId, $transactionIds)) {
                 $transactionIds[] = $txnId;
             }
         }
     }
     return $transactionIds;
 }