Skip to content

Commit 934db87

Browse files
committed
Add some checks
1 parent e798f75 commit 934db87

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,89 @@
88

99
namespace Magento\PaypalGraphQl\Observer;
1010

11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\Event\Observer;
13+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1214
use Magento\Payment\Observer\AbstractDataAssignObserver;
1315
use Magento\Quote\Api\Data\PaymentInterface;
16+
use Magento\Customer\Model\Session as CustomerModelSession;
1417

1518
/**
1619
* Class PayflowProSetCcData set CcData to quote payment
1720
*/
1821
class PayflowProSetCcData extends AbstractDataAssignObserver
1922
{
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+
2050
/**
2151
* Set CcData
2252
*
2353
* @param Observer $observer
54+
*
55+
* @throws GraphQlInputException
2456
*/
2557
public function execute(Observer $observer)
2658
{
2759
$dataObject = $this->readDataArgument($observer);
2860
$additionalData = $dataObject->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
61+
$paymentModel = $this->readPaymentModelArgument($observer);
2962

3063
if (!isset($additionalData['cc_details'])) {
3164
return;
3265
}
3366

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+
3582
foreach ($additionalData['cc_details'] as $ccKey => $ccValue) {
3683
$paymentModel->setData($ccKey, $ccValue);
3784
}
3885
}
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+
}
3996
}

app/code/Magento/PaypalGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ input PayflowProTokenInput @doc(description:"Input required to fetch payment tok
103103

104104
input PayflowProInput @doc(description:"Required input for Payflow Pro and Payments Pro payment methods.") {
105105
cc_details: CreditCardDetailsInput! @doc(description: "Required input for credit card related information")
106-
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.")
106+
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.")
107107
}
108108

109109
input CreditCardDetailsInput @doc(description:"Required fields for Payflow Pro and Payments Pro credit card payments") {

dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function testResolveCustomer(): void
7777
payment_method: {
7878
code: "{$paymentMethod}",
7979
payflowpro: {
80+
is_active_payment_token_enabler: true
8081
cc_details: {
8182
cc_exp_month: 12,
8283
cc_exp_year: 2030,

0 commit comments

Comments
 (0)