public function testPlaceActionAuthorizeCapture() { $newOrderStatus = 'new_status'; $customerNote = 'blabla'; $sum = 10; $this->orderMock->expects($this->any())->method('getTotalDue')->willReturn($sum); $this->orderMock->expects($this->any())->method('getBaseTotalDue')->willReturn($sum); $this->helperMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($this->paymentMethodMock)); $this->paymentMethodMock->expects($this->once())->method('getConfigPaymentAction')->willReturn(\Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE); $this->paymentMethodMock->expects($this->any())->method('getConfigData')->with('order_status', null)->willReturn($newOrderStatus); $statusHistory = $this->getMockForAbstractClass('Magento\\Sales\\Api\\Data\\OrderStatusHistoryInterface'); $this->invoiceMock->expects($this->once())->method('register')->willReturnSelf(); $this->invoiceMock->expects($this->once())->method('capture')->willReturnSelf(); $this->paymentMethodMock->expects($this->once())->method('canCapture')->willReturn(true); $this->orderMock->expects($this->any())->method('prepareInvoice')->willReturn($this->invoiceMock); $this->orderMock->expects($this->once())->method('addRelatedObject')->with($this->invoiceMock); $this->orderMock->expects($this->any())->method('getCustomerNote')->willReturn($customerNote); $this->orderMock->expects($this->any())->method('addStatusHistoryComment')->with($customerNote)->willReturn($statusHistory); $this->mockGetDefaultStatus(Order::STATE_PROCESSING, $newOrderStatus, ['first', 'second']); $this->orderMock->expects($this->any())->method('setState')->with(Order::STATE_PROCESSING)->willReturnSelf(); $this->orderMock->expects($this->any())->method('setStatus')->with($newOrderStatus)->willReturnSelf(); $this->paymentMethodMock->expects($this->once())->method('getConfigPaymentAction')->willReturn(null); $this->assertEquals($this->payment, $this->payment->place()); $this->assertEquals($this->invoiceMock, $this->payment->getCreatedInvoice()); $this->assertEquals($sum, $this->payment->getAmountAuthorized()); $this->assertEquals($sum, $this->payment->getBaseAmountAuthorized()); }
/** * @param \Magento\Sales\Model\Order\Payment $payment * @param \Magento\Framework\DataObject $response * @param string $transactionId * @return $this */ protected function addStatusCommentOnUpdate(\Magento\Sales\Model\Order\Payment $payment, \Magento\Framework\DataObject $response, $transactionId) { if ($payment->getIsTransactionApproved()) { $message = __('Transaction %1 has been approved. Amount %2. Transaction status is "%3"', $transactionId, $payment->getOrder()->getBaseCurrency()->formatTxt($payment->getAmountAuthorized()), $this->dataHelper->getTransactionStatusLabel($response->getTransactionStatus())); $payment->getOrder()->addStatusHistoryComment($message); } elseif ($payment->getIsTransactionDenied()) { $message = __('Transaction %1 has been voided/declined. Transaction status is "%2". Amount %3.', $transactionId, $this->dataHelper->getTransactionStatusLabel($response->getTransactionStatus()), $payment->getOrder()->getBaseCurrency()->formatTxt($payment->getAmountAuthorized())); $payment->getOrder()->addStatusHistoryComment($message); } return $this; }
/** * {@inheritdoc} */ public function getAmountAuthorized() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAmountAuthorized'); if (!$pluginInfo) { return parent::getAmountAuthorized(); } else { return $this->___callPlugins('getAmountAuthorized', func_get_args(), $pluginInfo); } }