* @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\Query; use Exception; use PrestaShop\Module\PrestashopCheckout\Repository\PaymentTokenRepository; class GetCustomerPaymentTokensQueryHandler { /** * @var PaymentTokenRepository */ private $paymentTokenRepository; /** * @param PaymentTokenRepository $paymentTokenRepository */ public function __construct(PaymentTokenRepository $paymentTokenRepository) { $this->paymentTokenRepository = $paymentTokenRepository; } /** * @param GetCustomerPaymentTokensQuery $query * * @return GetCustomerPaymentTokensQueryResult * * @throws Exception */ public function handle(GetCustomerPaymentTokensQuery $query) { // $paymentTokens = $this->paymentTokenRepository->findByPrestaShopCustomerId($query->getCustomerId()->getValue(), $query->getPageSize(), $query->getPageNumber()); $paymentTokens = $this->paymentTokenRepository->findByPrestaShopCustomerId($query->getCustomerId()->getValue()); if ($query->isTotalCountRequired()) { $totalItems = $this->paymentTokenRepository->getCount($query->getCustomerId()->getValue()); $totalPages = ceil($totalItems / $query->getPageSize()); } else { $totalItems = null; $totalPages = null; } return new GetCustomerPaymentTokensQueryResult( $paymentTokens, $query->getCustomerId(), $totalItems, (int) $totalPages ); } }