public function testGetCustomerSessionTokens() { $customerId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; $this->customerSession->expects(static::once())->method('getCustomerId')->willReturn($customerId); $this->paymentTokenManagement->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId)->willReturn($expectation); static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens()); }
/** * Returns list of payment tokens for current customer session * * @return PaymentTokenInterface[] */ public function getCustomerSessionTokens() { $vaultPayments = []; $customerId = $this->session->getCustomerId(); if (!$customerId) { return $vaultPayments; } return $this->tokenManagement->getVisibleAvailableTokens($customerId); }
/** * Returns list of payment tokens for current customer session * * @return PaymentTokenInterface[] */ public function getCustomerSessionTokens() { $vaultPayments = []; $customerId = $this->session->getCustomerId(); if (!$customerId) { return $vaultPayments; } $storeId = $this->storeManager->getStore()->getId(); if (!$this->vaultPayment->isActive($storeId)) { return $vaultPayments; } $providerCode = $this->vaultPayment->getProviderCode($storeId); return $this->tokenManagement->getVisibleAvailableTokens($customerId, $providerCode); }
public function testGetCustomerSessionTokens() { $customerId = 1; $providerCode = 'vault_provider'; $storeId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; $this->customerSessionMock->expects(self::once())->method('getCustomerId')->willReturn($customerId); $this->storeManager->expects(static::once())->method('getStore')->with(null)->willReturn($this->store); $this->store->expects(static::once())->method('getId')->willReturn($storeId); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true); $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($providerCode); $this->paymentTokenManagementMock->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId, $providerCode)->willReturn($expectation); static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens()); }
/** * @covers \Magento\BraintreeTwo\Gateway\Command\GetPaymentNonceCommand::execute */ public function testExecute() { $publicHash = '3wv2m24d2er3'; $customerId = 1; $token = 'jd2vnq'; $nonce = 's1dj23'; $this->subjectReader->expects(static::once())->method('readPublicHash')->willReturn($publicHash); $this->subjectReader->expects(static::once())->method('readCustomerId')->willReturn($customerId); $this->tokenManagement->expects(static::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($this->paymentToken); $this->paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token); $obj = new \stdClass(); $obj->success = true; $obj->paymentMethodNonce = new \stdClass(); $obj->paymentMethodNonce->nonce = $nonce; $this->adapter->expects(static::once())->method('createNonce')->with($token)->willReturn($obj); $this->responseValidator->expects(static::once())->method('validate')->with(['response' => ['object' => $obj]])->willReturn($this->validationResult); $this->validationResult->expects(static::once())->method('isValid')->willReturn(true); $this->validationResult->expects(static::never())->method('getFailsDescription'); $expected = $this->getMockBuilder(ArrayResult::class)->disableOriginalConstructor()->setMethods(['get'])->getMock(); $expected->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]); $this->resultFactory->expects(static::once())->method('create')->willReturn($expected); $actual = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]); static::assertEquals($expected, $actual); static::assertEquals($nonce, $actual->get()['paymentMethodNonce']); }
/** * Run test for saveTokenWithPaymentLink method */ public function testSaveTokenWithPaymentLinkWithDuplicateTokenNotVisible() { /** @var OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject $paymentMock */ $paymentMock = $this->getMock(OrderPaymentInterface::class); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */ $tokenMock = $this->getMock(PaymentTokenInterface::class); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $duplicateToken */ $duplicateToken = $this->getMock(PaymentTokenInterface::class); $entityId = 1; $newEntityId = 1; $paymentId = 1; $customerId = 1; $createdAt = '30-02-2017'; $publicHash = 'existing-token'; $duplicateTokenData = ['entity_id' => $entityId]; $newHash = 'new-token2'; $tokenMock->expects(static::atLeastOnce())->method('getPublicHash')->willReturn($publicHash); $tokenMock->expects(static::atLeastOnce())->method('getCustomerId')->willReturn($customerId); $this->paymentTokenResourceModelMock->expects(self::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($duplicateTokenData); $this->paymentTokenFactoryMock->expects(self::once())->method('create')->with(['data' => $duplicateTokenData])->willReturn($duplicateToken); $tokenMock->expects(static::once())->method('getIsVisible')->willReturn(false); $tokenMock->expects(static::once())->method('getCustomerId')->willReturn($customerId); $tokenMock->expects(static::once())->method('getCreatedAt')->willReturn($createdAt); $this->encryptorMock->expects(static::once())->method('getHash')->with($publicHash . $createdAt)->willReturn($newHash); $tokenMock->expects(static::once())->method('setPublicHash')->with($newHash); $this->paymentTokenRepositoryMock->expects(self::once())->method('save')->with($tokenMock); $tokenMock->expects(static::once())->method('getEntityId')->willReturn($newEntityId); $paymentMock->expects(self::once())->method('getEntityId')->willReturn($paymentId); $this->paymentTokenResourceModelMock->expects(static::once())->method('addLinkToOrderPayment')->with($newEntityId, $paymentId); $this->paymentTokenManagement->saveTokenWithPaymentLink($tokenMock, $paymentMock); }
/** * @param Http $request * @return PaymentTokenInterface|null */ private function getPaymentToken(Http $request) { $publicHash = $request->getPostValue(PaymentTokenInterface::PUBLIC_HASH); if ($publicHash === null) { return null; } return $this->paymentTokenManagement->getByPublicHash($publicHash, $this->customerSession->getCustomerId()); }
/** * Run test for saveTokenWithPaymentLink method */ public function testSaveTokenWithPaymentLink() { /** @var OrderPaymentInterface|\PHPUnit_Framework_MockObject_MockObject $paymentMock */ $paymentMock = $this->getMock(OrderPaymentInterface::class); /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */ $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass(); $tokenMock->expects(self::once())->method('getEntityId')->willReturn(1); $this->paymentTokenRepositoryMock->expects(self::once())->method('save')->with($tokenMock); $paymentMock->expects(self::once())->method('getEntityId'); $this->paymentTokenManagement->saveTokenWithPaymentLink($tokenMock, $paymentMock); }
public function testGetVisibleAvailableTokens() { $customerId = 1; $searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock(); $searchResult = $this->getMockForAbstractClass(PaymentTokenSearchResultsInterface::class); $token = $this->getMockForAbstractClass(PaymentTokenInterface::class); $customerFilter = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0); $visibilityFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_VISIBLE, true, 1); $isActiveFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_ACTIVE, true, 2); // express at expectations $expiresAtFilter = $this->createExpectedFilter(PaymentTokenInterface::EXPIRES_AT, '2015-01-01 00:00:00', 3); $this->filterBuilder->expects(static::once())->method('setConditionType')->with('gt')->willReturnSelf(); $date = $this->getMockBuilder('DateTime')->disableOriginalConstructor()->getMock(); $this->dateTimeFactory->expects(static::once())->method('create')->with("now", new \DateTimeZone('UTC'))->willReturn($date); $date->expects(static::once())->method('format')->with('Y-m-d 00:00:00')->willReturn('2015-01-01 00:00:00'); $this->searchCriteriaBuilder->expects(self::once())->method('addFilters')->with([$customerFilter, $visibilityFilter, $isActiveFilter, $expiresAtFilter])->willReturnSelf(); $this->searchCriteriaBuilder->expects(self::once())->method('create')->willReturn($searchCriteria); $this->paymentTokenRepository->expects(self::once())->method('getList')->with($searchCriteria)->willReturn($searchResult); $searchResult->expects(self::once())->method('getItems')->willReturn([$token]); static::assertEquals([$token], $this->paymentTokenManagement->getVisibleAvailableTokens($customerId)); }