Skip to content

Commit dbb3427

Browse files
committed
Use plugin for checking is customer logged
1 parent 1422df6 commit dbb3427

File tree

7 files changed

+87
-18
lines changed

7 files changed

+87
-18
lines changed

app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\PaypalGraphQl\Model\Plugin\Cart\HostedPro;
99

1010
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
11+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
1112
use Magento\Paypal\Model\Config;
1213
use Magento\Quote\Model\Quote;
1314
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;
@@ -47,6 +48,7 @@ public function __construct(
4748
* @param mixed $result
4849
* @param Quote $cart
4950
* @param array $paymentData
51+
* @param ContextInterface $context
5052
* @return void
5153
* @throws GraphQlInputException
5254
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
@@ -55,7 +57,8 @@ public function afterExecute(
5557
\Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject,
5658
$result,
5759
Quote $cart,
58-
array $paymentData
60+
array $paymentData,
61+
ContextInterface $context
5962
): void {
6063
$paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_HOSTEDPRO, $paymentData);
6164

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowPro;
9+
10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
11+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
12+
use Magento\Paypal\Model\Config;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;
15+
use Magento\Sales\Model\Order\Payment\Repository as PaymentRepository;
16+
use Magento\PaypalGraphQl\Observer\PayflowProSetCcData;
17+
18+
/**
19+
* Set additionalInformation on payment for PayflowPro method
20+
*/
21+
class SetPaymentMethodOnCart
22+
{
23+
/**
24+
* @var PaymentRepository
25+
*/
26+
private $paymentRepository;
27+
28+
/**
29+
* @var AdditionalDataProviderPool
30+
*/
31+
private $additionalDataProviderPool;
32+
33+
/**
34+
* @param PaymentRepository $paymentRepository
35+
* @param AdditionalDataProviderPool $additionalDataProviderPool
36+
*/
37+
public function __construct(
38+
PaymentRepository $paymentRepository,
39+
AdditionalDataProviderPool $additionalDataProviderPool
40+
) {
41+
$this->paymentRepository = $paymentRepository;
42+
$this->additionalDataProviderPool = $additionalDataProviderPool;
43+
}
44+
45+
/**
46+
* Set redirect URL paths on payment additionalInformation
47+
*
48+
* @param \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject
49+
* @param mixed $result
50+
* @param Quote $cart
51+
* @param array $paymentData
52+
* @return void
53+
* @throws GraphQlInputException
54+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
55+
*/
56+
public function afterExecute(
57+
\Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject,
58+
$result,
59+
Quote $cart,
60+
array $paymentData,
61+
ContextInterface $context
62+
): void {
63+
$paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_PAYFLOWPRO, $paymentData);
64+
65+
if (!$context->getExtensionAttributes()->getIsCustomer()
66+
&& array_key_exists(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, $paymentData)) {
67+
$payment = $cart->getPayment();
68+
$payment->unsAdditionalInformation(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER);
69+
$payment->save();
70+
}
71+
}
72+
}

app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace Magento\PaypalGraphQl\Observer;
1010

11-
use Magento\Customer\Model\Session as CustomerModelSession;
1211
use Magento\Framework\App\Config\ScopeConfigInterface;
1312
use Magento\Framework\Event\Observer;
1413
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
@@ -24,11 +23,6 @@ class PayflowProSetCcData extends AbstractDataAssignObserver
2423
const XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE = "payment/payflowpro_cc_vault/active";
2524
const IS_ACTIVE_PAYMENT_TOKEN_ENABLER = "is_active_payment_token_enabler";
2625

27-
/**
28-
* @var CustomerModelSession
29-
*/
30-
private $customerSession;
31-
3226
/**
3327
* Core store config
3428
*
@@ -37,14 +31,11 @@ class PayflowProSetCcData extends AbstractDataAssignObserver
3731
private $scopeConfig;
3832

3933
/**
40-
* @param CustomerModelSession $customerSession
4134
* @param ScopeConfigInterface $scopeConfig
4235
*/
4336
public function __construct(
44-
CustomerModelSession $customerSession,
4537
ScopeConfigInterface $scopeConfig
4638
) {
47-
$this->customerSession = $customerSession;
4839
$this->scopeConfig = $scopeConfig;
4940
}
5041

@@ -65,11 +56,9 @@ public function execute(Observer $observer)
6556
return;
6657
}
6758

68-
if ($this->customerSession->isLoggedIn() && $this->isPayflowProVaultEnable()) {
59+
if ($this->isPayflowProVaultEnable()) {
6960
if (!isset($additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER])) {
70-
throw new GraphQlInputException(
71-
__('Required parameter "is_active_payment_token_enabler" is missing.')
72-
);
61+
$paymentModel->setData(self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, false);
7362
}
7463

7564
$paymentModel->setData(

app/code/Magento/PaypalGraphQl/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"magento/module-quote-graph-ql": "*",
1414
"magento/module-sales": "*",
1515
"magento/module-payment": "*",
16-
"magento/module-store": "*",
17-
"magento/module-customer": "*"
16+
"magento/module-store": "*"
1817
},
1918
"suggest": {
2019
"magento/module-graph-ql": "*"

app/code/Magento/PaypalGraphQl/etc/graphql/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<type name="Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart">
1313
<plugin name="hosted_pro_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\HostedPro\SetPaymentMethodOnCart"/>
1414
</type>
15+
<type name="Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart">
16+
<plugin name="payflowpro_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowPro\SetPaymentMethodOnCart"/>
17+
</type>
1518
<type name="Magento\Paypal\Model\Payflowlink">
1619
<plugin name="payflow_link_update_redirect_urls" type="Magento\PaypalGraphQl\Model\Plugin\Payflowlink"/>
1720
</type>

app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Exception\NoSuchEntityException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
14+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
1415
use Magento\Quote\Api\Data\PaymentInterface;
1516
use Magento\Quote\Api\Data\PaymentInterfaceFactory;
1617
use Magento\Quote\Api\PaymentMethodManagementInterface;
@@ -57,10 +58,12 @@ public function __construct(
5758
*
5859
* @param Quote $cart
5960
* @param array $paymentData
61+
* @param ContextInterface $context
6062
* @throws GraphQlInputException
6163
* @throws GraphQlNoSuchEntityException
64+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6265
*/
63-
public function execute(Quote $cart, array $paymentData): void
66+
public function execute(Quote $cart, array $paymentData, ContextInterface $context): void
6467
{
6568
if (!isset($paymentData['code']) || empty($paymentData['code'])) {
6669
throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.'));

app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6868
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
6969
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
7070
$this->checkCartCheckoutAllowance->execute($cart);
71-
$this->setPaymentMethodOnCart->execute($cart, $paymentData);
71+
$this->setPaymentMethodOnCart->execute($cart, $paymentData, $context);
7272

7373
return [
7474
'cart' => [

0 commit comments

Comments
 (0)