예제 #1
0
 /**
  * Returns gateway response data object
  *
  * @param array $gatewayTransactionResponse
  * @return Object
  */
 public function getResponseObject($gatewayTransactionResponse)
 {
     $response = new DataObject();
     $response = $this->transparent->mapGatewayResponse($gatewayTransactionResponse, $response);
     $this->logger->debug($gatewayTransactionResponse, (array) $this->transparent->getDebugReplacePrivateDataKeys(), (bool) $this->transparent->getDebugFlag());
     return $response;
 }
예제 #2
0
 /**
  * @param bool $expectedResult
  * @param \Magento\Framework\DataObject $response
  * @param array $configMap
  * @param int $exactlyCount
  *
  * @dataProvider validationDataProvider
  */
 public function testValidation($expectedResult, \Magento\Framework\DataObject $response, array $configMap, $exactlyCount)
 {
     $this->payflowproFacade->expects(static::once())->method('getConfig')->willReturn($this->configMock);
     $this->configMock->expects(static::exactly($exactlyCount))->method('getValue')->willReturnMap($configMap);
     static::assertEquals($expectedResult, $this->validator->validate($response, $this->payflowproFacade));
     if (!$expectedResult) {
         static::assertNotEmpty($response->getRespmsg());
     }
 }
예제 #3
0
 /**
  * @param bool $expectedResult
  * @param \Magento\Framework\DataObject $response
  * @param string $avsSecurityCodeFlag
  *
  * @dataProvider validationDataProvider
  */
 public function testValidation($expectedResult, \Magento\Framework\DataObject $response, $avsSecurityCodeFlag)
 {
     $this->payflowproFacade->expects(static::once())->method('getConfig')->willReturn($this->configMock);
     $this->configMock->expects($this->once())->method('getValue')->with(CVV2Match::CONFIG_NAME)->willReturn($avsSecurityCodeFlag);
     $this->assertEquals($expectedResult, $this->validator->validate($response, $this->payflowproFacade));
     if (!$expectedResult) {
         $this->assertNotEmpty($response->getRespmsg());
     }
 }
 public function testGetResponseObject()
 {
     $gatewayTransactionResponse = [];
     $result = new \Magento\Framework\DataObject();
     $this->transparent->expects($this->once())->method('getDebugReplacePrivateDataKeys')->willReturn(['key1', 'key2']);
     $this->transparent->expects($this->once())->method('getDebugFlag')->willReturn(true);
     $this->transparent->expects($this->once())->method('mapGatewayResponse')->with($gatewayTransactionResponse, $result)->willReturn($result);
     $this->loggerMock->expects($this->once())->method('debug')->with($gatewayTransactionResponse, ['key1', 'key2'], true);
     $this->assertEquals($result, $this->model->getResponseObject($gatewayTransactionResponse));
 }
예제 #5
0
 /**
  * Validate data
  *
  * @param DataObject|Object $response
  * @param Transparent $transparentModel
  * @return bool
  */
 public function validate(DataObject $response, Transparent $transparentModel)
 {
     $config = $transparentModel->getConfig();
     foreach ($this->avsCheck as $fieldName => $settingName) {
         if ($config->getValue($settingName) == static::CONFIG_ON && strtolower((string) $response->getData($fieldName)) === static::RESPONSE_NO) {
             $response->setRespmsg($this->errorsMessages[$settingName]);
             return false;
         }
     }
     return true;
 }
예제 #6
0
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function execute()
 {
     $this->sessionTransparent->setQuoteId($this->sessionManager->getQuote()->getId());
     $token = $this->secureTokenService->requestToken($this->sessionManager->getQuote());
     $result = [];
     $result[$this->transparent->getCode()]['fields'] = $token->getData();
     $result['success'] = $token->getSecuretoken() ? true : false;
     if (!$result['success']) {
         $result['error'] = true;
         $result['error_messages'] = __('Secure Token Error. Try again.');
     }
     return $this->resultJsonFactory->create()->setData($result);
 }
예제 #7
0
 public function testRequestToken()
 {
     $request = new Object();
     $secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
     $this->transparent->expects($this->once())->method('buildBasicRequest')->willReturn($request);
     $this->transparent->expects($this->once())->method('fillCustomerContacts');
     $this->transparent->expects($this->once())->method('getConfig')->willReturn($this->getMock('Magento\\Paypal\\Model\\PayflowConfig', [], [], '', false));
     $this->transparent->expects($this->once())->method('postRequest')->willReturn(new Object());
     $this->mathRandom->expects($this->once())->method('getUniqueHash')->willReturn($secureTokenID);
     $this->url->expects($this->exactly(3))->method('getUrl');
     $quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->model->requestToken($quote);
     $this->assertEquals($secureTokenID, $request->getSecuretokenid());
 }
