From d29468da99c7dae39be1dbef880edd867440891f Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 10 Jun 2020 12:31:55 +0300 Subject: [PATCH 01/20] add data to schema --- app/code/Magento/PaypalGraphQl/etc/schema.graphqls | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls index b8f14eec70d18..b925aba293209 100644 --- a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls +++ b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls @@ -51,6 +51,7 @@ input PaymentMethodInput { payflow_link: PayflowLinkInput @doc(description:"Required input for PayPal Payflow Link and Payments Advanced payments") payflowpro: PayflowProInput @doc(description: "Required input type for PayPal Payflow Pro and Payment Pro payments") hosted_pro: HostedProInput @doc(description:"Required input for PayPal Hosted pro payments") + payflowpro_cc_vault: VaultTokenInput } input HostedProInput @doc(description:"A set of relative URLs that PayPal will use in response to various actions during the authorization process. Magento prepends the base URL to this value to create a full URL. For example, if the full URL is https://www.example.com/path/to/page.html, the relative URL is path/to/page.html. Use this input for Payments Pro Hosted Solution payment method.") { @@ -102,6 +103,7 @@ input PayflowProTokenInput @doc(description:"Input required to fetch payment tok input PayflowProInput @doc(description:"Required input for Payflow Pro and Payments Pro payment methods.") { cc_details: CreditCardDetailsInput! @doc(description: "Required input for credit card related information") + is_active_payment_token_enabler: Boolean! @doc(description:"States whether an entered by a customer credit/debit card should be tokenized for later usage. Required only if Vault is enabled for PayPal Payflow Pro payment integration.") } input CreditCardDetailsInput @doc(description:"Required fields for Payflow Pro and Payments Pro credit card payments") { @@ -141,3 +143,7 @@ input PayflowProResponseInput @doc(description:"Input required to complete payme type PayflowProResponseOutput { cart: Cart! } + +input VaultTokenInput @doc(description:"Required input for payment methods with Vault support.") { + public_hash: String! @doc(description: "The public hash of the payment token") +} From e798f7553d6ab21132d476ef0d7f7ab7a99475ea Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Sun, 21 Jun 2020 23:10:09 +0300 Subject: [PATCH 02/20] add cc data --- .../Observer/PayflowProSetCcData.php | 39 +++++++++++++++++++ .../PaypalGraphQl/etc/graphql/events.xml | 3 ++ 2 files changed, 42 insertions(+) create mode 100644 app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php diff --git a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php new file mode 100644 index 0000000000000..9dd5969672529 --- /dev/null +++ b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php @@ -0,0 +1,39 @@ +readDataArgument($observer); + $additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA); + + if (!isset($additionalData['cc_details'])) { + return; + } + + $paymentModel = $this->readPaymentModelArgument($observer); + foreach ($additionalData['cc_details'] as $ccKey => $ccValue) { + $paymentModel->setData($ccKey, $ccValue); + } + } +} diff --git a/app/code/Magento/PaypalGraphQl/etc/graphql/events.xml b/app/code/Magento/PaypalGraphQl/etc/graphql/events.xml index 41154e5ae06e6..0d2be95d77c92 100644 --- a/app/code/Magento/PaypalGraphQl/etc/graphql/events.xml +++ b/app/code/Magento/PaypalGraphQl/etc/graphql/events.xml @@ -12,4 +12,7 @@ + + + From 934db87d56bad355d759925aff9fe837c61ef398 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Mon, 22 Jun 2020 23:20:17 +0300 Subject: [PATCH 03/20] Add some checks --- .../Observer/PayflowProSetCcData.php | 59 ++++++++++++++++++- .../Magento/PaypalGraphQl/etc/schema.graphqls | 2 +- .../Customer/PlaceOrderWithPayflowProTest.php | 1 + 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php index 9dd5969672529..9bb8dfc0589fa 100644 --- a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php +++ b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php @@ -8,32 +8,89 @@ namespace Magento\PaypalGraphQl\Observer; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Event\Observer; +use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Payment\Observer\AbstractDataAssignObserver; use Magento\Quote\Api\Data\PaymentInterface; +use Magento\Customer\Model\Session as CustomerModelSession; /** * Class PayflowProSetCcData set CcData to quote payment */ class PayflowProSetCcData extends AbstractDataAssignObserver { + const XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE = "payment/payflowpro_cc_vault/active"; + const IS_ACTIVE_PAYMENT_TOKEN_ENABLER = "is_active_payment_token_enabler"; + + /** + * @var CustomerModelSession + */ + private $customerSession; + + /** + * Core store config + * + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @param CustomerModelSession $customerSession + * @param ScopeConfigInterface $scopeConfig + */ + public function __construct( + CustomerModelSession $customerSession, + ScopeConfigInterface $scopeConfig + ) { + $this->customerSession = $customerSession; + $this->scopeConfig = $scopeConfig; + } + /** * Set CcData * * @param Observer $observer + * + * @throws GraphQlInputException */ public function execute(Observer $observer) { $dataObject = $this->readDataArgument($observer); $additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA); + $paymentModel = $this->readPaymentModelArgument($observer); if (!isset($additionalData['cc_details'])) { return; } - $paymentModel = $this->readPaymentModelArgument($observer); + if($this->customerSession->isLoggedIn() && $this->isPayflowProVaultEnable()) { + if (!isset($additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER])) { + throw new GraphQlInputException( + __('Required parameter "is_active_payment_token_enabler" is missing.') + ); + } + + $paymentModel->setData( + self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, + $additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER] + ); + } else { + $paymentModel->setData(self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, false); + } + foreach ($additionalData['cc_details'] as $ccKey => $ccValue) { $paymentModel->setData($ccKey, $ccValue); } } + + /** + * Check if payflowpro vault is enable + * + * @return bool + */ + private function isPayflowProVaultEnable() + { + return (bool)$this->scopeConfig->getValue(self::XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE); + } } diff --git a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls index b925aba293209..e5adb6f25b1c2 100644 --- a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls +++ b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls @@ -103,7 +103,7 @@ input PayflowProTokenInput @doc(description:"Input required to fetch payment tok input PayflowProInput @doc(description:"Required input for Payflow Pro and Payments Pro payment methods.") { cc_details: CreditCardDetailsInput! @doc(description: "Required input for credit card related information") - is_active_payment_token_enabler: Boolean! @doc(description:"States whether an entered by a customer credit/debit card should be tokenized for later usage. Required only if Vault is enabled for PayPal Payflow Pro payment integration.") + is_active_payment_token_enabler: Boolean @doc(description:"States whether an entered by a customer credit/debit card should be tokenized for later usage. Required only if Vault is enabled for PayPal Payflow Pro payment integration.") } input CreditCardDetailsInput @doc(description:"Required fields for Payflow Pro and Payments Pro credit card payments") { diff --git a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php index 8ad5e4d98c24e..6a8b6cbc4df61 100644 --- a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php +++ b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php @@ -77,6 +77,7 @@ public function testResolveCustomer(): void payment_method: { code: "{$paymentMethod}", payflowpro: { + is_active_payment_token_enabler: true cc_details: { cc_exp_month: 12, cc_exp_year: 2030, From aef0f96fdc93dbfe01817426178223b73aae5088 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 23 Jun 2020 10:01:49 +0300 Subject: [PATCH 04/20] fix static issues --- .../Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php | 3 ++- app/code/Magento/PaypalGraphQl/composer.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php index 9bb8dfc0589fa..d45db9ae45a32 100644 --- a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php +++ b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php @@ -53,6 +53,7 @@ public function __construct( * @param Observer $observer * * @throws GraphQlInputException + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) */ public function execute(Observer $observer) { @@ -64,7 +65,7 @@ public function execute(Observer $observer) return; } - if($this->customerSession->isLoggedIn() && $this->isPayflowProVaultEnable()) { + if ($this->customerSession->isLoggedIn() && $this->isPayflowProVaultEnable()) { if (!isset($additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER])) { throw new GraphQlInputException( __('Required parameter "is_active_payment_token_enabler" is missing.') diff --git a/app/code/Magento/PaypalGraphQl/composer.json b/app/code/Magento/PaypalGraphQl/composer.json index 8d012be3492dd..6cf790dcfc0f7 100644 --- a/app/code/Magento/PaypalGraphQl/composer.json +++ b/app/code/Magento/PaypalGraphQl/composer.json @@ -13,7 +13,8 @@ "magento/module-quote-graph-ql": "*", "magento/module-sales": "*", "magento/module-payment": "*", - "magento/module-store": "*" + "magento/module-store": "*", + "magento/module-customer": "*" }, "suggest": { "magento/module-graph-ql": "*" From dee50092ec72e5265ced5250aa8842c20fe7a0f6 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 23 Jun 2020 13:30:49 +0300 Subject: [PATCH 05/20] Fix static issue --- app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php index d45db9ae45a32..54d4986d9e1d6 100644 --- a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php +++ b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php @@ -17,6 +17,7 @@ /** * Class PayflowProSetCcData set CcData to quote payment + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) */ class PayflowProSetCcData extends AbstractDataAssignObserver { @@ -53,7 +54,6 @@ public function __construct( * @param Observer $observer * * @throws GraphQlInputException - * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) */ public function execute(Observer $observer) { From 2e6e63ecf38a1b6679cca324c278bf7d5cf692c6 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 24 Jun 2020 22:55:20 +0300 Subject: [PATCH 06/20] Save data using setters --- .../PaypalGraphQl/Observer/PayflowProSetCcData.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php index 54d4986d9e1d6..191d2c0435f60 100644 --- a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php +++ b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php @@ -8,12 +8,12 @@ namespace Magento\PaypalGraphQl\Observer; +use Magento\Customer\Model\Session as CustomerModelSession; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Event\Observer; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Payment\Observer\AbstractDataAssignObserver; use Magento\Quote\Api\Data\PaymentInterface; -use Magento\Customer\Model\Session as CustomerModelSession; /** * Class PayflowProSetCcData set CcData to quote payment @@ -80,9 +80,11 @@ public function execute(Observer $observer) $paymentModel->setData(self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, false); } - foreach ($additionalData['cc_details'] as $ccKey => $ccValue) { - $paymentModel->setData($ccKey, $ccValue); - } + $ccData = $additionalData['cc_details']; + $paymentModel->setCcType($ccData['cc_type']); + $paymentModel->setCcExpYear($ccData['cc_exp_year']); + $paymentModel->setCcExpMonth($ccData['cc_exp_month']); + $paymentModel->setCcLast4($ccData['cc_last_4']); } /** From c28747d0899432aa0978df50396c2795b6cacc44 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 14 Jul 2020 17:55:35 +0300 Subject: [PATCH 07/20] Add description --- app/code/Magento/PaypalGraphQl/etc/schema.graphqls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls index e5adb6f25b1c2..cf7fcebf289a4 100644 --- a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls +++ b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls @@ -51,7 +51,7 @@ input PaymentMethodInput { payflow_link: PayflowLinkInput @doc(description:"Required input for PayPal Payflow Link and Payments Advanced payments") payflowpro: PayflowProInput @doc(description: "Required input type for PayPal Payflow Pro and Payment Pro payments") hosted_pro: HostedProInput @doc(description:"Required input for PayPal Hosted pro payments") - payflowpro_cc_vault: VaultTokenInput + payflowpro_cc_vault: VaultTokenInput @doc(description:"Required input for payment methods with Vault support.") } input HostedProInput @doc(description:"A set of relative URLs that PayPal will use in response to various actions during the authorization process. Magento prepends the base URL to this value to create a full URL. For example, if the full URL is https://www.example.com/path/to/page.html, the relative URL is path/to/page.html. Use this input for Payments Pro Hosted Solution payment method.") { @@ -103,7 +103,7 @@ input PayflowProTokenInput @doc(description:"Input required to fetch payment tok input PayflowProInput @doc(description:"Required input for Payflow Pro and Payments Pro payment methods.") { cc_details: CreditCardDetailsInput! @doc(description: "Required input for credit card related information") - is_active_payment_token_enabler: Boolean @doc(description:"States whether an entered by a customer credit/debit card should be tokenized for later usage. Required only if Vault is enabled for PayPal Payflow Pro payment integration.") + is_active_payment_token_enabler: Boolean @doc(description:"States whether details about the customer's credit/debit card should be tokenized for later usage. Required only if Vault is enabled for PayPal Payflow Pro payment integration.") } input CreditCardDetailsInput @doc(description:"Required fields for Payflow Pro and Payments Pro credit card payments") { From 57b733fdd4a59492b6b09842a287654f8044a759 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 22 Jul 2020 16:00:20 +0300 Subject: [PATCH 08/20] fix issue with cc_type --- .../PaypalGraphQl/Model/Resolver/PayflowProResponse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Model/Resolver/PayflowProResponse.php b/app/code/Magento/PaypalGraphQl/Model/Resolver/PayflowProResponse.php index ce44511c60f3e..b3ddced97aca6 100644 --- a/app/code/Magento/PaypalGraphQl/Model/Resolver/PayflowProResponse.php +++ b/app/code/Magento/PaypalGraphQl/Model/Resolver/PayflowProResponse.php @@ -126,9 +126,9 @@ public function resolve( $this->parameters->fromString(urldecode($paypalPayload)); $data = $this->parameters->toArray(); try { - $do = $this->dataObjectFactory->create(['data' => array_change_key_case($data, CASE_LOWER)]); - $this->responseValidator->validate($do, $this->transparent); - $this->transaction->savePaymentInQuote($do, $cart->getId()); + $response = $this->transaction->getResponseObject($data); + $this->responseValidator->validate($response, $this->transparent); + $this->transaction->savePaymentInQuote($response, $cart->getId()); } catch (LocalizedException $exception) { $parameters['error'] = true; $parameters['error_msg'] = $exception->getMessage(); From 1422df6a8dcdd8aa9cef74fc62c1ccf6fdbbea5a Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Wed, 22 Jul 2020 16:52:51 +0300 Subject: [PATCH 09/20] remove redundant data from graphql schema --- app/code/Magento/PaypalGraphQl/etc/schema.graphqls | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls index cf7fcebf289a4..905e702c512fd 100644 --- a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls +++ b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls @@ -51,7 +51,6 @@ input PaymentMethodInput { payflow_link: PayflowLinkInput @doc(description:"Required input for PayPal Payflow Link and Payments Advanced payments") payflowpro: PayflowProInput @doc(description: "Required input type for PayPal Payflow Pro and Payment Pro payments") hosted_pro: HostedProInput @doc(description:"Required input for PayPal Hosted pro payments") - payflowpro_cc_vault: VaultTokenInput @doc(description:"Required input for payment methods with Vault support.") } input HostedProInput @doc(description:"A set of relative URLs that PayPal will use in response to various actions during the authorization process. Magento prepends the base URL to this value to create a full URL. For example, if the full URL is https://www.example.com/path/to/page.html, the relative URL is path/to/page.html. Use this input for Payments Pro Hosted Solution payment method.") { @@ -143,7 +142,3 @@ input PayflowProResponseInput @doc(description:"Input required to complete payme type PayflowProResponseOutput { cart: Cart! } - -input VaultTokenInput @doc(description:"Required input for payment methods with Vault support.") { - public_hash: String! @doc(description: "The public hash of the payment token") -} From dbb34278aa50eb4ed5e9c428820a059d7199a922 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Mon, 27 Jul 2020 20:20:29 +0300 Subject: [PATCH 10/20] Use plugin for checking is customer logged --- .../Cart/HostedPro/SetPaymentMethodOnCart.php | 5 +- .../PayflowPro/SetPaymentMethodOnCart.php | 72 +++++++++++++++++++ .../Observer/PayflowProSetCcData.php | 15 +--- app/code/Magento/PaypalGraphQl/composer.json | 3 +- .../Magento/PaypalGraphQl/etc/graphql/di.xml | 3 + .../Model/Cart/SetPaymentMethodOnCart.php | 5 +- .../Model/Resolver/SetPaymentMethodOnCart.php | 2 +- 7 files changed, 87 insertions(+), 18 deletions(-) create mode 100644 app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php diff --git a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php index f3353afb7f5b7..f127a9355adfc 100644 --- a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php +++ b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php @@ -8,6 +8,7 @@ namespace Magento\PaypalGraphQl\Model\Plugin\Cart\HostedPro; use Magento\Framework\GraphQl\Exception\GraphQlInputException; +use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Paypal\Model\Config; use Magento\Quote\Model\Quote; use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool; @@ -47,6 +48,7 @@ public function __construct( * @param mixed $result * @param Quote $cart * @param array $paymentData + * @param ContextInterface $context * @return void * @throws GraphQlInputException * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -55,7 +57,8 @@ public function afterExecute( \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject, $result, Quote $cart, - array $paymentData + array $paymentData, + ContextInterface $context ): void { $paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_HOSTEDPRO, $paymentData); diff --git a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php new file mode 100644 index 0000000000000..eb72483f47d4a --- /dev/null +++ b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php @@ -0,0 +1,72 @@ +paymentRepository = $paymentRepository; + $this->additionalDataProviderPool = $additionalDataProviderPool; + } + + /** + * Set redirect URL paths on payment additionalInformation + * + * @param \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject + * @param mixed $result + * @param Quote $cart + * @param array $paymentData + * @return void + * @throws GraphQlInputException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterExecute( + \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject, + $result, + Quote $cart, + array $paymentData, + ContextInterface $context + ): void { + $paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_PAYFLOWPRO, $paymentData); + + if (!$context->getExtensionAttributes()->getIsCustomer() + && array_key_exists(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, $paymentData)) { + $payment = $cart->getPayment(); + $payment->unsAdditionalInformation(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER); + $payment->save(); + } + } +} diff --git a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php index 191d2c0435f60..801ec91d063c5 100644 --- a/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php +++ b/app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php @@ -8,7 +8,6 @@ namespace Magento\PaypalGraphQl\Observer; -use Magento\Customer\Model\Session as CustomerModelSession; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Event\Observer; use Magento\Framework\GraphQl\Exception\GraphQlInputException; @@ -24,11 +23,6 @@ class PayflowProSetCcData extends AbstractDataAssignObserver const XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE = "payment/payflowpro_cc_vault/active"; const IS_ACTIVE_PAYMENT_TOKEN_ENABLER = "is_active_payment_token_enabler"; - /** - * @var CustomerModelSession - */ - private $customerSession; - /** * Core store config * @@ -37,14 +31,11 @@ class PayflowProSetCcData extends AbstractDataAssignObserver private $scopeConfig; /** - * @param CustomerModelSession $customerSession * @param ScopeConfigInterface $scopeConfig */ public function __construct( - CustomerModelSession $customerSession, ScopeConfigInterface $scopeConfig ) { - $this->customerSession = $customerSession; $this->scopeConfig = $scopeConfig; } @@ -65,11 +56,9 @@ public function execute(Observer $observer) return; } - if ($this->customerSession->isLoggedIn() && $this->isPayflowProVaultEnable()) { + if ($this->isPayflowProVaultEnable()) { if (!isset($additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER])) { - throw new GraphQlInputException( - __('Required parameter "is_active_payment_token_enabler" is missing.') - ); + $paymentModel->setData(self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, false); } $paymentModel->setData( diff --git a/app/code/Magento/PaypalGraphQl/composer.json b/app/code/Magento/PaypalGraphQl/composer.json index 6cf790dcfc0f7..8d012be3492dd 100644 --- a/app/code/Magento/PaypalGraphQl/composer.json +++ b/app/code/Magento/PaypalGraphQl/composer.json @@ -13,8 +13,7 @@ "magento/module-quote-graph-ql": "*", "magento/module-sales": "*", "magento/module-payment": "*", - "magento/module-store": "*", - "magento/module-customer": "*" + "magento/module-store": "*" }, "suggest": { "magento/module-graph-ql": "*" diff --git a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml index cd5d6e2062bb9..a83a556b37d42 100644 --- a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml @@ -12,6 +12,9 @@ + + + diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php index 4deb794761efb..56cfcba140081 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php @@ -11,6 +11,7 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; +use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Quote\Api\Data\PaymentInterface; use Magento\Quote\Api\Data\PaymentInterfaceFactory; use Magento\Quote\Api\PaymentMethodManagementInterface; @@ -57,10 +58,12 @@ public function __construct( * * @param Quote $cart * @param array $paymentData + * @param ContextInterface $context * @throws GraphQlInputException * @throws GraphQlNoSuchEntityException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function execute(Quote $cart, array $paymentData): void + public function execute(Quote $cart, array $paymentData, ContextInterface $context): void { if (!isset($paymentData['code']) || empty($paymentData['code'])) { throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.')); diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php index fb6c1e678f1f0..b5e23d237b800 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php @@ -68,7 +68,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); $this->checkCartCheckoutAllowance->execute($cart); - $this->setPaymentMethodOnCart->execute($cart, $paymentData); + $this->setPaymentMethodOnCart->execute($cart, $paymentData, $context); return [ 'cart' => [ From 6b3da47001d7ede2dcb7d6bf78a88140fe2b83b6 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Mon, 27 Jul 2020 21:41:05 +0300 Subject: [PATCH 11/20] fixed static issues --- .../Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php | 1 + app/code/Magento/PaypalGraphQl/etc/graphql/di.xml | 2 -- .../Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php index eb72483f47d4a..1277a2464435d 100644 --- a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php +++ b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php @@ -49,6 +49,7 @@ public function __construct( * @param mixed $result * @param Quote $cart * @param array $paymentData + * @param ContextInterface $context * @return void * @throws GraphQlInputException * @SuppressWarnings(PHPMD.UnusedFormalParameter) diff --git a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml index a83a556b37d42..cbb70d52c401a 100644 --- a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml @@ -11,8 +11,6 @@ - - diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php index 56cfcba140081..80fe860381d04 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php @@ -19,7 +19,7 @@ use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool; /** - * Set payment method on cart + * Set payment method for cart */ class SetPaymentMethodOnCart { From 1baeb2128a59b70defb78d483a6ba669fd294c08 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 28 Jul 2020 14:47:04 +0300 Subject: [PATCH 12/20] Added integration tests --- .../Customer/PlaceOrderWithPayflowProTest.php | 1 - .../SaveCartDataWithPayflowProTest.php | 249 ++++++++++++++++++ 2 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php diff --git a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php index 6a8b6cbc4df61..8ad5e4d98c24e 100644 --- a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php +++ b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php @@ -77,7 +77,6 @@ public function testResolveCustomer(): void payment_method: { code: "{$paymentMethod}", payflowpro: { - is_active_payment_token_enabler: true cc_details: { cc_exp_month: 12, cc_exp_year: 2030, diff --git a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php new file mode 100644 index 0000000000000..d5e0b902311f8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php @@ -0,0 +1,249 @@ +json = $this->objectManager->get(SerializerInterface::class); + $this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class); + } + + /** + * Place order use payflowpro method and save cart data to future + * + * @magentoDataFixture Magento/Sales/_files/default_rollback.php + * @magentoDataFixture Magento/Sales/_files/default_rollback.php + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + * + * @return void + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPlaceOrderAndSaveDataForFuturePayflowPro(): void + { + $responseData = $this->placeOrderPayflowPro('is_active_payment_token_enabler: true'); + $this->assertArrayHasKey('data', $responseData); + $this->assertArrayHasKey('createPayflowProToken', $responseData['data']); + $this->assertTrue($this->getVaultCartData()->getIsActive()); + $this->assertTrue($this->getVaultCartData()->getIsVisible()); + } + + /** + * Place order use payflowpro method and not save cart data to future + * + * @magentoDataFixture Magento/Sales/_files/default_rollback.php + * @magentoDataFixture Magento/Sales/_files/default_rollback.php + * @magentoDataFixture Magento/Customer/_files/customer.php + * @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php + * @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php + * + * @return void + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testPlaceOrderAndNotSaveDataForFuturePayflowPro(): void + { + $responseData = $this->placeOrderPayflowPro('is_active_payment_token_enabler: false'); + $this->assertArrayHasKey('data', $responseData); + $this->assertArrayHasKey('createPayflowProToken', $responseData['data']); + $this->assertTrue($this->getVaultCartData()->getIsActive()); + $this->assertFalse($this->getVaultCartData()->getIsVisible()); + } + + /** + * @param $isActivePaymentTokenEnabler + * + * @return array + */ + private function placeOrderPayflowPro($isActivePaymentTokenEnabler) + { + $paymentMethod = 'payflowpro'; + $this->enablePaymentMethod($paymentMethod); + $this->enablePaymentMethod('payflowpro_cc_vault'); + $reservedQuoteId = 'test_quote'; + + $payload = 'BILLTOCITY=CityM&AMT=0.00&BILLTOSTREET=Green+str,+67&VISACARDLEVEL=12&SHIPTOCITY=CityM' + . '&NAMETOSHIP=John+Smith&ZIP=75477&BILLTOLASTNAME=Smith&BILLTOFIRSTNAME=John' + . '&RESPMSG=Verified&PROCCVV2=M&STATETOSHIP=AL&NAME=John+Smith&BILLTOZIP=75477&CVV2MATCH=Y' + . '&PNREF=B70CCC236815&ZIPTOSHIP=75477&SHIPTOCOUNTRY=US&SHIPTOSTREET=Green+str,+67&CITY=CityM' + . '&HOSTCODE=A&LASTNAME=Smith&STATE=AL&SECURETOKEN=MYSECURETOKEN&CITYTOSHIP=CityM&COUNTRYTOSHIP=US' + . '&AVSDATA=YNY&ACCT=1111&AUTHCODE=111PNI&FIRSTNAME=John&RESULT=0&IAVS=N&POSTFPSMSG=No+Rules+Triggered&' + . 'BILLTOSTATE=AL&BILLTOCOUNTRY=US&EXPDATE=0222&CARDTYPE=0&PREFPSMSG=No+Rules+Triggered&SHIPTOZIP=75477&' + . 'PROCAVS=A&COUNTRY=US&AVSZIP=N&ADDRESS=Green+str,+67&BILLTONAME=John+Smith&' + . 'ADDRESSTOSHIP=Green+str,+67&' + . 'AVSADDR=Y&SECURETOKENID=MYSECURETOKENID&SHIPTOSTATE=AL&TRANSTIME=2019-06-24+07%3A53%3A10'; + + $cart = $this->getQuoteByReservedOrderId($reservedQuoteId); + $cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId()); + + $query = <<objectManager->create(Token::class); + $customerToken = $tokenModel->createCustomerToken(1)->getToken(); + + $requestHeaders = [ + 'Content-Type' => 'application/json', + 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . $customerToken + ]; + $paypalResponse = new DataObject( + [ + 'result' => '0', + 'securetoken' => 'mysecuretoken', + 'securetokenid' => 'mysecuretokenid', + 'respmsg' => 'Approved', + 'result_code' => '0', + ] + ); + + $this->gatewayMock + ->method('postRequest') + ->willReturn($paypalResponse); + + $this->gatewayMock + ->method('postRequest') + ->willReturn( + new DataObject( + [ + 'result' => '0', + 'pnref' => 'A70AAC2378BA', + 'respmsg' => 'Approved', + 'authcode' => '647PNI', + 'avsaddr' => 'Y', + 'avszip' => 'N', + 'hostcode' => 'A', + 'procavs' => 'A', + 'visacardlevel' => '12', + 'transtime' => '2019-06-24 10:12:03', + 'firstname' => 'Cristian', + 'lastname' => 'Partica', + 'amt' => '14.99', + 'acct' => '1111', + 'expdate' => '0221', + 'cardtype' => '0', + 'iavs' => 'N', + 'result_code' => '0', + ] + ) + ); + + $response = $this->graphQlRequest->send($query, [], '', $requestHeaders); + + return $this->json->unserialize($response->getContent()); + } + + /** + * Get saved cart data + * + * @return PaymentTokenInterface + */ + private function getVaultCartData() + { + /** @var PaymentTokenManagement $tokenManagement */ + $tokenManagement = $this->objectManager->get(PaymentTokenManagement::class); + $token = $tokenManagement->getByGatewayToken('B70CCC236815', 'payflowpro',1); + /** @var PaymentTokenRepository $tokenRepository */ + $tokenRepository = $this->objectManager->get(PaymentTokenRepository::class); + return $tokenRepository->getById($token->getEntityId()); + } +} From afaede9ee5eaa54714f869baf348f6aca5ddb076 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 28 Jul 2020 18:05:54 +0300 Subject: [PATCH 13/20] minor fix --- .../Resolver/Customer/SaveCartDataWithPayflowProTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php index d5e0b902311f8..0de3e696613b4 100644 --- a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php +++ b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php @@ -81,8 +81,6 @@ public function testPlaceOrderAndSaveDataForFuturePayflowPro(): void * @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php * * @return void - * - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testPlaceOrderAndNotSaveDataForFuturePayflowPro(): void { @@ -97,6 +95,7 @@ public function testPlaceOrderAndNotSaveDataForFuturePayflowPro(): void * @param $isActivePaymentTokenEnabler * * @return array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ private function placeOrderPayflowPro($isActivePaymentTokenEnabler) { @@ -241,7 +240,11 @@ private function getVaultCartData() { /** @var PaymentTokenManagement $tokenManagement */ $tokenManagement = $this->objectManager->get(PaymentTokenManagement::class); - $token = $tokenManagement->getByGatewayToken('B70CCC236815', 'payflowpro',1); + $token = $tokenManagement->getByGatewayToken( + 'B70CCC236815', + 'payflowpro', + 1 + ); /** @var PaymentTokenRepository $tokenRepository */ $tokenRepository = $this->objectManager->get(PaymentTokenRepository::class); return $tokenRepository->getById($token->getEntityId()); From 986d5b19fc7edd126210fe5b4b6c6eab7532462a Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 28 Jul 2020 19:01:19 +0300 Subject: [PATCH 14/20] get customer id from cart not context --- .../Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php | 5 +---- .../Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php | 10 +++------- .../QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php | 6 ++---- .../Model/Resolver/SetPaymentMethodOnCart.php | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php index f127a9355adfc..f3353afb7f5b7 100644 --- a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php +++ b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/HostedPro/SetPaymentMethodOnCart.php @@ -8,7 +8,6 @@ namespace Magento\PaypalGraphQl\Model\Plugin\Cart\HostedPro; use Magento\Framework\GraphQl\Exception\GraphQlInputException; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Paypal\Model\Config; use Magento\Quote\Model\Quote; use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool; @@ -48,7 +47,6 @@ public function __construct( * @param mixed $result * @param Quote $cart * @param array $paymentData - * @param ContextInterface $context * @return void * @throws GraphQlInputException * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -57,8 +55,7 @@ public function afterExecute( \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject, $result, Quote $cart, - array $paymentData, - ContextInterface $context + array $paymentData ): void { $paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_HOSTEDPRO, $paymentData); diff --git a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php index 1277a2464435d..30f57f898f070 100644 --- a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php +++ b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php @@ -8,7 +8,6 @@ namespace Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowPro; use Magento\Framework\GraphQl\Exception\GraphQlInputException; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Paypal\Model\Config; use Magento\Quote\Model\Quote; use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool; @@ -49,7 +48,6 @@ public function __construct( * @param mixed $result * @param Quote $cart * @param array $paymentData - * @param ContextInterface $context * @return void * @throws GraphQlInputException * @SuppressWarnings(PHPMD.UnusedFormalParameter) @@ -58,13 +56,11 @@ public function afterExecute( \Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart $subject, $result, Quote $cart, - array $paymentData, - ContextInterface $context + array $paymentData ): void { $paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_PAYFLOWPRO, $paymentData); - - if (!$context->getExtensionAttributes()->getIsCustomer() - && array_key_exists(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, $paymentData)) { + $cartCustomerId = (int)$cart->getCustomerId(); + if ($cartCustomerId === 0 && array_key_exists(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, $paymentData)) { $payment = $cart->getPayment(); $payment->unsAdditionalInformation(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER); $payment->save(); diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php index 80fe860381d04..0fee0f2ae1549 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php @@ -11,7 +11,6 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; -use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Quote\Api\Data\PaymentInterface; use Magento\Quote\Api\Data\PaymentInterfaceFactory; use Magento\Quote\Api\PaymentMethodManagementInterface; @@ -19,7 +18,7 @@ use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool; /** - * Set payment method for cart + * Set payment method on cart */ class SetPaymentMethodOnCart { @@ -58,12 +57,11 @@ public function __construct( * * @param Quote $cart * @param array $paymentData - * @param ContextInterface $context * @throws GraphQlInputException * @throws GraphQlNoSuchEntityException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function execute(Quote $cart, array $paymentData, ContextInterface $context): void + public function execute(Quote $cart, array $paymentData): void { if (!isset($paymentData['code']) || empty($paymentData['code'])) { throw new GraphQlInputException(__('Required parameter "code" for "payment_method" is missing.')); diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php index b5e23d237b800..fb6c1e678f1f0 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php @@ -68,7 +68,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value $storeId = (int)$context->getExtensionAttributes()->getStore()->getId(); $cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId); $this->checkCartCheckoutAllowance->execute($cart); - $this->setPaymentMethodOnCart->execute($cart, $paymentData, $context); + $this->setPaymentMethodOnCart->execute($cart, $paymentData); return [ 'cart' => [ From 6925546abeab5e75b0f9bf997db7f5062775e230 Mon Sep 17 00:00:00 2001 From: Oleh Usik Date: Tue, 28 Jul 2020 22:52:06 +0300 Subject: [PATCH 15/20] minor fix --- .../Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php | 3 ++- .../Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php index 30f57f898f070..7ca4d41cfd33a 100644 --- a/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php +++ b/app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php @@ -60,7 +60,8 @@ public function afterExecute( ): void { $paymentData = $this->additionalDataProviderPool->getData(Config::METHOD_PAYFLOWPRO, $paymentData); $cartCustomerId = (int)$cart->getCustomerId(); - if ($cartCustomerId === 0 && array_key_exists(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, $paymentData)) { + if ($cartCustomerId === 0 && + array_key_exists(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, $paymentData)) { $payment = $cart->getPayment(); $payment->unsAdditionalInformation(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER); $payment->save(); diff --git a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php index 0fee0f2ae1549..4deb794761efb 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php +++ b/app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php @@ -59,7 +59,6 @@ public function __construct( * @param array $paymentData * @throws GraphQlInputException * @throws GraphQlNoSuchEntityException - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(Quote $cart, array $paymentData): void { From 065c78027a30f1ae4e65d6927c5535c4398e60cd Mon Sep 17 00:00:00 2001 From: Prabhu Ram Date: Wed, 29 Jul 2020 13:41:17 -0500 Subject: [PATCH 16/20] Added store config for payflowpro vault --- app/code/Magento/PaypalGraphQl/etc/graphql/di.xml | 8 ++++++++ app/code/Magento/PaypalGraphQl/etc/schema.graphqls | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml index cbb70d52c401a..9c884aa32ace4 100644 --- a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml @@ -54,4 +54,12 @@ + + + + + payment/payflowpro_cc_vault/active + + + diff --git a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls index 905e702c512fd..2cefc7d0c68af 100644 --- a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls +++ b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls @@ -142,3 +142,7 @@ input PayflowProResponseInput @doc(description:"Input required to complete payme type PayflowProResponseOutput { cart: Cart! } + +type StoreConfig { + payflowpro_vault_enabled: String @doc(description: "Payflowpro vault status.") +} From d47baa8c9cb5be44fbd145b902d8456bde35c83b Mon Sep 17 00:00:00 2001 From: Prabhu Ram Date: Wed, 29 Jul 2020 13:45:10 -0500 Subject: [PATCH 17/20] composer changes for store config --- app/code/Magento/PaypalGraphQl/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/PaypalGraphQl/composer.json b/app/code/Magento/PaypalGraphQl/composer.json index 8d012be3492dd..13864e54fa1f5 100644 --- a/app/code/Magento/PaypalGraphQl/composer.json +++ b/app/code/Magento/PaypalGraphQl/composer.json @@ -16,7 +16,8 @@ "magento/module-store": "*" }, "suggest": { - "magento/module-graph-ql": "*" + "magento/module-graph-ql": "*", + "magento/module-store-graph-ql": "*" }, "type": "magento2-module", "license": [ From fd8e270122df128ff7f2e46840bca31a91e7651e Mon Sep 17 00:00:00 2001 From: Prabhu Ram Date: Wed, 29 Jul 2020 16:42:12 -0500 Subject: [PATCH 18/20] added better naming for store config field --- app/code/Magento/PaypalGraphQl/etc/graphql/di.xml | 2 +- app/code/Magento/PaypalGraphQl/etc/schema.graphqls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml index 9c884aa32ace4..f1b99295f5627 100644 --- a/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/PaypalGraphQl/etc/graphql/di.xml @@ -58,7 +58,7 @@ - payment/payflowpro_cc_vault/active + payment/payflowpro_cc_vault/active diff --git a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls index 2cefc7d0c68af..52b0a6ec97518 100644 --- a/app/code/Magento/PaypalGraphQl/etc/schema.graphqls +++ b/app/code/Magento/PaypalGraphQl/etc/schema.graphqls @@ -144,5 +144,5 @@ type PayflowProResponseOutput { } type StoreConfig { - payflowpro_vault_enabled: String @doc(description: "Payflowpro vault status.") + payment_payflowpro_cc_vault_active: String @doc(description: "Payflow Pro vault status.") } From 3c9406da38d53cb0c1430aed258b0a3d29af2c79 Mon Sep 17 00:00:00 2001 From: Anusha Vattam Date: Fri, 31 Jul 2020 13:43:09 -0500 Subject: [PATCH 19/20] Added few new assertions on to SaveCartDataWithPayflowProTest --- .../Resolver/Customer/SaveCartDataWithPayflowProTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php index 0de3e696613b4..ebe8a579cc56a 100644 --- a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php +++ b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php @@ -63,6 +63,10 @@ public function testPlaceOrderAndSaveDataForFuturePayflowPro(): void $responseData = $this->placeOrderPayflowPro('is_active_payment_token_enabler: true'); $this->assertArrayHasKey('data', $responseData); $this->assertArrayHasKey('createPayflowProToken', $responseData['data']); + $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); + $this->assertNotEmpty($this->getVaultCartData()->getTokenDetails()); + $this->assertNotEmpty($this->getVaultCartData()->getGatewayToken()); + $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); $this->assertTrue($this->getVaultCartData()->getIsActive()); $this->assertTrue($this->getVaultCartData()->getIsVisible()); } @@ -87,6 +91,10 @@ public function testPlaceOrderAndNotSaveDataForFuturePayflowPro(): void $responseData = $this->placeOrderPayflowPro('is_active_payment_token_enabler: false'); $this->assertArrayHasKey('data', $responseData); $this->assertArrayHasKey('createPayflowProToken', $responseData['data']); + $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); + $this->assertNotEmpty($this->getVaultCartData()->getTokenDetails()); + $this->assertNotEmpty($this->getVaultCartData()->getGatewayToken()); + $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); $this->assertTrue($this->getVaultCartData()->getIsActive()); $this->assertFalse($this->getVaultCartData()->getIsVisible()); } From 05e9e4e584f055243f1f5aa1354ce7ddf21e9f4b Mon Sep 17 00:00:00 2001 From: Anusha Vattam Date: Mon, 3 Aug 2020 11:39:48 -0500 Subject: [PATCH 20/20] Removed duplicated assertion --- .../Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php index ebe8a579cc56a..11bd306211b9a 100644 --- a/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php +++ b/dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/SaveCartDataWithPayflowProTest.php @@ -66,7 +66,6 @@ public function testPlaceOrderAndSaveDataForFuturePayflowPro(): void $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); $this->assertNotEmpty($this->getVaultCartData()->getTokenDetails()); $this->assertNotEmpty($this->getVaultCartData()->getGatewayToken()); - $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); $this->assertTrue($this->getVaultCartData()->getIsActive()); $this->assertTrue($this->getVaultCartData()->getIsVisible()); } @@ -94,7 +93,6 @@ public function testPlaceOrderAndNotSaveDataForFuturePayflowPro(): void $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); $this->assertNotEmpty($this->getVaultCartData()->getTokenDetails()); $this->assertNotEmpty($this->getVaultCartData()->getGatewayToken()); - $this->assertNotEmpty($this->getVaultCartData()->getPublicHash()); $this->assertTrue($this->getVaultCartData()->getIsActive()); $this->assertFalse($this->getVaultCartData()->getIsVisible()); }