diff --git a/Model/Resolver/PaymentDetails.php b/Model/Resolver/PaymentDetails.php index 8f625a4..29ba0c0 100644 --- a/Model/Resolver/PaymentDetails.php +++ b/Model/Resolver/PaymentDetails.php @@ -3,9 +3,12 @@ namespace Paytrail\PaymentServiceGraphQl\Model\Resolver; use Magento\Checkout\Model\Session; +use Magento\Framework\Exception\NotFoundException; use Magento\Framework\GraphQl\Config\Element\Field; +use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Payment\Gateway\Command\CommandException; use Magento\Payment\Gateway\Command\CommandManagerPoolInterface; use Magento\Sales\Model\Order; use Paytrail\PaymentService\Exceptions\CheckoutException; @@ -17,6 +20,15 @@ class PaymentDetails implements ResolverInterface { + /** + * Class constructor. + * + * @param Session $checkoutSession + * @param LoggerInterface $logger + * @param CommandManagerPoolInterface $commandManagerPool + * @param PaymentProvidersData $paymentProvidersData + * @param ProviderForm $providerForm + */ public function __construct( private readonly Session $checkoutSession, private readonly LoggerInterface $logger, @@ -27,8 +39,10 @@ public function __construct( } /** + * Resolve function. + * * @param Field $field - * @param $context + * @param ContextInterface $context * @param ResolveInfo $info * @param array|null $value * @param array|null $args @@ -59,10 +73,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } /** + * Get Paytrail payment. + * * @param Order $order * * @return PaymentResponse - * @throws CheckoutException + * @throws NotFoundException + * @throws CommandException */ private function getPaytrailPayment(Order $order): PaymentResponse { @@ -87,6 +104,8 @@ private function getPaytrailPayment(Order $order): PaymentResponse } /** + * Get form parameters for selected provider. + * * @param PaymentResponse $response * @param Order $order * diff --git a/Model/Resolver/PaytrailConfig.php b/Model/Resolver/PaytrailConfig.php index 4e0277d..d8b3b5f 100644 --- a/Model/Resolver/PaytrailConfig.php +++ b/Model/Resolver/PaytrailConfig.php @@ -15,11 +15,10 @@ class PaytrailConfig implements ResolverInterface /** * @param MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId - * @param CartRepositoryInterface $cartRepository + * @param \Paytrail\PaymentService\Model\Ui\ConfigProvider $configProvider */ public function __construct( private readonly MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId, - private readonly CartRepositoryInterface $cartRepository, private readonly \Paytrail\PaymentService\Model\Ui\ConfigProvider $configProvider ) { } @@ -33,12 +32,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } - $cartId = $this->maskedQuoteIdToQuoteId->execute($args['cart_id']); $config = $this->configProvider->getConfig(); $methodGroups = $config['payment']['paytrail']['method_groups']; - return [ 'groups' => $methodGroups ]; diff --git a/Model/Resolver/RestoreQuote.php b/Model/Resolver/RestoreQuote.php index d9a9bbc..954d6a9 100644 --- a/Model/Resolver/RestoreQuote.php +++ b/Model/Resolver/RestoreQuote.php @@ -19,6 +19,7 @@ use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; +use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Quote\Api\CartRepositoryInterface; @@ -27,7 +28,6 @@ class RestoreQuote implements ResolverInterface { - /** * RestoreQuote constructor. * @@ -41,11 +41,22 @@ public function __construct( } /** - * @inheritdoc + * Resolve masked cart id to quote id + * + * @param Field $field + * @param ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * + * @return string + * @throws GraphQlAuthorizationException + * @throws GraphQlInputException + * @throws GraphQlNoSuchEntityException */ public function resolve( Field $field, - $context, + $context, ResolveInfo $info, array $value = null, array $args = null @@ -66,6 +77,8 @@ public function resolve( } /** + * Get cart for user + * * @param string $cartHash * @param int|null $customerId * @param int $storeId @@ -113,7 +126,11 @@ private function getQuoteByHash(string $cartHash, ?int $customerId, int $storeId } /** + * Restore Quote + * * @param CartInterface $cart + * + * @return void */ private function restoreQuote(CartInterface $cart): void { diff --git a/Observer/PaytrailSetAdditionalData.php b/Observer/PaytrailSetAdditionalData.php index e333b5f..737cca2 100644 --- a/Observer/PaytrailSetAdditionalData.php +++ b/Observer/PaytrailSetAdditionalData.php @@ -24,9 +24,12 @@ public function execute(Observer $observer): void $dataObject = $this->readDataArgument($observer); $additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA); - if (isset($additionalData['additional_information']) and isset($additionalData['additional_information']['provider'])) { + if (isset($additionalData['additional_information']) + && isset($additionalData['additional_information']['provider']) + ) { $additionalData = $additionalData['additional_information']; } + if (!is_array($additionalData)) { return; } diff --git a/Plugin/GetFrontendUrl.php b/Plugin/GetFrontendUrl.php index f7799d4..44f22f3 100644 --- a/Plugin/GetFrontendUrl.php +++ b/Plugin/GetFrontendUrl.php @@ -7,24 +7,34 @@ use Magento\Quote\Model\QuoteIdMaskFactory; use Magento\Sales\Model\Order; use Magento\Store\Model\StoreManagerInterface; +use Magento\Support\Model\Report\Group\Modules\Modules; use Paytrail\PaymentService\Controller\Receipt\Index; class GetFrontendUrl { + /** + * @param QuoteIdMaskFactory $idMaskFactory + * @param Modules $modules + * @param ScopeConfigInterface $config + * @param StoreManagerInterface $storeManager + */ public function __construct( - private readonly QuoteIdMaskFactory $idMaskFactory, - private readonly \Magento\Support\Model\Report\Group\Modules\Modules $modules, - private readonly ScopeConfigInterface $config, + private readonly QuoteIdMaskFactory $idMaskFactory, + private readonly Modules $modules, + private readonly ScopeConfigInterface $config, private readonly StoreManagerInterface $storeManager ) { } /** + * Get success url based on pwa configuration. + * * @param Index $subject * @param string $result * @param Order $order * * @return string + * @throws NoSuchEntityException */ public function afterGetSuccessUrl(Index $subject, string $result, Order $order): string { @@ -38,14 +48,15 @@ public function afterGetSuccessUrl(Index $subject, string $result, Order $order) } $maskedId = $this->getMaskedId($order); - $result = trim($frontendBaseUrl, '/') . '/checkout/success/' . $order->getIncrementId( - ) . '/maskedId/' . $maskedId; + $result = trim($frontendBaseUrl, '/') . '/checkout/success/' . $order->getIncrementId() + . '/maskedId/' . $maskedId; return $result; } - /** + * Get cart url based on pwa configuration. + * * @param Index $subject * @param string $result * @param Order $order @@ -72,6 +83,8 @@ public function afterGetCartUrl(Index $subject, string $result, Order $order): s } /** + * Get quote masked id. + * * @param Order $order * * @return string @@ -84,6 +97,8 @@ private function getMaskedId(Order $order): string } /** + * Get base url for pwa frontend + * * @return string */ private function getBaseUrl(): string diff --git a/etc/di.xml b/etc/di.xml index 2f849b3..6ec2397 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -11,4 +11,9 @@ type="Paytrail\PaymentServiceGraphQl\Plugin\GetFrontendUrl" sortOrder="100"/> + + + Magento\Checkout\Model\Session\Proxy + + diff --git a/etc/graphql/di.xml b/etc/graphql/di.xml index 40ea336..ddff80d 100644 --- a/etc/graphql/di.xml +++ b/etc/graphql/di.xml @@ -5,7 +5,9 @@ - Paytrail\PaymentServiceGraphQl\Model\PaytrailAdditionalDataProvider + + Paytrail\PaymentServiceGraphQl\Model\PaytrailAdditionalDataProvider + diff --git a/etc/graphql/events.xml b/etc/graphql/events.xml index 08f911e..3de2ced 100644 --- a/etc/graphql/events.xml +++ b/etc/graphql/events.xml @@ -5,8 +5,10 @@ * See COPYING.txt for license details. */ --> - + - +