-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[GraphQL] Paypal PayFlowPro store the payment details in myaccount for future #28821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 31 commits into
magento:2.4-develop
from
Usik2203:paypalflowpro-graphql
Aug 27, 2020
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
d29468d
add data to schema
Usik2203 e798f75
add cc data
Usik2203 934db87
Add some checks
Usik2203 aef0f96
fix static issues
Usik2203 dee5009
Fix static issue
Usik2203 2e6e63e
Save data using setters
Usik2203 f714e12
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 009a3ba
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 c28747d
Add description
Usik2203 6596e65
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 d6a2fb7
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 57b733f
fix issue with cc_type
Usik2203 1422df6
remove redundant data from graphql schema
Usik2203 dbb3427
Use plugin for checking is customer logged
Usik2203 6b3da47
fixed static issues
Usik2203 1baeb21
Added integration tests
Usik2203 7bd8e06
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 afaede9
minor fix
Usik2203 986d5b1
get customer id from cart not context
Usik2203 6925546
minor fix
Usik2203 d723f24
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 065c780
Added store config for payflowpro vault
d47baa8
composer changes for store config
a37e651
Merge branch 'paypalflowpro-graphql' of github.com:Usik2203/magento2 …
dthampy fd8e270
added better naming for store config field
af7ece4
Merge branch 'paypalflowpro-graphql' of github.com:Usik2203/magento2 …
47d7be2
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 3c9406d
Added few new assertions on to SaveCartDataWithPayflowProTest
avattam06 e4d71d1
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 05e9e4e
Removed duplicated assertion
avattam06 db47d6c
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
app/code/Magento/PaypalGraphQl/Model/Plugin/Cart/PayflowPro/SetPaymentMethodOnCart.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowPro; | ||
|
|
||
| use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
| use Magento\Paypal\Model\Config; | ||
| use Magento\Quote\Model\Quote; | ||
| use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool; | ||
| use Magento\Sales\Model\Order\Payment\Repository as PaymentRepository; | ||
| use Magento\PaypalGraphQl\Observer\PayflowProSetCcData; | ||
|
|
||
| /** | ||
| * Set additionalInformation on payment for PayflowPro method | ||
| */ | ||
| class SetPaymentMethodOnCart | ||
| { | ||
| /** | ||
| * @var PaymentRepository | ||
| */ | ||
| private $paymentRepository; | ||
|
|
||
| /** | ||
| * @var AdditionalDataProviderPool | ||
| */ | ||
| private $additionalDataProviderPool; | ||
|
|
||
| /** | ||
| * @param PaymentRepository $paymentRepository | ||
| * @param AdditionalDataProviderPool $additionalDataProviderPool | ||
| */ | ||
| public function __construct( | ||
| PaymentRepository $paymentRepository, | ||
| AdditionalDataProviderPool $additionalDataProviderPool | ||
| ) { | ||
| $this->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 | ||
| ): 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)) { | ||
| $payment = $cart->getPayment(); | ||
| $payment->unsAdditionalInformation(PayflowProSetCcData::IS_ACTIVE_PAYMENT_TOKEN_ENABLER); | ||
| $payment->save(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| 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; | ||
|
|
||
| /** | ||
| * Class PayflowProSetCcData set CcData to quote payment | ||
| * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) | ||
| */ | ||
| 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"; | ||
|
|
||
| /** | ||
| * Core store config | ||
| * | ||
| * @var ScopeConfigInterface | ||
| */ | ||
| private $scopeConfig; | ||
|
|
||
| /** | ||
| * @param ScopeConfigInterface $scopeConfig | ||
| */ | ||
| public function __construct( | ||
| ScopeConfigInterface $scopeConfig | ||
| ) { | ||
| $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; | ||
| } | ||
|
|
||
| if ($this->isPayflowProVaultEnable()) { | ||
| if (!isset($additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER])) { | ||
| $paymentModel->setData(self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, false); | ||
| } | ||
|
|
||
| $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); | ||
| } | ||
|
|
||
| $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']); | ||
| } | ||
|
|
||
| /** | ||
| * Check if payflowpro vault is enable | ||
| * | ||
| * @return bool | ||
| */ | ||
| private function isPayflowProVaultEnable() | ||
| { | ||
| return (bool)$this->scopeConfig->getValue(self::XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.