예제 #8
0
 /**
  * Test method
  * with resultCode = RESPONSE_CODE_APPROVED and Origresult != RESPONSE_CODE_FRAUDSERVICE_FILTER
  */
 public function testAuthorize()
 {
     $this->initializationAuthorizeMock();
     $this->buildRequestData();
     $paymentTokenMock = $this->getMock(PaymentTokenInterface::class);
     $extensionAttributes = $this->getMockBuilder('Magento\\Sales\\Api\\Data\\OrderPaymentExtensionInterface')->disableOriginalConstructor()->setMethods(['setVaultPaymentToken'])->getMock();
     $ccDetails = ['cc_type' => 'VI', 'cc_number' => '1111'];
     $this->responseMock->setData('result_code', Payflowpro::RESPONSE_CODE_APPROVED);
     $this->responseMock->setData('origresult', 0);
     $this->responseMock->setData('pnref', 'test-pnref');
     $this->gatewayMock->expects($this->once())->method('postRequest')->willReturn($this->responseMock);
     $this->responseValidator->expects($this->once())->method('validate')->with($this->responseMock);
     $this->paymentMock->expects($this->once())->method('setTransactionId')->with('test-pnref')->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('setIsTransactionClosed')->with(0);
     $this->paymentMock->expects($this->once())->method('getCcExpYear')->willReturn('2017');
     $this->paymentMock->expects($this->once())->method('getCcExpMonth')->willReturn('12');
     $this->paymentMock->expects(static::any())->method('getAdditionalInformation')->willReturnMap([[Transparent::CC_DETAILS, $ccDetails], [Transparent::PNREF, 'test-pnref']]);
     $this->paymentTokenFactory->expects(static::once())->method('create')->willReturn($paymentTokenMock);
     $paymentTokenMock->expects(static::once())->method('setGatewayToken')->with('test-pnref');
     $paymentTokenMock->expects(static::once())->method('setTokenDetails')->with(json_encode($ccDetails));
     $paymentTokenMock->expects(static::once())->method('setExpiresAt')->with('2018-01-01 00:00:00');
     $this->paymentMock->expects(static::once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
     $extensionAttributes->expects(static::once())->method('setVaultPaymentToken')->with($paymentTokenMock);
     $this->assertSame($this->object, $this->object->authorize($this->paymentMock, 33));
 }
예제 #9
0
 /**
  * Get the Secure Token from Paypal for TR
  *
  * @param Quote $quote
  *
  * @return DataObject
  * @throws \Exception
  */
 public function requestToken(Quote $quote)
 {
     $request = $this->transparent->buildBasicRequest();
     $request->setTrxtype(Payflowpro::TRXTYPE_AUTH_ONLY);
     $request->setVerbosity('HIGH');
     $request->setAmt(0);
     $request->setCreatesecuretoken('Y');
     $request->setSecuretokenid($this->mathRandom->getUniqueHash());
     $request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
     $request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
     $request->setCancelurl($this->url->getUrl('paypal/transparent/cancel'));
     $request->setDisablereceipt('TRUE');
     $request->setSilenttran('TRUE');
     $this->transparent->fillCustomerContacts($quote, $request);
     $result = $this->transparent->postRequest($request, $this->transparent->getConfig());
     return $result;
 }
예제 #10
0
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function executeInternal()
 {
     /** @var Quote $quote */
     $quote = $this->sessionManager->getQuote();
     if (!$quote or !$quote instanceof Quote) {
         return $this->getErrorResponse();
     }
     $this->sessionTransparent->setQuoteId($quote->getId());
     try {
         $token = $this->secureTokenService->requestToken($quote);
         if (!$token->getData('securetoken')) {
             throw new \LogicException();
         }
         return $this->resultJsonFactory->create()->setData([$this->transparent->getCode() => ['fields' => $token->getData()], 'success' => true, 'error' => false]);
     } catch (\Exception $e) {
         return $this->getErrorResponse();
     }
 }
예제 #11
0
 /**
  * Run test execute method
  *
  * @param array $result
  * @param array $resultExpectation
  *
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $result, array $resultExpectation)
 {
     $quoteId = 99;
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $tokenMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData', 'getSecuretoken'])->disableOriginalConstructor()->getMock();
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId);
     $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willReturn($tokenMock);
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $tokenMock->expects($this->once())->method('getData')->willReturn($result['transparent']['fields']);
     $tokenMock->expects($this->once())->method('getSecuretoken')->willReturn($result['success']);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }
예제 #12
0
 /**
  * Validate data
  *
  * @param DataObject $response
  * @param Transparent $transparentModel
  * @return bool
  */
 public function validate(DataObject $response, Transparent $transparentModel)
 {
     if ($transparentModel->getConfig()->getValue(static::CONFIG_NAME) === static::CONFIG_OFF) {
         return true;
     }
     if ($this->isMatchCvv($response)) {
         return true;
     }
     if ($this->isNotMatchCvv($response)) {
         $response->setRespmsg(static::ERROR_MESSAGE);
         return false;
     }
     if ($this->isCvvDoNotExists($response)) {
         return true;
     }
     $response->setRespmsg(static::ERROR_MESSAGE);
     return false;
 }
 public function testExecuteSuccess()
 {
     $quoteId = 99;
     $tokenFields = ['fields-1', 'fields-2', 'fields-3'];
     $secureToken = 'token_hash';
     $resultExpectation = ['transparent' => ['fields' => ['fields-1', 'fields-2', 'fields-3']], 'success' => true, 'error' => false];
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $tokenMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId);
     $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willReturn($tokenMock);
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $tokenMock->expects($this->atLeastOnce())->method('getData')->willReturnMap([['', null, $tokenFields], ['securetoken', null, $secureToken]]);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }
예제 #14
0
 /**
  * Test method
  * with resultCode = RESPONSE_CODE_APPROVED and Origresult != RESPONSE_CODE_FRAUDSERVICE_FILTER
  */
 public function testAuthorize()
 {
     $this->initializationAuthorizeMock();
     $this->buildRequestData();
     $this->responseMock->expects($this->any())->method('getResultCode')->willReturn(Payflowpro::RESPONSE_CODE_APPROVED);
     $this->responseMock->expects($this->any())->method('getOrigresult')->willReturn(0);
     $this->gatewayMock->expects($this->once())->method('postRequest')->willReturn($this->responseMock);
     $this->responseValidator->expects($this->once())->method('validate')->with($this->responseMock);
     $this->responseMock->expects($this->once())->method('getPnref')->willReturn('test-pnref');
     $this->paymentMock->expects($this->once())->method('setTransactionId')->with('test-pnref')->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('setIsTransactionClosed')->with(0);
     $this->assertSame($this->object, $this->object->authorize($this->paymentMock, 33));
 }
