/**
  * Run test for getById method
  */
 public function testGetById()
 {
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
     $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
     $this->tokenFactoryMock->expects(self::once())->method('create')->willReturn($tokenMock);
     self::assertEquals($tokenMock, $this->repository->getById(1));
 }
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * Get vault payment token entity
  *
  * @param \Braintree\Transaction $transaction
  * @param OrderPaymentInterface $payment
  * @return PaymentTokenInterface|null
  */
 protected function getVaultPaymentToken(Transaction $transaction, OrderPaymentInterface $payment)
 {
     // Check token existing in gateway response
     $token = $transaction->creditCardDetails->token;
     if (empty($token)) {
         return null;
     }
     $order = $payment->getOrder();
     /** @var PaymentTokenInterface $paymentToken */
     $paymentToken = $this->paymentTokenFactory->create();
     $paymentToken->setGatewayToken($token);
     $paymentToken->setCustomerId($order->getCustomerId());
     $paymentToken->setPaymentMethodCode($payment->getMethod());
     $paymentToken->setCreatedAt($order->getCreatedAt());
     $paymentToken->setTokenDetails($this->convertDetailsToJSON(['type' => $this->getCreditCardType($transaction->creditCardDetails->cardType), 'maskedCC' => $transaction->creditCardDetails->last4, 'expirationDate' => $transaction->creditCardDetails->expirationDate]));
     return $paymentToken;
 }
 /**
  * Loads a specified payment token.
  *
  * @param int $entityId The payment token entity ID.
  * @return \Magento\Vault\Api\Data\PaymentTokenInterface Payment token interface.
  */
 public function getById($entityId)
 {
     $tokenModel = $this->paymentTokenFactory->create();
     $this->resourceModel->load($tokenModel, $entityId);
     return $tokenModel;
 }
 /**
  * @inheritdoc
  */
 public function getById($entityId)
 {
     return $this->tokenFactory->create();
 }
 /**
  * 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));
 }
Ejemplo n.º 7
0
 /**
  * Get payment token by public hash.
  *
  * @param string $hash Public hash.
  * @param int $customerId Customer ID.
  * @return PaymentTokenInterface|null Payment token interface.
  */
 public function getByPublicHash($hash, $customerId)
 {
     $tokenData = $this->paymentTokenResourceModel->getByPublicHash($hash, $customerId);
     $tokenModel = !empty($tokenData) ? $this->paymentTokenFactory->create(['data' => $tokenData]) : null;
     return $tokenModel;
 }