/** * 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; $gatewayToken = 'xs4vf3'; $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::atLeastOnce())->method('getIsVisible')->willReturn(false); $tokenMock->expects(static::atLeastOnce())->method('getCustomerId')->willReturn($customerId); $tokenMock->expects(static::atLeastOnce())->method('getGatewayToken')->willReturn($gatewayToken); $this->encryptorMock->expects(static::once())->method('getHash')->with($publicHash . $gatewayToken)->willReturn($newHash); $tokenMock->expects(static::once())->method('setPublicHash')->with($newHash); $this->paymentTokenRepositoryMock->expects(self::once())->method('save')->with($tokenMock); $tokenMock->expects(static::atLeastOnce())->method('getEntityId')->willReturn($newEntityId); $paymentMock->expects(self::atLeastOnce())->method('getEntityId')->willReturn($paymentId); $this->paymentTokenResourceModelMock->expects(static::once())->method('addLinkToOrderPayment')->with($newEntityId, $paymentId); $this->paymentTokenManagement->saveTokenWithPaymentLink($tokenMock, $paymentMock); }
/** * Performs persist operations for a specified payment token. * * @param \Magento\Vault\Api\Data\PaymentTokenInterface $entity The payment token. * @return \Magento\Vault\Api\Data\PaymentTokenInterface Saved payment token data. */ public function save(Data\PaymentTokenInterface $paymentToken) { /** @var PaymentToken $paymentToken */ $this->resourceModel->save($paymentToken); return $paymentToken; }
/** * Run test for getByGatewayToken method (return NULL) */ public function testGetByGatewayTokenNull() { $this->paymentTokenResourceModelMock->expects(self::once())->method('getByGatewayToken')->with('some-not-exists-token', 1, 1)->willReturn([]); $this->paymentTokenFactoryMock->expects(self::never())->method('create'); self::assertEquals(null, $this->paymentTokenManagement->getByGatewayToken('some-not-exists-token', 1, 1)); }
/** * Add link between payment token and order payment. * * @param int $paymentTokenId Payment token ID. * @param int $orderPaymentId Order payment ID. * @return bool */ public function addLinkToOrderPayment($paymentTokenId, $orderPaymentId) { return $this->paymentTokenResourceModel->addLinkToOrderPayment($paymentTokenId, $orderPaymentId); }