/** * @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(); }
/** * Create mock for response factory * @return void */ private function initResponseFactoryMock() { $this->responseFactoryMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Response\\Factory')->disableOriginalConstructor()->getMock(); $this->responseMock = $this->getMockBuilder('Magento\\Authorizenet\\Model\\Directpost\\Response')->setMethods(['isValidHash', 'getXTransId', 'getXResponseCode', 'getXResponseReasonCode', 'getXResponseReasonText', 'getXAmount', 'setXResponseCode', 'setXResponseReasonCode', 'setXAvsCode', 'setXResponseReasonText', 'setXTransId', 'setXInvoiceNum', 'setXAmount', 'setXMethod', 'setXType', 'setData', 'setXAccountNumber', '__wakeup'])->disableOriginalConstructor()->getMock(); $this->responseMock->expects(static::any())->method('setXResponseCode')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXResponseReasonCode')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXResponseReasonText')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXAvsCode')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXTransId')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXInvoiceNum')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXAmount')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXMethod')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setXType')->willReturnSelf(); $this->responseMock->expects(static::any())->method('setData')->willReturnSelf(); $this->responseFactoryMock->expects($this->any())->method('create')->willReturn($this->responseMock); }
/** * Process capture request * * @param \Magento\Authorizenet\Model\Directpost\Response $result * @param \Magento\Payment\Model\InfoInterface $payment * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ protected function processCapture($result, $payment) { switch ($result->getXResponseCode()) { case self::RESPONSE_CODE_APPROVED: case self::RESPONSE_CODE_HELD: if (in_array($result->getXResponseReasonCode(), [self::RESPONSE_REASON_CODE_APPROVED, self::RESPONSE_REASON_CODE_PENDING_REVIEW, self::RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED])) { if (!$payment->getParentTransactionId() || $result->getXTransId() != $payment->getParentTransactionId()) { $payment->setTransactionId($result->getXTransId()); } $payment->setIsTransactionClosed(0)->setTransactionAdditionalInfo(self::REAL_TRANSACTION_ID_KEY, $result->getXTransId()); return $this; } throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($result->getXResponseReasonText())); case self::RESPONSE_CODE_DECLINED: case self::RESPONSE_CODE_ERROR: throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($result->getXResponseReasonText())); default: throw new \Magento\Framework\Exception\LocalizedException(__('Payment capturing error.')); } }
/** * @param int $xResponseCode * @param bool $expectedValue * @dataProvider isApprovedDataProvider */ public function testIsApproved($xResponseCode, $expectedValue) { $this->responseModel->setXResponseCode($xResponseCode); $this->assertSame($expectedValue, $this->responseModel->isApproved()); }