/** * Save order into registry to use it in the overloaded controller. * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { /* @var $order Order */ $order = $observer->getEvent()->getData('order'); $this->authorizenetData->updateOrderEditIncrements($order); return $this; }
/** * Update all edit increments for all orders if module is enabled. * Needed for correct work of edit orders in Admin area. * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function updateAllEditIncrements(\Magento\Framework\Event\Observer $observer) { /* @var $order \Magento\Sales\Model\Order */ $order = $observer->getEvent()->getData('order'); $this->_authorizenetData->updateOrderEditIncrements($order); return $this; }
/** * Post request to gateway and return response * * @param \Magento\Authorizenet\Model\Request $request * @return \Magento\Authorizenet\Model\Response * @throws \Magento\Framework\Exception\LocalizedException */ protected function postRequest(\Magento\Authorizenet\Model\Request $request) { $result = $this->responseFactory->create(); /** @var \Magento\Framework\HTTP\ZendClient $client */ $client = $this->httpClientFactory->create(); $url = $this->getConfigData('cgi_url') ?: self::CGI_URL; $debugData = ['url' => $url, 'request' => $request->getData()]; $client->setUri($url); $client->setConfig(['maxredirects' => 0, 'timeout' => 30]); foreach ($request->getData() as $key => $value) { $request->setData($key, str_replace(self::RESPONSE_DELIM_CHAR, '', $value)); } $request->setXDelimChar(self::RESPONSE_DELIM_CHAR); $client->setParameterPost($request->getData()); $client->setMethod(\Zend_Http_Client::POST); try { $response = $client->request(); $responseBody = $response->getBody(); $debugData['response'] = $responseBody; } catch (\Exception $e) { $result->setXResponseCode(-1)->setXResponseReasonCode($e->getCode())->setXResponseReasonText($e->getMessage()); throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($e->getMessage())); } finally { $this->_debug($debugData); } $r = explode(self::RESPONSE_DELIM_CHAR, $responseBody); if ($r) { $result->setXResponseCode((int) str_replace('"', '', $r[0]))->setXResponseReasonCode((int) str_replace('"', '', $r[2]))->setXResponseReasonText($r[3])->setXAvsCode($r[5])->setXTransId($r[6])->setXInvoiceNum($r[7])->setXAmount($r[9])->setXMethod($r[10])->setXType($r[11])->setData('x_MD5_Hash', $r[37])->setXAccountNumber($r[50]); } else { throw new \Magento\Framework\Exception\LocalizedException(__('Something went wrong in the payment gateway.')); } return $result; }
/** * @param bool $responseCode * * @expectedException \Magento\Framework\Exception\LocalizedException * @dataProvider checkResponseCodeFailureDataProvider */ public function testCheckResponseCodeFailure($responseCode) { $reasonText = 'reason text'; $this->responseMock->expects($this->once())->method('getXResponseCode')->willReturn($responseCode); $this->responseMock->expects($this->any())->method('getXResponseReasonText')->willReturn($reasonText); $this->dataHelperMock->expects($this->any())->method('wrapGatewayError')->with($reasonText)->willReturn(__('Gateway error: ' . $reasonText)); $this->directpost->checkResponseCode(); }
/** * @covers \Magento\Authorizenet\Model\Directpost::refund() * @return void */ public function testSuccessRefund() { $card = 1111; $this->paymentMock->expects(static::exactly(2))->method('getCcLast4')->willReturn($card); $this->paymentMock->expects(static::once())->method('decrypt')->willReturn($card); $this->paymentMock->expects(static::exactly(3))->method('getParentTransactionId')->willReturn(self::TRANSACTION_ID . '-capture'); $this->paymentMock->expects(static::once())->method('getPoNumber')->willReturn(self::INVOICE_NUM); $this->paymentMock->expects(static::once())->method('setIsTransactionClosed')->with(true)->willReturnSelf(); $orderMock = $this->getOrderMock(); $this->paymentMock->expects(static::exactly(2))->method('getOrder')->willReturn($orderMock); $transactionMock = $this->getMockBuilder(Order\Payment\Transaction::class)->disableOriginalConstructor()->setMethods(['getAdditionalInformation'])->getMock(); $transactionMock->expects(static::once())->method('getAdditionalInformation')->with(Directpost::REAL_TRANSACTION_ID_KEY)->willReturn(self::TRANSACTION_ID); $this->transactionRepositoryMock->expects(static::once())->method('getByTransactionId')->willReturn($transactionMock); $response = $this->getRefundResponseBody(Directpost::RESPONSE_CODE_APPROVED, Directpost::RESPONSE_REASON_CODE_APPROVED, 'Successful'); $this->httpClientMock->expects(static::once())->method('getBody')->willReturn($response); $this->responseMock->expects(static::once())->method('getXResponseCode')->willReturn(Directpost::RESPONSE_CODE_APPROVED); $this->responseMock->expects(static::once())->method('getXResponseReasonCode')->willReturn(Directpost::RESPONSE_REASON_CODE_APPROVED); $this->dataHelperMock->expects(static::never())->method('wrapGatewayError'); $this->directpost->refund($this->paymentMock, self::TOTAL_AMOUNT); }
/** * Process exceptions for gateway action with a lot of transactions * * @param \Magento\Payment\Model\Info $payment * @param string $messages * @param bool $isSuccessfulTransactions * @return void * @throws \Magento\Framework\Model\Exception */ protected function _processFailureMultitransactionAction($payment, $messages, $isSuccessfulTransactions) { if ($isSuccessfulTransactions) { $messages[] = __('Gateway actions are locked because the gateway cannot complete ' . 'one or more of the transactions. ' . 'Please log in to your Authorize.Net account to manually resolve the issue(s).'); /** * If there is successful transactions we can not to cancel order but * have to save information about processed transactions in order`s comments and disable * opportunity to voiding\capturing\refunding in future. Current order and payment will not be saved because we have to * load new order object and set information into this object. */ $currentOrderId = $payment->getOrder()->getId(); $copyOrder = $this->_orderFactory->create()->load($currentOrderId); $copyOrder->getPayment()->setAdditionalInformation($this->_isGatewayActionsLockedKey, 1); foreach ($messages as $message) { $copyOrder->addStatusHistoryComment($message); } $copyOrder->save(); } throw new \Magento\Framework\Model\Exception($this->_authorizenetData->convertMessagesToMessage($messages)); }
/** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Sales\Model\OrderFactory $orderFactory * @param \Magento\Backend\Model\UrlInterface $backendUrl */ public function __construct(Context $context, StoreManagerInterface $storeManager, OrderFactory $orderFactory, UrlInterface $backendUrl) { parent::__construct($context, $storeManager, $orderFactory); $this->_urlBuilder = $backendUrl; }
/** * @param string $code * @param string $expected * * @dataProvider getTransactionStatusLabelDataProvider */ public function testGetTransactionStatusLabel($code, $expected) { $this->assertSame($expected, (string) $this->dataHelper->getTransactionStatusLabel($code)); }