Skip to content
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

[GraphQL] Paypal PayFlowPro store the payment details in myaccount for future #28821

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d29468d
add data to schema
Usik2203 Jun 10, 2020
e798f75
add cc data
Usik2203 Jun 21, 2020
934db87
Add some checks
Usik2203 Jun 22, 2020
aef0f96
fix static issues
Usik2203 Jun 23, 2020
dee5009
Fix static issue
Usik2203 Jun 23, 2020
2e6e63e
Save data using setters
Usik2203 Jun 24, 2020
f714e12
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 Jul 8, 2020
009a3ba
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 Jul 10, 2020
c28747d
Add description
Usik2203 Jul 14, 2020
6596e65
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 Jul 14, 2020
d6a2fb7
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 Jul 21, 2020
57b733f
fix issue with cc_type
Usik2203 Jul 22, 2020
1422df6
remove redundant data from graphql schema
Usik2203 Jul 22, 2020
dbb3427
Use plugin for checking is customer logged
Usik2203 Jul 27, 2020
6b3da47
fixed static issues
Usik2203 Jul 27, 2020
1baeb21
Added integration tests
Usik2203 Jul 28, 2020
7bd8e06
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 Jul 28, 2020
afaede9
minor fix
Usik2203 Jul 28, 2020
986d5b1
get customer id from cart not context
Usik2203 Jul 28, 2020
6925546
minor fix
Usik2203 Jul 28, 2020
d723f24
Merge branch '2.4-develop' into paypalflowpro-graphql
Usik2203 Jul 28, 2020
065c780
Added store config for payflowpro vault
prabhuram93 Jul 29, 2020
d47baa8
composer changes for store config
prabhuram93 Jul 29, 2020
a37e651
Merge branch 'paypalflowpro-graphql' of github.com:Usik2203/magento2 …
dthampy Jul 29, 2020
fd8e270
added better naming for store config field
prabhuram93 Jul 29, 2020
af7ece4
Merge branch 'paypalflowpro-graphql' of github.com:Usik2203/magento2 …
prabhuram93 Jul 29, 2020
47d7be2
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 Jul 30, 2020
3c9406d
Added few new assertions on to SaveCartDataWithPayflowProTest
avattam06 Jul 31, 2020
e4d71d1
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 Jul 31, 2020
05e9e4e
Removed duplicated assertion
avattam06 Aug 3, 2020
db47d6c
Merge branch '2.4-develop' into paypalflowpro-graphql
avattam06 Aug 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="payflowpro_vault_enabled" 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.")
}
avattam06 marked this conversation as resolved.
Show resolved Hide resolved

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 {
payflowpro_vault_enabled: String @doc(description: "Payflowpro vault status.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keharper @joni-jones I added a store config field for vault. Let me know if the name/description needs to be updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prabhuram93, my understanding that for StoreConfig values, we follow the same semantic as in config.xml. For Payflow Pro it will be payment_payflowpro_cc_vault_active.

cc @paliarush

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joni-jones We were doing that until we implemented aliasing. We can have custom field names that are not tied to config.xml. But if you feel payment_payflowpro_cc_vault_active is more relevant I can update accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the description to Payflow Pro to match PayPal's branding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have aliases now, let's use whatever makes the most sense from the API client perspective. We also need to make sure to have proper namespaces to prevent conflicts in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @paliarush payment_payflowpro_cc_vault_active has better namespacing. @joni-jones I am gonna go with that.

}
Loading