Skip to content

Commit 10fb079

Browse files
committed
MC-17409: Add integration tests for Payflow Pro support
- added place order end to end test for the paypalflow pro support
1 parent ae94b9d commit 10fb079

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
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\PaypalGraphQl\Model\Resolver\Customer;
9+
10+
use Magento\Framework\App\Request\Http;
11+
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\Framework\UrlInterface;
16+
use Magento\Framework\DataObject;
17+
use Magento\Framework\Webapi\Request;
18+
19+
/**
20+
* Test ExpressSetPaymentMethodTest graphql endpoint for customer
21+
*
22+
* @magentoAppArea graphql
23+
*/
24+
class PlaceOrderWithPayflowProTest extends PaypalPayflowProAbstractTest
25+
{
26+
/**
27+
* @var Http
28+
*/
29+
private $request;
30+
31+
/**
32+
* @var SerializerInterface
33+
*/
34+
private $json;
35+
36+
/**
37+
* @var QuoteIdToMaskedQuoteId
38+
*/
39+
private $quoteIdToMaskedId;
40+
41+
protected function setUp()
42+
{
43+
parent::setUp();
44+
45+
$this->request = $this->objectManager->create(Http::class);
46+
$this->json = $this->objectManager->get(SerializerInterface::class);
47+
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
48+
49+
$this->objectManager = Bootstrap::getObjectManager();
50+
$this->graphqlController = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
51+
$this->request = $this->objectManager->create(Http::class);
52+
}
53+
54+
/**
55+
* Test end to end test to process a paypal payflow pro order
56+
*
57+
* @return void
58+
* @magentoDataFixture Magento/Customer/_files/customer.php
59+
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
60+
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
61+
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
62+
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
63+
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
64+
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
65+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
66+
*/
67+
public function testResolveCustomer(): void
68+
{
69+
$paymentMethod = 'payflowpro';
70+
$this->enablePaymentMethod($paymentMethod);
71+
$reservedQuoteId = 'test_quote';
72+
73+
$payload = 'BILLTOCITY=CityM&AMT=0.00&BILLTOSTREET=Green+str,+67&VISACARDLEVEL=12&SHIPTOCITY=CityM'
74+
. '&NAMETOSHIP=John+Smith&ZIP=75477&BILLTOLASTNAME=Smith&BILLTOFIRSTNAME=John'
75+
. '&RESPMSG=Verified&PROCCVV2=M&STATETOSHIP=AL&NAME=John+Smith&BILLTOZIP=75477&CVV2MATCH=Y'
76+
. '&PNREF=B70CCC236815&ZIPTOSHIP=75477&SHIPTOCOUNTRY=US&SHIPTOSTREET=Green+str,+67&CITY=CityM'
77+
. '&HOSTCODE=A&LASTNAME=Smith&STATE=AL&SECURETOKEN=MYSECURETOKEN&CITYTOSHIP=CityM&COUNTRYTOSHIP=US'
78+
. '&AVSDATA=YNY&ACCT=1111&AUTHCODE=111PNI&FIRSTNAME=John&RESULT=0&IAVS=N&POSTFPSMSG=No+Rules+Triggered&'
79+
. 'BILLTOSTATE=AL&BILLTOCOUNTRY=US&EXPDATE=0222&CARDTYPE=0&PREFPSMSG=No+Rules+Triggered&SHIPTOZIP=75477&'
80+
. 'PROCAVS=A&COUNTRY=US&AVSZIP=N&ADDRESS=Green+str,+67&BILLTONAME=John+Smith&'
81+
. 'ADDRESSTOSHIP=Green+str,+67&'
82+
. 'AVSADDR=Y&SECURETOKENID=MYSECURETOKENID&SHIPTOSTATE=AL&TRANSTIME=2019-06-24+07%3A53%3A10';
83+
84+
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
85+
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
86+
87+
$url = $this->objectManager->get(UrlInterface::class);
88+
$baseUrl = $url->getBaseUrl();
89+
90+
$query = <<<QUERY
91+
mutation {
92+
setPaymentMethodOnCart(input: {
93+
payment_method: {
94+
code: "{$paymentMethod}",
95+
additional_data: {
96+
payflowpro: {
97+
cc_details: {
98+
cc_exp_month: 12,
99+
cc_exp_year: 2030,
100+
cc_last_4: 1111,
101+
cc_type: "IV",
102+
}
103+
}
104+
}
105+
},
106+
cart_id: "{$cartId}"})
107+
{
108+
cart {
109+
selected_payment_method {
110+
code
111+
}
112+
}
113+
}
114+
createPayflowProToken(
115+
input: {
116+
cart_id:"{$cartId}",
117+
urls: {
118+
cancel_url: "{$baseUrl}paypal/transparent/cancel/"
119+
error_url: "{$baseUrl}paypal/transparent/error/"
120+
return_url: "{$baseUrl}paypal/transparent/response/"
121+
}
122+
}
123+
) {
124+
response_message
125+
result
126+
result_code
127+
secure_token
128+
secure_token_id
129+
}
130+
handlePayflowProResponse(input: {
131+
paypal_payload: "$payload",
132+
cart_id: "{$cartId}"
133+
})
134+
{
135+
cart {
136+
selected_payment_method {
137+
code
138+
}
139+
}
140+
}
141+
placeOrder(input: {cart_id: "{$cartId}"}) {
142+
order {
143+
order_id
144+
}
145+
}
146+
}
147+
QUERY;
148+
149+
$postData = $this->json->serialize(['query' => $query]);
150+
$this->request->setPathInfo('/graphql');
151+
$this->request->setMethod('POST');
152+
$this->request->setContent($postData);
153+
154+
/** @var \Magento\Integration\Model\Oauth\Token $tokenModel */
155+
$tokenModel = $this->objectManager->create(\Magento\Integration\Model\Oauth\Token::class);
156+
$customerToken = $tokenModel->createCustomerToken(1)->getToken();
157+
158+
$webApiRequest = $this->objectManager->get(Request::class);
159+
$webApiRequest->getHeaders()
160+
->addHeaderLine('Content-Type', 'application/json')
161+
->addHeaderLine('Accept', 'application/json')
162+
->addHeaderLine('Authorization', 'Bearer ' . $customerToken);
163+
$this->request->setHeaders($webApiRequest->getHeaders());
164+
165+
$paypalResponse = new DataObject(
166+
[
167+
'result' => '0',
168+
'securetoken' => 'mysecuretoken',
169+
'securetokenid' => 'mysecuretokenid',
170+
'respmsg' => 'Approved',
171+
'result_code' => '0',
172+
]
173+
);
174+
175+
$this->gatewayMock
176+
->expects($this->at(0))
177+
->method('postRequest')
178+
->willReturn($paypalResponse);
179+
180+
$this->gatewayMock
181+
->expects($this->at(1))
182+
->method('postRequest')
183+
->willReturn(
184+
new DataObject(
185+
[
186+
'result' => '0',
187+
'pnref' => 'A70AAC2378BA',
188+
'respmsg' => 'Approved',
189+
'authcode' => '647PNI',
190+
'avsaddr' => 'Y',
191+
'avszip' => 'N',
192+
'hostcode' => 'A',
193+
'procavs' => 'A',
194+
'visacardlevel' => '12',
195+
'transtime' => '2019-06-24 10:12:03',
196+
'firstname' => 'Cristian',
197+
'lastname' => 'Partica',
198+
'amt' => '14.99',
199+
'acct' => '1111',
200+
'expdate' => '0221',
201+
'cardtype' => '0',
202+
'iavs' => 'N',
203+
'result_code' => '0',
204+
]
205+
)
206+
);
207+
208+
$response = $this->graphqlController->dispatch($this->request);
209+
$responseData = $this->json->unserialize($response->getContent());
210+
211+
$this->assertArrayHasKey('data', $responseData);
212+
$this->assertArrayHasKey('createPayflowProToken', $responseData['data']);
213+
$createTokenData = $responseData['data']['createPayflowProToken'];
214+
$this->assertArrayNotHasKey('errors', $responseData);
215+
$this->assertEquals($paypalResponse->getData('securetoken'), $createTokenData['secure_token']);
216+
$this->assertEquals($paypalResponse->getData('securetokenid'), $createTokenData['secure_token_id']);
217+
218+
$this->assertTrue(
219+
isset($responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code'])
220+
);
221+
$this->assertEquals(
222+
$paymentMethod,
223+
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
224+
);
225+
226+
$this->assertTrue(
227+
isset($responseData['data']['handlePayflowProResponse']['cart']['selected_payment_method']['code'])
228+
);
229+
$this->assertEquals(
230+
$paymentMethod,
231+
$responseData['data']['handlePayflowProResponse']['cart']['selected_payment_method']['code']
232+
);
233+
234+
$this->assertTrue(
235+
isset($responseData['data']['placeOrder']['order']['order_id'])
236+
);
237+
$this->assertEquals(
238+
'test_quote',
239+
$responseData['data']['placeOrder']['order']['order_id']
240+
);
241+
}
242+
}

0 commit comments

Comments
 (0)