Basket/Handler/ProductHandler.php
public function handle(array $options, BasketInterface $basket, Client $client): void
    {
        /** @var null|ItemResult $item */
        [
            'exception_handler' => $exceptionHandler,
            'item' => $item,
            'product' => $productId,
            'recover_item' => $recoverItem,
            'user' => $runetId,
        ] = $options;

        $itemProductId = null !== $item ? $item->Product->Id : null;

        if ($itemProductId === $productId) {
            return;
        }

        if (null !== $itemProductId) {
            try {
                $client
                    ->payDelete()
                    ->setOrderItemId($item->Id)
                    ->getRawResult();
            } catch (RunetIdException $exception) {
                $exceptionHandler($exception);

                return;
            }
        }

        if (null === $productId) {
            return;
        }

        try {
            $client
                ->payAdd()
                ->setOwnerRunetId($runetId)
                ->setProductId($productId)
                ->getResult();
        } catch (RunetIdException $exception) {
            if (null !== $itemProductId && $recoverItem) {
                /* @var int $itemProductId */
                $client
                    ->payAdd()
                    ->setOwnerRunetId($runetId)
                    ->setProductId($itemProductId)
                    ->getRawResult();
            }

            $exceptionHandler($exception);
        }
    }
public function handle(array $options, BasketInterface $basket, Client $client): void
    {
        /** @var null|ItemResult $item */
        [
            'exception_handler' => $exceptionHandler,
            'item' => $item,
            'product' => $productId,
            'recover_item' => $recoverItem,
            'user' => $runetId,
        ] = $options;

        $itemProductId = null !== $item ? $item->Product->Id : null;

        if ($itemProductId === $productId) {
            return;
        }

        if (null !== $itemProductId) {
            try {
                $client
                    ->payDelete()
                    ->setOrderItemId($item->Id)
                    ->getRawResult();
            } catch (RunetIdException $exception) {
                $exceptionHandler($exception);

                return;
            }
        }

        if (null === $productId) {
            return;
        }

        try {
            $client
                ->payAdd()
                ->setOwnerRunetId($runetId)
                ->setProductId($productId)
                ->getResult();
        } catch (RunetIdException $exception) {
            if (null !== $itemProductId && $recoverItem) {
                /* @var int $itemProductId */
                $client
                    ->payAdd()
                    ->setOwnerRunetId($runetId)
                    ->setProductId($itemProductId)
                    ->getRawResult();
            }

            $exceptionHandler($exception);
        }
    }
{@inheritdoc}