Skip to content

Commit 1baeb21

Browse files
committed
Added integration tests
1 parent 6b3da47 commit 1baeb21

File tree

2 files changed

+249
-1
lines changed

2 files changed

+249
-1
lines changed

dev/tests/integration/testsuite/Magento/PaypalGraphQl/Model/Resolver/Customer/PlaceOrderWithPayflowProTest.php

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

0 commit comments

Comments
 (0)