/** * @param OrderPaymentInterface $orderPayment * @return void */ private function attachTokenExtensionAttribute(OrderPaymentInterface $orderPayment) { $additionalInformation = $orderPayment->getAdditionalInformation(); $tokenData = isset($additionalInformation[self::TOKEN_METADATA_KEY]) ? $additionalInformation[self::TOKEN_METADATA_KEY] : null; if ($tokenData === null) { throw new \LogicException("Token metadata should be defined"); } $customerId = $tokenData[PaymentTokenInterface::CUSTOMER_ID]; $publicHash = $tokenData[PaymentTokenInterface::PUBLIC_HASH]; $paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId); if ($paymentToken === null) { throw new \LogicException("No token found"); } $extensionAttributes = $this->getPaymentExtensionAttributes($orderPayment); $extensionAttributes->setVaultPaymentToken($paymentToken); }