Skip to content

Commit eea0ef0

Browse files
authored
Merge pull request #4424 from magento-honey-badgers/payflow-graphql-pr
[honey] Payflow Pro and Payflow Link GraphQl Support
2 parents f77ac3c + 20e1b0d commit eea0ef0

40 files changed

+2720
-59
lines changed

app/code/Magento/Backend/Test/Mftf/Test/AdminLoginTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88

99
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10-
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
1111
<test name="AdminLoginTest">
1212
<annotations>
1313
<features value="Backend"/>
@@ -24,4 +24,4 @@
2424
<seeInCurrentUrl url="{{AdminLoginPage.url}}" stepKey="seeAdminLoginUrl"/>
2525
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
2626
</test>
27-
</tests>
27+
</tests>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminPrivacyPolicyTest">
12+
<annotations>
13+
<features value="Backend"/>
14+
<stories value="Checks to see if privacy policy url is in the admin page and every sub page"/>
15+
<title value="There should be a privacy policy url in the admin page and every sub page"/>
16+
<description value="There should be a privacy policy url in the admin page and every sub page"/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="MC-17787"/>
19+
<group value="backend"/>
20+
<group value="login"/>
21+
</annotations>
22+
23+
<!-- Logging in Magento admin and checking for Privacy policy footer in dashboard -->
24+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
25+
<closeAdminNotification stepKey="closeAdminNotification"/>
26+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkDashboard"/>
27+
28+
<!-- Checking for Privacy policy footer in salesOrderPage -->
29+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToSalesOrder">
30+
<argument name="menuUiId" value="magento-sales-sales"/>
31+
<argument name="submenuUiId" value="magento-sales-sales-order"/>
32+
</actionGroup>
33+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkSalesOrder"/>
34+
35+
<!-- Checking for Privacy policy footer in catalogProductsPage -->
36+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToCatalogProducts">
37+
<argument name="menuUiId" value="magento-catalog-catalog"/>
38+
<argument name="submenuUiId" value="magento-catalog-catalog-products"/>
39+
</actionGroup>
40+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkCatalogProducts"/>
41+
42+
<!-- Checking for Privacy policy footer in customersAllCustomersPage -->
43+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToCustomersAllCustomers">
44+
<argument name="menuUiId" value="magento-customer-customer"/>
45+
<argument name="submenuUiId" value="magento-customer-customer-manage"/>
46+
</actionGroup>
47+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkCustomersAllCustomers"/>
48+
49+
<!-- Checking for Privacy policy footer in marketingCatalogPriceRulePage -->
50+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToMarketingCatalogPriceRule">
51+
<argument name="menuUiId" value="magento-backend-marketing"/>
52+
<argument name="submenuUiId" value="magento-catalogrule-promo-catalog"/>
53+
</actionGroup>
54+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkMarketingCatalogPriceRule"/>
55+
56+
<!-- Checking for Privacy policy footer in contentBlocksPage -->
57+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToContentBlocks">
58+
<argument name="menuUiId" value="magento-backend-content"/>
59+
<argument name="submenuUiId" value="magento-cms-cms-block"/>
60+
</actionGroup>
61+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkContentBlocks"/>
62+
63+
<!-- Checking for Privacy policy footer in reportSearcbTermsPage -->
64+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToReportsSearchTerms">
65+
<argument name="menuUiId" value="magento-reports-report"/>
66+
<argument name="submenuUiId" value="magento-search-report-search-term"/>
67+
</actionGroup>
68+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkReportsSearchTerms"/>
69+
70+
<!-- Checking for Privacy policy footer in storesAllStoresPage -->
71+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToStoresAllStores">
72+
<argument name="menuUiId" value="magento-backend-stores"/>
73+
<argument name="submenuUiId" value="magento-backend-system-store"/>
74+
</actionGroup>
75+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkStoresAllStores"/>
76+
77+
<!-- Checking for Privacy policy footer in systemImportPage -->
78+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToSystemImport">
79+
<argument name="menuUiId" value="magento-backend-system"/>
80+
<argument name="submenuUiId" value="magento-importexport-system-convert-import"/>
81+
</actionGroup>
82+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkSystemImport"/>
83+
84+
<!-- Checking for Privacy policy footer in findPartnersAndExtensionsPage -->
85+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToFindPartnersAndExtensions">
86+
<argument name="menuUiId" value="magento-marketplace-partners"/>
87+
<argument name="submenuUiId" value="magento-marketplace-partners"/>
88+
</actionGroup>
89+
<seeLink userInput="Privacy Policy" url="https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf" stepKey="seePrivacyPolicyLinkFindPartnersAndExtensions"/>
90+
</test>
91+
</tests>
92+
93+

