/**
  * Create payment vault record
  *
  * @param Observer $observer
  * @return $this
  */
 public function execute(Observer $observer)
 {
     /** @var OrderPaymentInterface $payment */
     $payment = $observer->getDataByKey(self::PAYMENT_OBJECT_DATA_KEY);
     $extensionAttributes = $payment->getExtensionAttributes();
     $paymentToken = $this->getPaymentToken($extensionAttributes);
     if ($paymentToken === null) {
         return $this;
     }
     if ($paymentToken->getEntityId() !== null) {
         $this->paymentTokenManagement->addLinkToOrderPayment($paymentToken->getEntityId(), $payment->getEntityId());
         return $this;
     }
     $order = $payment->getOrder();
     $paymentToken->setCustomerId($order->getCustomerId());
     $paymentToken->setIsActive(true);
     $paymentToken->setPaymentMethodCode($payment->getMethod());
     $additionalInformation = $payment->getAdditionalInformation();
     if (isset($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE])) {
         $paymentToken->setIsVisible((bool) (int) $additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE]);
     }
     $paymentToken->setPublicHash($this->generatePublicHash($paymentToken));
     $this->paymentTokenManagement->saveTokenWithPaymentLink($paymentToken, $payment);
     $extensionAttributes->setVaultPaymentToken($paymentToken);
     return $this;
 }
 /**
  * Create payment vault record
  *
  * @param Observer $observer
  * @return $this
  */
 public function execute(Observer $observer)
 {
     /** @var OrderPaymentInterface $payment */
     $payment = $observer->getDataByKey(self::PAYMENT_OBJECT_DATA_KEY);
     $extensionAttributes = $payment->getExtensionAttributes();
     $paymentToken = $this->getPaymentToken($extensionAttributes);
     // Save only new tokens that has been set during first order placement
     if ($paymentToken === null || $paymentToken->getEntityId() > 0) {
         return $this;
     }
     $paymentToken->setPublicHash($this->generatePublicHash($paymentToken));
     $paymentToken->setIsActive(true);
     $additionalInformation = $payment->getAdditionalInformation();
     if (isset($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE])) {
         $paymentToken->setIsVisible((bool) (int) $additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE]);
     }
     $this->paymentTokenManagement->saveTokenWithPaymentLink($paymentToken, $payment);
     $extensionAttributes->setVaultPaymentToken($paymentToken);
     return $this;
 }