|
8 | 8 |
|
9 | 9 | namespace Magento\PaypalGraphQl\Observer;
|
10 | 10 |
|
| 11 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
11 | 12 | use Magento\Framework\Event\Observer;
|
| 13 | +use Magento\Framework\GraphQl\Exception\GraphQlInputException; |
12 | 14 | use Magento\Payment\Observer\AbstractDataAssignObserver;
|
13 | 15 | use Magento\Quote\Api\Data\PaymentInterface;
|
| 16 | +use Magento\Customer\Model\Session as CustomerModelSession; |
14 | 17 |
|
15 | 18 | /**
|
16 | 19 | * Class PayflowProSetCcData set CcData to quote payment
|
17 | 20 | */
|
18 | 21 | class PayflowProSetCcData extends AbstractDataAssignObserver
|
19 | 22 | {
|
| 23 | + const XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE = "payment/payflowpro_cc_vault/active"; |
| 24 | + const IS_ACTIVE_PAYMENT_TOKEN_ENABLER = "is_active_payment_token_enabler"; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var CustomerModelSession |
| 28 | + */ |
| 29 | + private $customerSession; |
| 30 | + |
| 31 | + /** |
| 32 | + * Core store config |
| 33 | + * |
| 34 | + * @var ScopeConfigInterface |
| 35 | + */ |
| 36 | + private $scopeConfig; |
| 37 | + |
| 38 | + /** |
| 39 | + * @param CustomerModelSession $customerSession |
| 40 | + * @param ScopeConfigInterface $scopeConfig |
| 41 | + */ |
| 42 | + public function __construct( |
| 43 | + CustomerModelSession $customerSession, |
| 44 | + ScopeConfigInterface $scopeConfig |
| 45 | + ) { |
| 46 | + $this->customerSession = $customerSession; |
| 47 | + $this->scopeConfig = $scopeConfig; |
| 48 | + } |
| 49 | + |
20 | 50 | /**
|
21 | 51 | * Set CcData
|
22 | 52 | *
|
23 | 53 | * @param Observer $observer
|
| 54 | + * |
| 55 | + * @throws GraphQlInputException |
24 | 56 | */
|
25 | 57 | public function execute(Observer $observer)
|
26 | 58 | {
|
27 | 59 | $dataObject = $this->readDataArgument($observer);
|
28 | 60 | $additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
|
| 61 | + $paymentModel = $this->readPaymentModelArgument($observer); |
29 | 62 |
|
30 | 63 | if (!isset($additionalData['cc_details'])) {
|
31 | 64 | return;
|
32 | 65 | }
|
33 | 66 |
|
34 |
| - $paymentModel = $this->readPaymentModelArgument($observer); |
| 67 | + if($this->customerSession->isLoggedIn() && $this->isPayflowProVaultEnable()) { |
| 68 | + if (!isset($additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER])) { |
| 69 | + throw new GraphQlInputException( |
| 70 | + __('Required parameter "is_active_payment_token_enabler" is missing.') |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + $paymentModel->setData( |
| 75 | + self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, |
| 76 | + $additionalData[self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER] |
| 77 | + ); |
| 78 | + } else { |
| 79 | + $paymentModel->setData(self::IS_ACTIVE_PAYMENT_TOKEN_ENABLER, false); |
| 80 | + } |
| 81 | + |
35 | 82 | foreach ($additionalData['cc_details'] as $ccKey => $ccValue) {
|
36 | 83 | $paymentModel->setData($ccKey, $ccValue);
|
37 | 84 | }
|
38 | 85 | }
|
| 86 | + |
| 87 | + /** |
| 88 | + * Check if payflowpro vault is enable |
| 89 | + * |
| 90 | + * @return bool |
| 91 | + */ |
| 92 | + private function isPayflowProVaultEnable() |
| 93 | + { |
| 94 | + return (bool)$this->scopeConfig->getValue(self::XML_PATH_PAYMENT_PAYFLOWPRO_CC_VAULT_ACTIVE); |
| 95 | + } |
39 | 96 | }
|
0 commit comments