Skip to content

Commit

Permalink
🔃 [GraphQL] Community Contributions - 2.4-develop
Browse files Browse the repository at this point in the history
Accepted Community Pull Requests:
 - #28821: [GraphQL] Paypal PayFlowPro store the payment details in myaccount for future (by @Usik2203)


Fixed GitHub Issues:
 - #28520: Implement the schema for PayPal PayFloPro (reported by @nrkapoor) has been fixed in #28821 by @Usik2203 in 2.4-develop branch
   Related commits:
     1. d29468d
     2. e798f75
     3. 934db87
     4. aef0f96
     5. dee5009
     6. 2e6e63e
     7. f714e12
     8. 009a3ba
     9. c28747d
     10. 6596e65
     11. d6a2fb7
     12. 57b733f
     13. 1422df6
     14. dbb3427
     15. 6b3da47
     16. 1baeb21
     17. 7bd8e06
     18. afaede9
     19. 986d5b1
     20. 6925546
     21. d723f24
     22. 065c780
     23. d47baa8
     24. a37e651
     25. fd8e270
     26. af7ece4
     27. 47d7be2
     28. 3c9406d
     29. e4d71d1
     30. 05e9e4e
     31. db47d6c

 - #28558: Implement the schema for PayPal PayFloPro (reported by @magento-engcom-team) has been fixed in #28821 by @Usik2203 in 2.4-develop branch
   Related commits:
     1. d29468d
     2. e798f75
     3. 934db87
     4. aef0f96
     5. dee5009
     6. 2e6e63e
     7. f714e12
     8. 009a3ba
     9. c28747d
     10. 6596e65
     11. d6a2fb7
     12. 57b733f
     13. 1422df6
     14. dbb3427
     15. 6b3da47
     16. 1baeb21
     17. 7bd8e06
     18. afaede9
     19. 986d5b1
     20. 6925546
     21. d723f24
     22. 065c780
     23. d47baa8
     24. a37e651
     25. fd8e270
     26. af7ece4
     27. 47d7be2
     28. 3c9406d
     29. e4d71d1
     30. 05e9e4e
     31. db47d6c
  • Loading branch information
magento-engcom-team authored Aug 7, 2020
2 parents 42311fa + 97e3946 commit d598c12
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 4 deletions.
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
88 changes: 88 additions & 0 deletions app/code/Magento/PaypalGraphQl/Observer/PayflowProSetCcData.php
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);
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/PaypalGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
9 changes: 9 additions & 0 deletions app/code/Magento/PaypalGraphQl/etc/graphql/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</type>
<type name="Magento\QuoteGraphQl\Model\Cart\SetPaymentMethodOnCart">
<plugin name="hosted_pro_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\HostedPro\SetPaymentMethodOnCart"/>
<plugin name="payflowpro_payment_method" type="Magento\PaypalGraphQl\Model\Plugin\Cart\PayflowPro\SetPaymentMethodOnCart"/>
</type>
<type name="Magento\Paypal\Model\Payflowlink">
<plugin name="payflow_link_update_redirect_urls" type="Magento\PaypalGraphQl\Model\Plugin\Payflowlink"/>
Expand Down Expand Up @@ -53,4 +54,12 @@
</argument>
</arguments>
</type>

<type name="Magento\StoreGraphQl\Model\Resolver\Store\StoreConfigDataProvider">
<arguments>
<argument name="extendedConfigData" xsi:type="array">
<item name="payment_payflowpro_cc_vault_active" xsi:type="string">payment/payflowpro_cc_vault/active</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/PaypalGraphQl/etc/graphql/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<event name="payment_method_assign_data_payflow_advanced">
<observer name="payflow_advanced_data_assigner" instance="Magento\PaypalGraphQl\Observer\PayflowLinkSetAdditionalData"/>
</event>
<event name="payment_method_assign_data_payflowpro">
<observer name="payflowpro_cc_data_assigner" instance="Magento\PaypalGraphQl\Observer\PayflowProSetCcData" />
</event>
</config>
5 changes: 5 additions & 0 deletions app/code/Magento/PaypalGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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 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") {
Expand Down Expand Up @@ -141,3 +142,7 @@ input PayflowProResponseInput @doc(description:"Input required to complete payme
type PayflowProResponseOutput {
cart: Cart!
}

type StoreConfig {
payment_payflowpro_cc_vault_active: String @doc(description: "Payflow Pro vault status.")
}
Loading

0 comments on commit d598c12

Please sign in to comment.