예제 #15
0
 /**
  * Executes command basing on business object
  *
  * @param array $commandSubject
  * @return null|ResultInterface
  */
 public function execute(array $commandSubject)
 {
     /** @var double $amount */
     $amount = $commandSubject['amount'];
     /** @var PaymentDataObjectInterface $paymentDO */
     $paymentDO = $commandSubject['payment'];
     $payment = $paymentDO->getPayment();
     $storeId = $paymentDO->getOrder()->getStoreId();
     $this->payflowFacade->setStore($storeId);
     /** @var \Magento\Vault\Api\Data\PaymentTokenInterface $token */
     $token = $payment->getExtensionAttributes()->getVaultPaymentToken();
     $request = $this->payflowFacade->buildBasicRequest();
     $request->setAmt($this->formatPrice($amount));
     $request->setTrxtype(Transparent::TRXTYPE_SALE);
     $request->setOrigid($token->getGatewayToken());
     $this->payflowFacade->addRequestOrderInfo($request, $payment->getOrder());
     $response = $this->payflowFacade->postRequest($request, $this->payflowFacade->getConfig());
     $this->payflowFacade->processErrors($response);
     $this->payflowFacade->setTransStatus($payment, $response);
 }
예제 #16
0
 /**
  * Executes command basing on business object
  *
  * @param array $commandSubject
  * @return ResultInterface|null
  * @throws LocalizedException
  * @throws InvalidTransitionException
  */
 public function execute(array $commandSubject)
 {
     /** @var double $amount */
     $amount = $commandSubject['amount'];
     /** @var PaymentDataObjectInterface $paymentDO */
     $paymentDO = $commandSubject['payment'];
     $payment = $paymentDO->getPayment();
     $storeId = $paymentDO->getOrder()->getStoreId();
     $this->payflowFacade->setStore($storeId);
     $request = $this->payflowFacade->buildBasicRequest();
     /** @var \Magento\Sales\Model\Order $order */
     $order = $payment->getOrder();
     $this->payflowFacade->addRequestOrderInfo($request, $order);
     $request = $this->payflowFacade->fillCustomerContacts($order, $request);
     /** @var \Magento\Vault\Api\Data\PaymentTokenInterface $token */
     $token = $payment->getExtensionAttributes()->getVaultPaymentToken();
     $request->setData('trxtype', Transparent::TRXTYPE_AUTH_ONLY);
     $request->setData('origid', $token->getGatewayToken());
     $request->setData('amt', $this->formatPrice($amount));
     $response = $this->payflowFacade->postRequest($request, $this->payflowFacade->getConfig());
     $this->payflowFacade->processErrors($response);
     try {
         $this->payflowFacade->getResponceValidator()->validate($response, $this->payflowFacade);
     } catch (LocalizedException $exception) {
         $payment->setParentTransactionId($response->getData(Transparent::PNREF));
         $this->payflowFacade->void($payment);
         throw new LocalizedException(__('Error processing payment, please try again later.'));
     }
     $this->payflowFacade->setTransStatus($payment, $response);
     return $this;
 }