* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ namespace PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\CommandHandler; use Exception; use PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\Command\SavePaymentTokenCommand; use PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\Entity\PaymentToken; use PrestaShop\Module\PrestashopCheckout\Repository\PaymentTokenRepository; class SavePaymentTokenCommandHandler { /** @var PaymentTokenRepository */ private $paymentTokenRepository; public function __construct(PaymentTokenRepository $paymentTokenRepository) { $this->paymentTokenRepository = $paymentTokenRepository; } /** * @throws Exception */ public function handle(SavePaymentTokenCommand $command) { $token = new PaymentToken( $command->getPaymentTokenId()->getValue(), $command->getPaypalCustomerId()->getValue(), $command->getPaymentSource(), $command->getPaymentTokenData(), $command->getMerchantId(), $command->getStatus(), $command->isFavorite() ); $this->paymentTokenRepository->save($token); if ($command->isFavorite()) { $this->paymentTokenRepository->setTokenFavorite($command->getPaymentTokenId()); } } }