/** * Performs authorize transaction * * @param InfoInterface|Object $payment * @param float $amount * @return $this * @throws InvalidTransitionException * @throws LocalizedException */ public function authorize(InfoInterface $payment, $amount) { /** @var Payment $payment */ $request = $this->buildBasicRequest(); /** @var \Magento\Sales\Model\Order $order */ $order = $payment->getOrder(); $this->addRequestOrderInfo($request, $order); $request = $this->fillCustomerContacts($order, $request); $token = $payment->getAdditionalInformation(self::PNREF); $request->setData('trxtype', self::TRXTYPE_AUTH_ONLY); $request->setData('origid', $token); $request->setData('amt', $this->formatPrice($amount)); $response = $this->postRequest($request, $this->getConfig()); $this->processErrors($response); try { $this->responseValidator->validate($response, $this); } catch (LocalizedException $exception) { $payment->setParentTransactionId($response->getData(self::PNREF)); $this->void($payment); throw new LocalizedException(__('Error processing payment. Please try again later.')); } $this->setTransStatus($payment, $response); $this->createPaymentToken($payment, $token); $payment->unsAdditionalInformation(self::CC_DETAILS); return $this; }
/** * @return ResultInterface */ public function execute() { $parameters = []; try { $response = $this->transaction->getResponseObject($this->getRequest()->getPostValue()); $this->responseValidator->validate($response, $this->transparent); $this->transaction->savePaymentInQuote($response); } catch (LocalizedException $exception) { $parameters['error'] = true; $parameters['error_msg'] = $exception->getMessage(); } $this->coreRegistry->register(Iframe::REGISTRY_KEY, $parameters); $resultLayout = $this->resultLayoutFactory->create(); $resultLayout->addDefaultHandle(); $resultLayout->getLayout()->getUpdate()->load(['transparent_payment_response']); return $resultLayout; }
/** * Performs authorize transaction * * @param \Magento\Payment\Model\InfoInterface|Object $payment * @param float $amount * @return $this * @throws InvalidTransitionException * @throws LocalizedException */ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount) { $request = $this->buildBasicRequest(); $order = $payment->getOrder(); $this->addRequestOrderInfo($request, $order); $request = $this->fillCustomerContacts($order, $request); $request->setTrxtype(self::TRXTYPE_AUTH_ONLY); $request->setOrigid($payment->getAdditionalInformation('pnref')); $request->setAmt(round($amount, 2)); $response = $this->postRequest($request, $this->getConfig()); $this->processErrors($response); try { $this->responseValidator->validate($response); } catch (LocalizedException $exception) { $payment->setParentTransactionId($response->getPnref()); $this->void($payment); throw new LocalizedException(__('Error processing payment, please try again later.')); } $this->setTransStatus($payment, $response); $payment->unsAdditionalInformation('pnref'); return $this; }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Transaction has been declined */ public function testValidateUnknownCode() { $response = new DataObject(['result' => 7777777777, 'respmsg' => 'Test error msg']); $this->validatorMock->expects($this->never())->method('validate')->with($response)->willReturn(false); $this->responseValidator->validate($response, $this->payflowFacade); }