Skip to content

Commit 9433a6c

Browse files
committed
MC-17118: PayPal :: Payflow link support
1 parent e955925 commit 9433a6c

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

app/code/Magento/PaypalGraphQl/Model/PayflowLinkAdditionalDataProvider.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\PaypalGraphQl\Model;
99

10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
11+
use Magento\Framework\Url\Validator as UrlValidator;
1012
use Magento\Paypal\Model\Config;
1113
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderInterface;
1214

@@ -15,14 +17,51 @@
1517
*/
1618
class PayflowLinkAdditionalDataProvider implements AdditionalDataProviderInterface
1719
{
20+
/**
21+
* @var UrlValidator
22+
*/
23+
private $urlValidator;
24+
25+
/**
26+
* @param UrlValidator $urlValidator
27+
*/
28+
public function __construct(UrlValidator $urlValidator)
29+
{
30+
$this->urlValidator = $urlValidator;
31+
}
32+
1833
/**
1934
* Returns additional data
2035
*
2136
* @param array $data
2237
* @return array
38+
* @throws GraphQlInputException
2339
*/
2440
public function getData(array $data): array
2541
{
26-
return $data[Config::METHOD_PAYFLOWLINK] ?? [];
42+
$additionalData = $data[Config::METHOD_PAYFLOWLINK] ?? [];
43+
$this->validateUrls($additionalData);
44+
45+
return $additionalData;
46+
}
47+
48+
/**
49+
* Validate redirect urls
50+
*
51+
* @param array $data
52+
* @throws GraphQlInputException
53+
*/
54+
private function validateUrls(array $data): void
55+
{
56+
$urlKeys = ['cancel_url', 'return_url', 'error_url'];
57+
58+
foreach ($urlKeys as $urlKey) {
59+
if (isset($data[$urlKey])) {
60+
if (!$this->urlValidator->isValid($data[$urlKey])) {
61+
$errorMessage = $this->urlValidator->getMessages()['invalidUrl'] ?? "Invalid Url.";
62+
throw new GraphQlInputException(__($errorMessage));
63+
}
64+
}
65+
}
2766
}
2867
}

0 commit comments

Comments
 (0)