app/code/Magento/Backend/view/adminhtml/layout/default.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@
6060
</container>
6161
<container name="legal.system" htmlTag="div" htmlClass="footer-legal-system col-m-6">
6262
<block class="Magento\Backend\Block\Page\Footer" name="version" as="version" />
63+
<block class="Magento\Framework\View\Element\Template" name="privacyPolicy" as="privacyPolicy" template="Magento_Backend::page/privacyPolicy.phtml">
64+
<arguments>
65+
<argument name="privacypolicy_url" xsi:type="string">https://magento.com/sites/default/files/REVISED-MAGENTO-PRIVACY-POLICY.pdf</argument>
66+
</arguments>
67+
</block>
6368
<block class="Magento\Framework\View\Element\Template" name="report" as="report" template="Magento_Backend::page/report.phtml">
6469
<arguments>
6570
<argument name="bugreport_url" xsi:type="string">https://github.com/magento/magento2/issues</argument>
6671
</arguments>
6772
</block>
73+
6874
</container>
6975
</container>
7076
</referenceContainer>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
?>
8+
9+
<a class="link-report" href="<?= $block->escapeUrl($block->getPrivacypolicyUrl()) ?>" id="footer_privacy" target="_blank">
10+
<?= $block->escapeHtml(__('Privacy Policy')) ?>
11+
</a> |

app/code/Magento/Paypal/Controller/Transparent/Response.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
use Magento\Paypal\Model\Payflow\Transparent;
2020
use Magento\Sales\Api\PaymentFailuresInterface;
2121
use Magento\Framework\Session\Generic as Session;
22+
use Magento\Framework\App\Action\HttpPostActionInterface;
2223

