Skip to content

Commit d01abec

Browse files
committed
Merge remote-tracking branch 'origin/MC-17118-payflow-link' into payflow-graphql-pr
2 parents bb2d325 + 70e8de8 commit d01abec

File tree

8 files changed

+330
-293
lines changed

8 files changed

+330
-293
lines changed

app/code/Magento/PaypalGraphQl/Model/Resolver/PayflowLinkToken.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public function resolve(
8787
return [
8888
'mode' => $this->getPaymentMode($payment),
8989
'paypal_url' => $this->getPayflowLinkUrl($payment),
90-
'secret_token' => $paymentAdditionalInformation['secure_token'],
91-
'secret_token_id' => $paymentAdditionalInformation['secure_token_id'],
90+
'secure_token' => $paymentAdditionalInformation['secure_token'],
91+
'secure_token_id' => $paymentAdditionalInformation['secure_token_id'],
9292
];
9393
}
9494

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ type PaypalExpressToken @doc(description: "Contains the token returned by PayPal
2525
}
2626

2727
type PayflowLinkToken {
28-
secret_token: String @doc(description:"Secret token generated by PayPal")
29-
secret_token_id: String @doc(description:"Secret token ID generated by PayPal")
28+
secure_token: String @doc(description:"Secure token generated by PayPal")
29+
secure_token_id: String @doc(description:"Secure token ID generated by PayPal")
3030
mode: PayflowLinkMode @doc(description:"Mode for Payflow transaction")
3131
paypal_url: String @doc(description:"PayPal URL used for requesting Payflow form")
3232
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Service;
9+
10+
use Magento\Framework\App\Request\Http;
11+
use Magento\Framework\Serialize\SerializerInterface;
12+
use Magento\GraphQl\Controller\GraphQl;
13+
use Magento\Framework\App\Response\Http as HttpResponse;
14+
use Magento\TestFramework\ObjectManager;
15+
use Magento\Framework\Webapi\Request;
16+
17+
/**
18+
* Service class to simplify GraphQl requests for integration tests
19+
*/
20+
class GraphQlRequest
21+
{
22+
/**
23+
* @var string
24+
*/
25+
private $controllerPath = '/graphql';
26+
27+
/**
28+
* @var Http
29+
*/
30+
private $httpRequest;
31+
32+
/**
33+
* @var array
34+
*/
35+
private $defaultHeaders = ['Content-Type' => 'application/json'];
36+
37+
/**
38+
* @var SerializerInterface
39+
*/
40+
private $json;
41+
42+
/**
43+
* @var GraphQl
44+
*/
45+
private $controller;
46+
47+
/**
48+
* @param Http $httpRequest
49+
* @param SerializerInterface $json
50+
* @param GraphQl $controller
51+
*/
52+
public function __construct(
53+
Http $httpRequest,
54+
SerializerInterface $json,
55+
GraphQl $controller
56+
) {
57+
$this->httpRequest = $httpRequest;
58+
$this->json = $json;
59+
$this->controller = $controller;
60+
}
61+
62+
/**
63+
* Send request and return response
64+
*
65+
* @param string $query
66+
* @param array $variables
67+
* @param string $operation
68+
* @param array $headers
69+
* @return HttpResponse
70+
*/
71+
public function send(
72+
string $query,
73+
array $variables = [],
74+
string $operation = '',
75+
array $headers = []
76+
) {
77+
$this->httpRequest->setPathInfo($this->controllerPath);
78+
$this->setQuery($query, $variables, $operation)
79+
->setHeaders($headers);
80+
81+
/** @var HttpResponse $response */
82+
$response = $this->controller->dispatch($this->httpRequest);
83+
return $response;
84+
}
85+
86+
/**
87+
* Set query data on request
88+
*
89+
* @param string $query
90+
* @param array $variables
91+
* @param string $operation
92+
* @return GraphQlRequest
93+
*/
94+
private function setQuery(string $query, array $variables = [], string $operation = ''): self
95+
{
96+
if (strpos(trim($query), 'mutation') === 0) {
97+
$this->httpRequest->setMethod('POST');
98+
$this->setPostContent($query, $variables, $operation);
99+
} else {
100+
$this->httpRequest->setMethod('GET');
101+
$this->setGetContent($query, $variables, $operation);
102+
}
103+
104+
return $this;
105+
}
106+
107+
/**
108+
* Set headers on request
109+
*
110+
* @param array $headers
111+
* @return GraphQlRequest
112+
*/
113+
private function setHeaders(array $headers): self
114+
{
115+
$allHeaders = array_merge($this->defaultHeaders, $headers);
116+
117+
$webApiRequest = ObjectManager::getInstance()->get(Request::class);
118+
$requestHeaders = $webApiRequest->getHeaders();
119+
foreach ($allHeaders as $key => $value) {
120+
$requestHeaders->addHeaderLine($key, $value);
121+
}
122+
123+
$this->httpRequest->setHeaders($webApiRequest->getHeaders());
124+
125+
return $this;
126+
}
127+
128+
/**
129+
* Set POST body for request
130+
*
131+
* @param string $query
132+
* @param array $variables
133+
* @param string $operation
134+
* @return GraphQlRequest
135+
*/
136+
private function setPostContent(string $query, array $variables = [], string $operation = ''): self
137+
{
138+
$content = [
139+
'query' => $query,
140+
'variables' => !empty($variables) ? $this->json->serialize($variables) : null,
141+
'operationName' => !empty($operation) ? $operation : null
142+
];
143+
$this->httpRequest->setContent($this->json->serialize($content));
144+
145+
return $this;
146+
}
147+
148+
/**
149+
* Set GET parameters for request
150+
*
151+
* @param string $query
152+
* @param array $variables
153+
* @param string $operation
154+
* @return GraphQlRequest
155+
*/
156+
private function setGetContent(string $query, array $variables = [], string $operation = ''): self
157+
{
158+
$this->httpRequest->setQueryValue('query', $query);
159+
160+
if (!empty($variables)) {
161+
$this->httpRequest->setQueryValue('variables', $variables);
162+
}
163+
if (!empty($operation)) {
164+
$this->httpRequest->setQueryValue('operationName', $operation);
165+
}
166+
167+
return $this;
168+
}
169+
}

dev/tests/integration/testsuite/Magento/Paypal/_files/order_payflow_link_with_payment_rollback.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
*/
66

77
use Magento\TestFramework\Helper\Bootstrap;
8+
use Magento\Sales\Model\ResourceModel\Order\Collection;
9+
use Magento\Framework\Registry;
10+
11+
$objectManager = Bootstrap::getObjectManager();
812

913
/** @var \Magento\Framework\Registry $registry */
10-
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
14+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
1115
$registry->unregister('isSecureArea');
1216
$registry->register('isSecureArea', true);
1317

1418
/** @var $order \Magento\Sales\Model\Order */
15-
$orderCollection = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\ResourceModel\Order\Collection::class);
19+
$orderCollection = $objectManager->create(Collection::class);
1620
foreach ($orderCollection as $order) {
1721
$order->delete();
1822
}

0 commit comments

Comments
 (0)