diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/PaymentMethod/AvailablePaymentMethodsDataProvider.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethods.php similarity index 52% rename from app/code/Magento/QuoteGraphQl/Model/Cart/PaymentMethod/AvailablePaymentMethodsDataProvider.php rename to app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethods.php index daa51d8729995..907d778550593 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/PaymentMethod/AvailablePaymentMethodsDataProvider.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethods.php @@ -5,15 +5,19 @@ */ declare(strict_types=1); -namespace Magento\QuoteGraphQl\Model\Cart\PaymentMethod; +namespace Magento\QuoteGraphQl\Model\Resolver; use Magento\Checkout\Api\PaymentInformationManagementInterface; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\GraphQl\Config\Element\Field; +use Magento\Framework\GraphQl\Query\ResolverInterface; +use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Quote\Api\Data\CartInterface; /** - * Get array of available payment methods. + * Get list of active payment methods resolver. */ -class AvailablePaymentMethodsDataProvider +class AvailablePaymentMethods implements ResolverInterface { /** * @var PaymentInformationManagementInterface @@ -21,7 +25,6 @@ class AvailablePaymentMethodsDataProvider private $informationManagement; /** - * AvailablePaymentMethodsDataProvider constructor. * @param PaymentInformationManagementInterface $informationManagement */ public function __construct(PaymentInformationManagementInterface $informationManagement) @@ -29,25 +32,37 @@ public function __construct(PaymentInformationManagementInterface $informationMa $this->informationManagement = $informationManagement; } + /** + * @inheritdoc + */ + public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) + { + if (!isset($value['model'])) { + throw new LocalizedException(__('"model" value should be specified')); + } + + $cart = $value['model']; + return $this->getPaymentMethodsData($cart); + } + /** * Collect and return information about available payment methods * * @param CartInterface $cart * @return array */ - public function getPaymentMethods(CartInterface $cart): array + private function getPaymentMethodsData(CartInterface $cart): array { $paymentInformation = $this->informationManagement->getPaymentInformation($cart->getId()); $paymentMethods = $paymentInformation->getPaymentMethods(); - $paymentMethodsNested = []; + $paymentMethodsData = []; foreach ($paymentMethods as $paymentMethod) { - $paymentMethodsNested[] = [ + $paymentMethodsData[] = [ 'title' => $paymentMethod->getTitle(), - 'code' => $paymentMethod->getCode() + 'code' => $paymentMethod->getCode(), ]; } - - return $paymentMethodsNested; + return $paymentMethodsData; } } diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethodsResolver.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethodsResolver.php deleted file mode 100644 index 17747ec11b25a..0000000000000 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/AvailablePaymentMethodsResolver.php +++ /dev/null @@ -1,48 +0,0 @@ -addressDataProvider = $addressDataProvider; - } - - /** - * @inheritdoc - */ - public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) - { - if (!isset($value['model'])) { - throw new LocalizedException(__('"model" value should be specified')); - } - - $cart = $value['model']; - - return $this->addressDataProvider->getPaymentMethods($cart); - } -} diff --git a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls index a505b87ccbae9..bab85f26b8b1e 100644 --- a/app/code/Magento/QuoteGraphQl/etc/schema.graphqls +++ b/app/code/Magento/QuoteGraphQl/etc/schema.graphqls @@ -104,7 +104,7 @@ type Cart { applied_coupon: AppliedCoupon shipping_addresses: [CartAddress]! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddresses") billing_address: CartAddress! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\BillingAddress") - available_payment_methods : [CheckoutPaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethodsResolver") @doc(description: "Available payment methods") + available_payment_methods : [CheckoutPaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethods") @doc(description: "Available payment methods") } type CartAddress {