-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-7916: [GraphQL] PayFlowPro store the payment details in myacco…
…unt for future #28821
- Loading branch information
Showing
8 changed files
with
438 additions
and
4 deletions.
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 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 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 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 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 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 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 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.