2324
/**
25+
* Class for requesting the response result form the paypal controller.
2426
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2527
*/
26-
class Response extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface
28+
class Response extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface, HttpPostActionInterface
2729
{
2830
/**
2931
* Core registry
@@ -112,6 +114,8 @@ public function validateForCsrf(RequestInterface $request): ?bool
112114
}
113115

114116
/**
117+
* Saves the payment in quote
118+
*
115119
* @return ResultInterface
116120
*/
117121
public function execute()
@@ -120,7 +124,7 @@ public function execute()
120124
try {
121125
$response = $this->transaction->getResponseObject($this->getRequest()->getPostValue());
122126
$this->responseValidator->validate($response, $this->transparent);
123-
$this->transaction->savePaymentInQuote($response);
127+
$this->transaction->savePaymentInQuote($response, (int)$this->sessionTransparent->getQuoteId());
124128
} catch (LocalizedException $exception) {
125129
$parameters['error'] = true;
126130
$parameters['error_msg'] = $exception->getMessage();

app/code/Magento/Paypal/Model/Payflow/Service/Request/SecureToken.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Paypal\Model\Payflow\Service\Request;
710

811
use Magento\Framework\Math\Random;
@@ -13,7 +16,7 @@
1316
use Magento\Quote\Model\Quote;
1417

1518
/**
16-
* Class SecureToken
19+
* Class for requesting a secure Payflow Pro token from Paypal
1720
*/
1821
class SecureToken
1922
{
@@ -42,7 +45,6 @@ public function __construct(
4245
Random $mathRandom,
4346
Transparent $transparent
4447
) {
45-
4648
$this->url = $url;
4749
$this->mathRandom = $mathRandom;
4850
$this->transparent = $transparent;
@@ -52,11 +54,12 @@ public function __construct(
5254
* Get the Secure Token from Paypal for TR
5355
*
5456
* @param Quote $quote
57+
* @param string[] $urls
5558
*
5659
* @return DataObject
5760
* @throws \Exception
5861
*/
59-
public function requestToken(Quote $quote)
62+
public function requestToken(Quote $quote, array $urls = [])
6063
{
6164
$this->transparent->setStore($quote->getStoreId());
6265
$request = $this->transparent->buildBasicRequest();
@@ -67,9 +70,9 @@ public function requestToken(Quote $quote)
6770
$request->setCurrency($quote->getBaseCurrencyCode());
6871
$request->setCreatesecuretoken('Y');
6972
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
70-
$request->setReturnurl($this->url->getUrl('paypal/transparent/response'));
71-
$request->setErrorurl($this->url->getUrl('paypal/transparent/response'));
72-
$request->setCancelurl($this->url->getUrl('paypal/transparent/response'));
73+
$request->setReturnurl($urls['return_url'] ?? $this->url->getUrl('paypal/transparent/response'));
74+
$request->setErrorurl($urls['error_url'] ?? $this->url->getUrl('paypal/transparent/response'));
75+
$request->setCancelurl($urls['cancel_url'] ?? $this->url->getUrl('paypal/transparent/response'));
7376
$request->setDisablereceipt('TRUE');
7477
$request->setSilenttran('TRUE');
7578

app/code/Magento/Paypal/Model/Payflow/Service/Response/Transaction.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\Intl\DateTimeFactory;
1212
use Magento\Payment\Model\Method\Logger;
1313
use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface;
14-
use Magento\Framework\Session\Generic;
1514
use Magento\Paypal\Model\Payflowpro;
1615
use Magento\Quote\Api\CartRepositoryInterface;
1716
use Magento\Paypal\Model\Payflow\Transparent;
@@ -25,11 +24,6 @@
2524
*/
2625
class Transaction
2726
{
28-
/**
29-
* @var Generic
30-
*/
31-
protected $sessionTransparent;
32-
3327
/**
3428
* @var CartRepositoryInterface
3529
*/
@@ -61,7 +55,6 @@ class Transaction
6155
private $dateTimeFactory;
6256

6357
/**
64-
* @param Generic $sessionTransparent
6558
* @param CartRepositoryInterface $quoteRepository
6659
* @param Transparent $transparent
6760
* @param PaymentMethodManagementInterface $paymentManagement
@@ -70,15 +63,13 @@ class Transaction
7063
* @param DateTimeFactory $dateTimeFactory
7164
*/
7265
public function __construct(
73-
Generic $sessionTransparent,
7466
CartRepositoryInterface $quoteRepository,
7567
Transparent $transparent,
7668
PaymentMethodManagementInterface $paymentManagement,
7769
HandlerInterface $errorHandler,
7870
Logger $logger,
7971
DateTimeFactory $dateTimeFactory
8072
) {
81-
$this->sessionTransparent = $sessionTransparent;
8273
$this->quoteRepository = $quoteRepository;
8374
$this->transparent = $transparent;
8475
$this->paymentManagement = $paymentManagement;
@@ -111,13 +102,13 @@ public function getResponseObject($gatewayTransactionResponse)
111102
* Saves payment information in quote.
112103
*
113104
* @param DataObject $response
105+
* @param int $cartId
114106
* @return void
115107
* @throws \InvalidArgumentException
116108
*/
117-
public function savePaymentInQuote($response)
109+
public function savePaymentInQuote($response, $cartId)
118110
{
119-
$quote = $this->quoteRepository->get($this->sessionTransparent->getQuoteId());
120-
111+
$quote = $this->quoteRepository->get($cartId);
121112
$payment = $this->paymentManagement->get($quote->getId());
122113
if (!$payment instanceof Payment) {
123114
throw new \InvalidArgumentException("Variable must contain instance of \\Quote\\Payment.");

app/code/Magento/Paypal/Model/Payflowlink.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ protected function _buildTokenRequest(\Magento\Sales\Model\Order\Payment $paymen
425425
$request->setCreatesecuretoken('Y')
426426
->setSecuretokenid($this->mathRandom->getUniqueHash())
427427
->setTrxtype($this->_getTrxTokenType());
428+
$request = $this->updateRequestReturnUrls($request, $payment);
428429

429430
$order = $payment->getOrder();
430431
$request->setAmt(sprintf('%.2F', $order->getBaseTotalDue()))
@@ -440,8 +441,7 @@ protected function _buildTokenRequest(\Magento\Sales\Model\Order\Payment $paymen
440441
}
441442

442443
/**
443-
* Get store id from response if exists
444-
* or default
444+
* Get store id from response if exists or default
445445
*
446446
* @return int
447447
*/
@@ -464,7 +464,6 @@ public function buildBasicRequest()
464464
/** @var \Magento\Paypal\Model\Payflow\Request $request */
465465
$request = $this->_requestFactory->create();
466466
$cscEditable = $this->getConfigData('csc_editable');
467-
468467
$data = parent::buildBasicRequest();
469468

470469
$request->setData($data->getData());
@@ -514,6 +513,7 @@ protected function _getTrxTokenType()
514513

515514
/**
516515
* If response is failed throw exception
516+
*
517517
* Set token data in payment object
518518
*
519519
* @param \Magento\Framework\DataObject $response
@@ -558,6 +558,7 @@ protected function _getSecureSilentPostHash($payment)
558558
*/
559559
protected function _generateSecureSilentPostHash($payment)
560560
{
561+
//phpcs:ignore Magento2.Security.InsecureFunction
561562
$secureHash = md5($this->mathRandom->getRandomString(10));
562563
$payment->setAdditionalInformation($this->_secureSilentPostHashKey, $secureHash);
563564
return $secureHash;
@@ -600,4 +601,30 @@ protected function _getCallbackUrl($actionName)
600601

601602
return $websiteUrl . 'paypal/' . $this->_callbackController . '/' . $actionName;
602603
}
604+
605+
/**
606+
* Update the redirect urls on the request if they are set on the payment
607+
*
608+
* @param \Magento\Paypal\Model\Payflow\Request $request
609+
* @param \Magento\Sales\Model\Order\Payment $payment
610+
* @return \Magento\Paypal\Model\Payflow\Request
611+
*/
612+
private function updateRequestReturnUrls(
613+
\Magento\Paypal\Model\Payflow\Request $request,
614+
\Magento\Sales\Model\Order\Payment $payment
615+
): \Magento\Paypal\Model\Payflow\Request {
616+
$paymentData = $payment->getAdditionalInformation();
617+
618+
if (!empty($paymentData['cancel_url'])) {
619+
$request->setCancelurl($paymentData['cancel_url']);
620+
}
621+
if (!empty($paymentData['return_url'])) {
622+
$request->setReturnurl($paymentData['return_url']);
623+
}
624+
if (!empty($paymentData['error_url'])) {
625+
$request->setErrorurl($paymentData['error_url']);
626+
}
627+
628+
return $request;
629+
}
603630
}

app/code/Magento/Paypal/Test/Unit/Model/Payflow/Service/Response/TransactionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function testGetResponseObject($gatewayTransactionResponse)
4949
*/
5050
public function testSavePaymentInQuote()
5151
{
52+
$cartId = 12;
5253
/** @var Transaction $transactionService */
5354
$transactionService = (new ObjectManager($this))->getObject(
5455
Transaction::class,
@@ -57,7 +58,7 @@ public function testSavePaymentInQuote()
5758
]
5859
);
5960

60-
$transactionService->savePaymentInQuote(new DataObject);
61+
$transactionService->savePaymentInQuote(new DataObject, $cartId);
6162
}
6263

6364
/**

0 commit comments

Comments
 (0)