Exemplo n.º 1
0
 /**
  * @covers \Magento\Paypal\Model\Pro::capture
  */
 public function testCapture()
 {
     $paymentMock = $this->getPaymentMock();
     $orderMock = $this->getOrderMock();
     $this->apiMock->expects(static::any())->method('setAuthorizationId')->willReturnSelf();
     $this->apiMock->expects(static::any())->method('setIsCaptureComplete')->willReturnSelf();
     $this->apiMock->expects(static::any())->method('setAmount')->willReturnSelf();
     $paymentMock->expects(static::once())->method('getOrder')->willReturn($orderMock);
     $this->apiMock->expects(static::once())->method('getTransactionId')->willReturn(45);
     $this->apiMock->expects(static::any())->method('getDataUsingMethod')->willReturn(false);
     $amount = 43.03;
     $this->pro->capture($paymentMock, $amount);
 }
Exemplo n.º 2
0
 /**
  * Capture payment
  *
  * @param \Magento\Framework\Object|Payment $payment
  * @param float $amount
  * @return $this
  */
 public function capture(\Magento\Framework\Object $payment, $amount)
 {
     if (false === $this->_pro->capture($payment, $amount)) {
         $this->_placeOrder($payment, $amount);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Capture payment
  *
  * @param \Magento\Framework\DataObject|InfoInterface|Payment $payment
  * @param float $amount
  * @return $this
  */
 public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     if (false === $this->_pro->capture($payment, $amount)) {
         $this->_placeOrder($payment, $amount);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Capture payment
  *
  * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface|Payment $payment
  * @param float $amount
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $authorizationTransaction = $payment->getAuthorizationTransaction();
     $authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period')));
     $maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number')));
     $order = $payment->getOrder();
     $isAuthorizationCreated = false;
     if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
         $voided = false;
         if (!$authorizationTransaction->getIsClosed() && $this->_isTransactionExpired($authorizationTransaction, $authorizationPeriod)) {
             //Save payment state and configure payment object for voiding
             $isCaptureFinal = $payment->getShouldCloseParentTransaction();
             $payment->setShouldCloseParentTransaction(false);
             $payment->setParentTransactionId($authorizationTransaction->getTxnId());
             $payment->unsTransactionId();
             $payment->setVoidOnlyAuthorization(true);
             $payment->void(new \Magento\Framework\DataObject());
             //Revert payment state after voiding
             $payment->unsAuthorizationTransaction();
             $payment->unsTransactionId();
             $payment->setShouldCloseParentTransaction($isCaptureFinal);
             $voided = true;
         }
         if ($authorizationTransaction->getIsClosed() || $voided) {
             if ($payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) {
                 $this->_exception->create(['phrase' => __('The maximum number of child authorizations is reached.')]);
             }
             $api = $this->_callDoAuthorize($amount, $payment, $authorizationTransaction->getParentTxnId());
             //Adding authorization transaction
             $this->_pro->importPaymentInfo($api, $payment);
             $payment->setTransactionId($api->getTransactionId());
             $payment->setParentTransactionId($authorizationTransaction->getParentTxnId());
             $payment->setIsTransactionClosed(false);
             $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
             if ($payment->getIsTransactionPending()) {
                 $message = __('We\'ll authorize the amount of %1 as soon as the payment gateway approves it.', $formatedPrice);
             } else {
                 $message = __('The authorized amount is %1.', $formatedPrice);
             }
             $transaction = $this->transactionBuilder->setPayment($payment)->setOrder($order)->setTransactionId($payment->getTransactionId())->setFailSafe(true)->build(Transaction::TYPE_AUTH);
             $payment->addTransactionCommentsToOrder($transaction, $message);
             $payment->setParentTransactionId($api->getTransactionId());
             $isAuthorizationCreated = true;
         }
         //close order transaction if needed
         if ($payment->getShouldCloseParentTransaction()) {
             $orderTransaction = $this->getOrderTransaction($payment);
             if ($orderTransaction) {
                 $orderTransaction->setIsClosed(true);
                 $order->addRelatedObject($orderTransaction);
             }
         }
     }
     if (false === $this->_pro->capture($payment, $amount)) {
         $this->_placeOrder($payment, $amount);
     }
     if ($isAuthorizationCreated && isset($transaction)) {
         $transaction->setIsClosed(true);
     }
     return $this;
 }