- /**
- * @param PaymentTokenInterface $token
- * @param OrderPaymentInterface $payment
- * @return bool
- */
- public function saveTokenWithPaymentLink(PaymentTokenInterface $token, OrderPaymentInterface $payment)
- {
- $tokenDuplicate = $this->getByPublicHash(
- $token->getPublicHash(),
- $token->getCustomerId()
- );
-
- if (!empty($tokenDuplicate)) {
- if ($token->getIsVisible() || $tokenDuplicate->getIsVisible()) {
- $token->setEntityId($tokenDuplicate->getEntityId());
- $token->setIsVisible(true);
- } elseif ($token->getIsVisible() === $tokenDuplicate->getIsVisible()) {
- $token->setEntityId($tokenDuplicate->getEntityId());
- } else {
- $token->setPublicHash(
- $this->encryptor->getHash(
- $token->getPublicHash() . $token->getGatewayToken()
- )
- );
- }
- }
-
- $this->paymentTokenRepository->save($token);
-
- $result = $this->addLinkToOrderPayment($token->getEntityId(), $payment->getEntityId());
-
- return $result;
- }