ltsecurityinc安防产品在线商城代码
This commit is contained in:
+72
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test getHostedProUrl graphql endpoint for Paypal Hosted Pro payment method
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class GetHostedProSecureUrlTest extends TestCase
|
||||
{
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->json = $objectManager->get(SerializerInterface::class);
|
||||
$this->graphQlRequest = $objectManager->create(GraphQlRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get hostedpro secure URL
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/hosted_pro/active 1
|
||||
* @magentoConfigFixture default_store payment/hosted_pro/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_order_hostedpro.php
|
||||
* @return void
|
||||
*/
|
||||
public function testResolveHostedProUrl(): void
|
||||
{
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedQuoteId);
|
||||
|
||||
$payflowLinkTokenQuery
|
||||
= <<<QUERY
|
||||
{
|
||||
getHostedProUrl(input: {cart_id:"$cartId"})
|
||||
{
|
||||
secure_form_url
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlRequest->send($payflowLinkTokenQuery);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertNotEmpty($responseData['data']['getHostedProUrl']);
|
||||
$expectedSecureUrl = 'https://hostedpro.paypal.com';
|
||||
$actualSecureUrl = $responseData['data']['getHostedProUrl']['secure_form_url'];
|
||||
$this->assertEquals($expectedSecureUrl, $actualSecureUrl);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test getPayflowLinkToken graphql endpoint for non-registered customer
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class GetPayflowLinkTokenTest extends TestCase
|
||||
{
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var ObjectManager */
|
||||
private $objectManager;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->graphQlRequest = $this->objectManager->create(GraphQlRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get payflowLink secure token
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_link/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_link/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_payflow_link_with_payment.php
|
||||
* @return void
|
||||
*/
|
||||
public function testResolvePayflowLinkToken() : void
|
||||
{
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute($reservedQuoteId);
|
||||
|
||||
$payflowLinkTokenQuery
|
||||
= <<<QUERY
|
||||
{
|
||||
getPayflowLinkToken(input: {cart_id:"$cartId"})
|
||||
{
|
||||
secure_token
|
||||
secure_token_id
|
||||
mode
|
||||
paypal_url
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlRequest->send($payflowLinkTokenQuery);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
|
||||
$payflowLinkTokenResponse = $responseData['data']['getPayflowLinkToken'];
|
||||
$this->assertArrayHasKey('secure_token', $payflowLinkTokenResponse);
|
||||
$this->assertArrayHasKey('secure_token_id', $payflowLinkTokenResponse);
|
||||
$this->assertEquals('TEST', $payflowLinkTokenResponse['mode']);
|
||||
$this->assertEquals('https://pilot-payflowlink.paypal.com', $payflowLinkTokenResponse['paypal_url']);
|
||||
}
|
||||
}
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\PaypalGraphQl\PaypalExpressAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
|
||||
/**
|
||||
* Test ExpressSetPaymentMethodTest graphql endpoint for guest
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PaypalExpressSetPaymentMethodTest extends PaypalExpressAbstractTest
|
||||
{
|
||||
/**
|
||||
* @var SerializerInterface
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteId
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test end to end test to process a paypal express order
|
||||
*
|
||||
* @param string $paymentMethod
|
||||
* @return void
|
||||
* @dataProvider getPaypalCodesProvider
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testResolveGuest(string $paymentMethod): void
|
||||
{
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
if ($paymentMethod === 'payflow_express') {
|
||||
$this->enablePaymentMethod('payflow_link');
|
||||
}
|
||||
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$payerId = 'PAYER123456';
|
||||
$token = 'EC-TOKEN1234';
|
||||
$correlationId = 'c123456789';
|
||||
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createPaypalExpressToken(input: {
|
||||
cart_id: "{$cartId}",
|
||||
code: "{$paymentMethod}",
|
||||
urls: {
|
||||
return_url: "paypal/express/return/",
|
||||
cancel_url: "paypal/express/cancel/"
|
||||
success_url: "checkout/onepage/success/",
|
||||
pending_url: "checkout/onepage/pending/"
|
||||
}
|
||||
express_button: false
|
||||
})
|
||||
{
|
||||
__typename
|
||||
token
|
||||
paypal_urls{
|
||||
start
|
||||
edit
|
||||
}
|
||||
}
|
||||
setPaymentMethodOnCart(input: {
|
||||
payment_method: {
|
||||
code: "{$paymentMethod}",
|
||||
paypal_express: {
|
||||
payer_id: "$payerId",
|
||||
token: "$token"
|
||||
}
|
||||
payflow_express: {
|
||||
payer_id: "$payerId",
|
||||
token: "$token"
|
||||
}
|
||||
},
|
||||
cart_id: "{$cartId}"})
|
||||
{
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "{$cartId}"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$paypalRequest = include __DIR__ . '/../../../_files/guest_paypal_create_token_request.php';
|
||||
$paypalResponse = [
|
||||
'TOKEN' => $token,
|
||||
'CORRELATIONID' => $correlationId,
|
||||
'ACK' => 'Success'
|
||||
];
|
||||
|
||||
if ($paymentMethod == 'payflow_express') {
|
||||
$paypalRequest['SOLUTIONTYPE'] = null;
|
||||
}
|
||||
|
||||
$paypalRequest['AMT'] = '30.00';
|
||||
$paypalRequest['SHIPPINGAMT'] = '10.00';
|
||||
|
||||
$paypalRequestDetails = [
|
||||
'TOKEN' => $token,
|
||||
];
|
||||
|
||||
$paypalRequestDetailsResponse = include __DIR__ . '/../../../_files/paypal_set_payer_id_repsonse.php';
|
||||
$paypalRequestPlaceOrder = include __DIR__ . '/../../../_files/paypal_place_order_request.php';
|
||||
|
||||
$this->nvpMock
|
||||
->method('call')
|
||||
->withConsecutive(
|
||||
[Nvp::SET_EXPRESS_CHECKOUT, $paypalRequest],
|
||||
[Nvp::GET_EXPRESS_CHECKOUT_DETAILS, $paypalRequestDetails],
|
||||
[Nvp::DO_EXPRESS_CHECKOUT_PAYMENT, $paypalRequestPlaceOrder]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$paypalResponse,
|
||||
$paypalRequestDetailsResponse,
|
||||
[
|
||||
'RESULT' => '0',
|
||||
'PNREF' => 'B7PPAC033FF2',
|
||||
'RESPMSG' => 'Approved',
|
||||
'AVSADDR' => 'Y',
|
||||
'AVSZIP' => 'Y',
|
||||
'TOKEN' => $token,
|
||||
'PAYERID' => $payerId,
|
||||
'PPREF' => '7RK43642T8939154L',
|
||||
'CORRELATIONID' => $correlationId,
|
||||
'PAYMENTTYPE' => 'instant',
|
||||
'PENDINGREASON' => 'authorization'
|
||||
]
|
||||
);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertArrayHasKey('createPaypalExpressToken', $responseData['data']);
|
||||
$createTokenData = $responseData['data']['createPaypalExpressToken'];
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertEquals($paypalResponse['TOKEN'], $createTokenData['token']);
|
||||
$this->assertArrayHasKey('paypal_urls', $createTokenData);
|
||||
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
$paymentMethod,
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['placeOrder']['order']['order_number'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test_quote',
|
||||
$responseData['data']['placeOrder']['order']['order_number']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paypal method codes provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaypalCodesProvider(): array
|
||||
{
|
||||
return [
|
||||
['paypal_express'],
|
||||
['payflow_express'],
|
||||
];
|
||||
}
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\PaypalGraphQl\PaypalExpressAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
|
||||
/**
|
||||
* Test create PaypalExpressToken graphql endpoint for guest
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PaypalExpressTokenTest extends PaypalExpressAbstractTest
|
||||
{
|
||||
/**
|
||||
* @var SerializerInterface
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteId
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create paypal token for guest
|
||||
*
|
||||
* @param string $paymentMethod
|
||||
* @return void
|
||||
* @dataProvider getPaypalCodesProvider
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testResolve($paymentMethod): void
|
||||
{
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
if ($paymentMethod === 'payflow_express') {
|
||||
$this->enablePaymentMethod('payflow_link');
|
||||
}
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
$query = $this->getCreateTokenMutation($cartId, $paymentMethod);
|
||||
|
||||
$paypalRequest = include __DIR__ . '/../../../_files/guest_paypal_create_token_request.php';
|
||||
if ($paymentMethod == 'payflow_express') {
|
||||
$paypalRequest['SOLUTIONTYPE'] = null;
|
||||
}
|
||||
$paypalResponse = [
|
||||
'TOKEN' => 'EC-TOKEN1234',
|
||||
'CORRELATIONID' => 'c123456789',
|
||||
'ACK' => 'Success'
|
||||
];
|
||||
|
||||
$this->nvpMock
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with(Nvp::SET_EXPRESS_CHECKOUT, $paypalRequest)
|
||||
->willReturn($paypalResponse);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$createTokenData = $responseData['data']['createPaypalExpressToken'];
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertEquals($paypalResponse['TOKEN'], $createTokenData['token']);
|
||||
$this->assertArrayHasKey('paypal_urls', $createTokenData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create paypal token for guest
|
||||
*
|
||||
* @param string $paymentMethod
|
||||
* @return void
|
||||
* @dataProvider getPaypalCodesProvider
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testResolveWithPaypalError($paymentMethod): void
|
||||
{
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
if ($paymentMethod === 'payflow_express') {
|
||||
$this->enablePaymentMethod('payflow_link');
|
||||
}
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
$query = $this->getCreateTokenMutation($cartId, $paymentMethod);
|
||||
|
||||
$paypalRequest = include __DIR__ . '/../../../_files/guest_paypal_create_token_request.php';
|
||||
if ($paymentMethod == 'payflow_express') {
|
||||
$paypalRequest['SOLUTIONTYPE'] = null;
|
||||
}
|
||||
$expectedExceptionMessage = "PayPal gateway has rejected request. Sample PayPal Error.";
|
||||
$expectedException = new LocalizedException(__($expectedExceptionMessage));
|
||||
|
||||
$this->nvpMock
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with(Nvp::SET_EXPRESS_CHECKOUT, $paypalRequest)
|
||||
->willThrowException($expectedException);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('createPaypalExpressToken', $responseData['data']);
|
||||
$this->assertEmpty($responseData['data']['createPaypalExpressToken']);
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create paypal token for Invalid Url for guest
|
||||
*
|
||||
* @param string $paymentMethod
|
||||
* @return void
|
||||
* @dataProvider getPaypalCodesProvider
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testResolveWithInvalidRedirectUrl($paymentMethod): void
|
||||
{
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
if ($paymentMethod === 'payflow_express') {
|
||||
$this->enablePaymentMethod('payflow_link');
|
||||
}
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
|
||||
$query = $this->getCreateTokenMutationWithInvalidUrl($cartId, $paymentMethod);
|
||||
$expectedExceptionMessage = "Invalid Url.";
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('createPaypalExpressToken', $responseData['data']);
|
||||
$this->assertEmpty($responseData['data']['createPaypalExpressToken']);
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paypal method codes provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaypalCodesProvider(): array
|
||||
{
|
||||
return [
|
||||
['paypal_express'],
|
||||
['payflow_express'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get GraphQl query for creating Paypal token
|
||||
*
|
||||
* @param string $cartId
|
||||
* @param string $paymentMethod
|
||||
* @return string
|
||||
*/
|
||||
protected function getCreateTokenMutationWithInvalidUrl(string $cartId, string $paymentMethod): string
|
||||
{
|
||||
return <<<QUERY
|
||||
mutation {
|
||||
createPaypalExpressToken(input: {
|
||||
cart_id: "{$cartId}",
|
||||
code: "{$paymentMethod}",
|
||||
urls: {
|
||||
return_url: "paypal/express/return/",
|
||||
cancel_url: "paypal/express/cancel/"
|
||||
success_url: "http://mage.com/checkout/onepage/success/",
|
||||
pending_url: "checkout/onepage/pending/"
|
||||
}
|
||||
})
|
||||
{
|
||||
__typename
|
||||
token
|
||||
paypal_urls{
|
||||
start
|
||||
edit
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
}
|
||||
}
|
||||
+203
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
/**
|
||||
* Test ExpressSetPaymentMethodTest graphql endpoint for guest
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PaypalPayflowProSetPaymentMethodTest extends PaypalPayflowProAbstractTest
|
||||
{
|
||||
/**
|
||||
* @var SerializerInterface
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteId
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test end to end test to process a paypal payflow pro order
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testResolveGuest(): void
|
||||
{
|
||||
$paymentMethod = 'payflowpro';
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
|
||||
$reservedQuoteId = 'test_quote';
|
||||
|
||||
$payload = 'BILLTOCITY=CityM&AMT=0.00&BILLTOSTREET=Green+str,+67&VISACARDLEVEL=12&SHIPTOCITY=CityM'
|
||||
. '&NAMETOSHIP=John+Smith&ZIP=75477&BILLTOLASTNAME=Smith&BILLTOFIRSTNAME=John'
|
||||
. '&RESPMSG=Verified&PROCCVV2=M&STATETOSHIP=AL&NAME=John+Smith&BILLTOZIP=75477&CVV2MATCH=Y'
|
||||
. '&PNREF=B70CCC236815&ZIPTOSHIP=75477&SHIPTOCOUNTRY=US&SHIPTOSTREET=Green+str,+67&CITY=CityM'
|
||||
. '&HOSTCODE=A&LASTNAME=Smith&STATE=AL&SECURETOKEN=MYSECURETOKEN&CITYTOSHIP=CityM&COUNTRYTOSHIP=US'
|
||||
. '&AVSDATA=YNY&ACCT=1111&AUTHCODE=111PNI&FIRSTNAME=John&RESULT=0&IAVS=N&POSTFPSMSG=No+Rules+Triggered&'
|
||||
. 'BILLTOSTATE=AL&BILLTOCOUNTRY=US&EXPDATE=0222&CARDTYPE=0&PREFPSMSG=No+Rules+Triggered&SHIPTOZIP=75477&'
|
||||
. 'PROCAVS=A&COUNTRY=US&AVSZIP=N&ADDRESS=Green+str,+67&BILLTONAME=John+Smith&'
|
||||
. 'ADDRESSTOSHIP=Green+str,+67&'
|
||||
. 'AVSADDR=Y&SECURETOKENID=MYSECURETOKENID&SHIPTOSTATE=AL&TRANSTIME=2019-06-24+07%3A53%3A10';
|
||||
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
payment_method: {
|
||||
code: "{$paymentMethod}",
|
||||
payflowpro: {
|
||||
cc_details: {
|
||||
cc_exp_month: 12,
|
||||
cc_exp_year: 2030,
|
||||
cc_last_4: 1111,
|
||||
cc_type: "IV",
|
||||
}
|
||||
}
|
||||
},
|
||||
cart_id: "{$cartId}"})
|
||||
{
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
createPayflowProToken(
|
||||
input: {
|
||||
cart_id:"{$cartId}",
|
||||
urls: {
|
||||
cancel_url: "paypal/transparent/cancel/"
|
||||
error_url: "paypal/transparent/error/"
|
||||
return_url: "paypal/transparent/response/"
|
||||
}
|
||||
}
|
||||
) {
|
||||
response_message
|
||||
result
|
||||
result_code
|
||||
secure_token
|
||||
secure_token_id
|
||||
}
|
||||
handlePayflowProResponse(input: {
|
||||
paypal_payload: "$payload",
|
||||
cart_id: "{$cartId}"
|
||||
})
|
||||
{
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "{$cartId}"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$paypalResponse = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'securetoken' => 'mysecuretoken',
|
||||
'securetokenid' => 'mysecuretokenid',
|
||||
'respmsg' => 'Approved',
|
||||
'result_code' => '0',
|
||||
]
|
||||
);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$paypalResponse,
|
||||
new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'pnref' => 'A70AAC2378BA',
|
||||
'respmsg' => 'Approved',
|
||||
'authcode' => '647PNI',
|
||||
'avsaddr' => 'Y',
|
||||
'avszip' => 'N',
|
||||
'hostcode' => 'A',
|
||||
'procavs' => 'A',
|
||||
'visacardlevel' => '12',
|
||||
'transtime' => '2019-06-24 10:12:03',
|
||||
'firstname' => 'Cristian',
|
||||
'lastname' => 'Partica',
|
||||
'amt' => '14.99',
|
||||
'acct' => '1111',
|
||||
'expdate' => '0221',
|
||||
'cardtype' => '0',
|
||||
'iavs' => 'N',
|
||||
'result_code' => '0'
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertArrayHasKey('createPayflowProToken', $responseData['data']);
|
||||
$createTokenData = $responseData['data']['createPayflowProToken'];
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertEquals($paypalResponse->getData('securetoken'), $createTokenData['secure_token']);
|
||||
$this->assertEquals($paypalResponse->getData('securetokenid'), $createTokenData['secure_token_id']);
|
||||
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
$paymentMethod,
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['handlePayflowProResponse']['cart']['selected_payment_method']['code'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
$paymentMethod,
|
||||
$responseData['data']['handlePayflowProResponse']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['placeOrder']['order']['order_number'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test_quote',
|
||||
$responseData['data']['placeOrder']['order']['order_number']
|
||||
);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Laminas\Http\Exception\RuntimeException;
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
|
||||
/**
|
||||
* Test PaypalPayflowProTokenExceptionTest graphql endpoint for guest
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PaypalPayflowProTokenExceptionTest extends PaypalPayflowProAbstractTest
|
||||
{
|
||||
/**
|
||||
* @var SerializerInterface
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteId
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create paypal token for guest
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testResolveWithPaypalError(): void
|
||||
{
|
||||
$this->enablePaymentMethod('payflowpro');
|
||||
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
$query = $this->getCreatePayflowTokenMutation($cartId);
|
||||
|
||||
$expectedExceptionMessage = "Payment Gateway is unreachable at the moment. Please use another payment option.";
|
||||
$expectedException = new RuntimeException($expectedExceptionMessage);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willThrowException($expectedException);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('createPayflowProToken', $responseData['data']);
|
||||
$this->assertEmpty($responseData['data']['createPayflowProToken']);
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
/**
|
||||
* Test PaypalPayflowProTokenTest graphql endpoint for guest
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PaypalPayflowProTokenTest extends PaypalPayflowProAbstractTest
|
||||
{
|
||||
/**
|
||||
* @var SerializerInterface
|
||||
*/
|
||||
private $json;
|
||||
|
||||
/**
|
||||
* @var QuoteIdToMaskedQuoteId
|
||||
*/
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create paypal token for guest
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
*/
|
||||
public function testResolve(): void
|
||||
{
|
||||
$this->enablePaymentMethod('payflowpro');
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
$query = $this->getCreatePayflowTokenMutation($cartId);
|
||||
|
||||
$paypalResponse = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'securetoken' => 'mysecuretoken',
|
||||
'securetokenid' => 'mysecuretokenid',
|
||||
'respmsg' => 'Approved',
|
||||
'result_code' => '0',
|
||||
]
|
||||
);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willReturn($paypalResponse);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertArrayHasKey('createPayflowProToken', $responseData['data']);
|
||||
$createTokenData = $responseData['data']['createPayflowProToken'];
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertEquals($paypalResponse->getData('securetoken'), $createTokenData['secure_token']);
|
||||
$this->assertEquals($paypalResponse->getData('securetokenid'), $createTokenData['secure_token_id']);
|
||||
$this->assertEquals($paypalResponse->getData('result'), $createTokenData['result']);
|
||||
$this->assertEquals($paypalResponse->getData('result_code'), $createTokenData['result_code']);
|
||||
$this->assertEquals($paypalResponse->getData('respmsg'), $createTokenData['response_message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test redirect Urls are validated
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
*/
|
||||
public function testResolveWithInvalidRedirectUrl(): void
|
||||
{
|
||||
$this->enablePaymentMethod('payflowpro');
|
||||
$reservedQuoteId = 'test_quote';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createPayflowProToken(
|
||||
input: {
|
||||
cart_id:"{$cartId}",
|
||||
urls: {
|
||||
cancel_url: "paypal/transparent/cancel/"
|
||||
error_url: "http://domain/paypal/transparent/cancel"
|
||||
return_url: "paypal/transparent/response/"
|
||||
}
|
||||
}
|
||||
) {
|
||||
response_message
|
||||
result
|
||||
result_code
|
||||
secure_token
|
||||
secure_token_id
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$expectedExceptionMessage = "Invalid Url.";
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
}
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Paypal\Model\Hostedpro;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Paypal\Model\Api\Type\Factory as ApiFactory;
|
||||
|
||||
/**
|
||||
* End to end place order test using hostedpro via graphql endpoint
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PlaceOrderWithHostedProTest extends TestCase
|
||||
{
|
||||
/** @var string */
|
||||
private $paymentMethod = Config::METHOD_HOSTEDPRO;
|
||||
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/** @var ObjectManager */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Nvp|MockObject */
|
||||
private $nvpMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->graphQlRequest = $this->objectManager->create(GraphQlRequest::class);
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
|
||||
$this->nvpMock = $this->getMockBuilder(Nvp::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['call'])
|
||||
->getMock();
|
||||
|
||||
$apiFactoryMock = $this->getMockBuilder(ApiFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
$apiFactoryMock->method('create')->willReturn($this->nvpMock);
|
||||
|
||||
$this->objectManager->addSharedInstance($apiFactoryMock, ApiFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager->removeSharedInstance(ApiFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful place order with Hosted Pro
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/hosted_pro/active 1
|
||||
* @magentoConfigFixture default_store paypal/wpp/sandbox_flag 1
|
||||
* @magentoConfigFixture default_store paypal/general/merchant_country GB
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testPlaceOrderWithHostedPro(): void
|
||||
{
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$this->paymentMethod"
|
||||
hosted_pro: {
|
||||
cancel_url:"paypal/hostedpro/customcancel"
|
||||
return_url:"paypal/hostedpro/customreturn"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "$cartId"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$apiRequestData = require __DIR__ . '/../../../_files/hosted_pro_nvp_request.php';
|
||||
$apiResponseData = require __DIR__ . '/../../../_files/hosted_pro_nvp_response.php';
|
||||
|
||||
$this->nvpMock
|
||||
->expects($this->once())
|
||||
->method('call')
|
||||
->with(Hostedpro::BM_BUTTON_METHOD, $apiRequestData)
|
||||
->willReturn($apiResponseData);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertEquals(
|
||||
$this->paymentMethod,
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['placeOrder']['order']['order_number'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test_quote',
|
||||
$responseData['data']['placeOrder']['order']['order_number']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test place order with Hosted Pro with a declined status
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/hosted_pro/active 1
|
||||
* @magentoConfigFixture default_store paypal/wpp/sandbox_flag 1
|
||||
* @magentoConfigFixture default_store paypal/general/merchant_country GB
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testOrderWithHostedProDeclined(): void
|
||||
{
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$this->paymentMethod"
|
||||
hosted_pro: {
|
||||
cancel_url:"paypal/hostedpro/customCancel"
|
||||
return_url:"paypal/hostedpro/customReturnUrl"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "$cartId"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$exceptionMessage = 'Declined response message from PayPal gateway';
|
||||
$exception = new LocalizedException(__($exceptionMessage));
|
||||
$expectedExceptionMessage = 'Unable to place order: A server error stopped your order from being placed. ' .
|
||||
'Please try to place your order again';
|
||||
|
||||
$this->nvpMock->method('call')->willThrowException($exception);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setPaymentMethodOnCart with invalid url inputs
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/hosted_pro/active 1
|
||||
* @magentoConfigFixture default_store paypal/wpp/sandbox_flag 1
|
||||
* @magentoConfigFixture default_store paypal/general/merchant_country GB
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testSetPaymentMethodInvalidUrls()
|
||||
{
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$this->paymentMethod"
|
||||
hosted_pro: {
|
||||
cancel_url:"http://mysite.com/paypal/hostedpro/customCancel"
|
||||
return_url:"http://mysite.com/paypal/hostedpro/customReturnUrl"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$expectedExceptionMessage = 'Invalid Url.';
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
}
|
||||
+279
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Laminas\Http\Exception\RuntimeException;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\Paypal\Model\Payflow\Request;
|
||||
use Magento\Paypal\Model\Payflow\RequestFactory;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Paypal\Model\Payflowlink;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* End to end place order test using payflow_link via graphql endpoint for guest
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PlaceOrderWithPayflowLinkTest extends TestCase
|
||||
{
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/** @var ObjectManager */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Gateway|MockObject */
|
||||
private $gateway;
|
||||
|
||||
/** @var Request|MockObject */
|
||||
private $payflowRequest;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->graphQlRequest = $this->objectManager->create(GraphQlRequest::class);
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->gateway = $this->getMockBuilder(Gateway::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['postRequest'])
|
||||
->getMock();
|
||||
|
||||
$requestFactory = $this->getMockBuilder(RequestFactory::class)
|
||||
->setMethods(['create'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->payflowRequest = $this->getMockBuilder(Request::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['__call','setData'])
|
||||
->getMock();
|
||||
$this->payflowRequest->method('__call')
|
||||
->willReturnCallback(
|
||||
function ($method) {
|
||||
if (strpos($method, 'set') === 0) {
|
||||
return $this->payflowRequest;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
$requestFactory->expects($this->any())->method('create')->willReturn($this->payflowRequest);
|
||||
$this->objectManager->addSharedInstance($this->gateway, Gateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager->removeSharedInstance(Gateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful place Order with Payflow link
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_link/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_link/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testResolvePlaceOrderWithPayflowLink(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_link';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$paymentMethod"
|
||||
payflow_link:
|
||||
{
|
||||
cancel_url:"paypal/payflow/cancel"
|
||||
return_url:"paypal/payflow/return"
|
||||
error_url:"paypal/payflow/error"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "$cartId"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
|
||||
$button = 'Magento_2_' . $productMetadata->getEdition();
|
||||
|
||||
$payflowLinkResponse = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'respmsg' => 'Approved',
|
||||
'pnref' => 'V19A3D27B61E',
|
||||
'result_code' => '0'
|
||||
]
|
||||
);
|
||||
$this->gateway->expects($this->once())
|
||||
->method('postRequest')
|
||||
->willReturn($payflowLinkResponse);
|
||||
|
||||
$this->payflowRequest
|
||||
->method('setData')
|
||||
->willReturnMap(
|
||||
[
|
||||
[
|
||||
'user' => null,
|
||||
'vendor' => null,
|
||||
'partner' => null,
|
||||
'pwd' => null,
|
||||
'verbosity' => null,
|
||||
'BUTTONSOURCE' => $button,
|
||||
'tender' => 'C',
|
||||
],
|
||||
$this->returnSelf()
|
||||
],
|
||||
['USER1', 1, $this->returnSelf()],
|
||||
['USER2', 'USER2SilentPostHash', $this->returnSelf()]
|
||||
);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertEquals(
|
||||
$paymentMethod,
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['placeOrder']['order']['order_number'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test_quote',
|
||||
$responseData['data']['placeOrder']['order']['order_number']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test place Order with Payflow link with a declined status
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_link/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_link/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testResolveWithPayflowLinkDeclined(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_link';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$paymentMethod"
|
||||
payflow_link:
|
||||
{
|
||||
cancel_url:"paypal/payflow/cancelPayment"
|
||||
return_url:"paypal/payflow/returnUrl"
|
||||
error_url:"paypal/payflow/returnUrl"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "$cartId"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
|
||||
$exception = new RuntimeException(__('Declined response message from PayPal gateway')->render());
|
||||
//Exception message is transformed into more controlled message
|
||||
$expectedExceptionMessage =
|
||||
"Unable to place order: Payment Gateway is unreachable at the moment. Please use another payment option.";
|
||||
|
||||
$this->payflowRequest->method('setData')
|
||||
->with(
|
||||
[
|
||||
[
|
||||
'invnum' => 'test_quote',
|
||||
'amt' => '30.00',
|
||||
'pnref' => 'TEST123PNREF',
|
||||
'USER2' => '1EncryptedSilentPostHash',
|
||||
'result' => $resultCode,
|
||||
'trxtype' => 'A',
|
||||
|
||||
]
|
||||
]
|
||||
)
|
||||
->willReturnSelf();
|
||||
|
||||
$this->gateway->method('postRequest')->willThrowException($exception);
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals(
|
||||
$expectedExceptionMessage,
|
||||
$actualError['message']
|
||||
);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
}
|
||||
+319
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Laminas\Http\Exception\RuntimeException;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\Paypal\Model\Payflow\Request;
|
||||
use Magento\Paypal\Model\Payflow\RequestFactory;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Paypal\Model\Payflowlink;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* End to end place order test using PayPal payments advanced via GraphQl
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PlaceOrderWithPaymentsAdvancedTest extends TestCase
|
||||
{
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/** @var ObjectManager */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Gateway|MockObject */
|
||||
private $gateway;
|
||||
|
||||
/** @var Request|MockObject */
|
||||
private $paymentRequest;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->graphQlRequest = $this->objectManager->create(GraphQlRequest::class);
|
||||
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->gateway = $this->getMockBuilder(Gateway::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['postRequest'])
|
||||
->getMock();
|
||||
|
||||
$requestFactory = $this->getMockBuilder(RequestFactory::class)
|
||||
->setMethods(['create'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->paymentRequest = $this->getMockBuilder(Request::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['__call','setData'])
|
||||
->getMock();
|
||||
$this->paymentRequest->method('__call')
|
||||
->willReturnCallback(
|
||||
function ($method) {
|
||||
if (strpos($method, 'set') === 0) {
|
||||
return $this->paymentRequest;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
$requestFactory->method('create')->willReturn($this->paymentRequest);
|
||||
$this->objectManager->addSharedInstance($this->gateway, Gateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager->removeSharedInstance(Gateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful place Order with Payments Advanced
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_advanced/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_advanced/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testResolvePlaceOrderWithPaymentsAdvanced(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_advanced';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$productMetadata = ObjectManager::getInstance()->get(ProductMetadataInterface::class);
|
||||
$button = 'Magento_2_' . $productMetadata->getEdition();
|
||||
|
||||
$payflowLinkResponse = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'respmsg' => 'Approved',
|
||||
'pnref' => 'V19A3D27B61E',
|
||||
'result_code' => '0'
|
||||
]
|
||||
);
|
||||
$this->gateway->expects($this->once())
|
||||
->method('postRequest')
|
||||
->willReturn($payflowLinkResponse);
|
||||
|
||||
$this->paymentRequest
|
||||
->method('setData')
|
||||
->willReturnMap(
|
||||
[
|
||||
[
|
||||
'user' => null,
|
||||
'vendor' => null,
|
||||
'partner' => null,
|
||||
'pwd' => null,
|
||||
'verbosity' => null,
|
||||
'BUTTONSOURCE' => $button,
|
||||
'tender' => 'C',
|
||||
],
|
||||
$this->returnSelf()
|
||||
],
|
||||
['USER1', 1, $this->returnSelf()],
|
||||
['USER2', 'USER2SilentPostHash', $this->returnSelf()]
|
||||
);
|
||||
|
||||
$responseData = $this->setPaymentMethodAndPlaceOrder($cartId, $paymentMethod);
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertEquals(
|
||||
$paymentMethod,
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
$this->assertNotEmpty(isset($responseData['data']['placeOrder']['order']['order_number']));
|
||||
$this->assertEquals('test_quote', $responseData['data']['placeOrder']['order']['order_number']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test place Order with Payments Advanced with Invalid Url.
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_advanced/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_advanced/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testResolvePaymentsAdvancedWithInvalidUrl(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_advanced';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$responseData = $this->setPaymentMethodWithInValidUrl($cartId, $paymentMethod);
|
||||
$expectedExceptionMessage = "Invalid Url.";
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test place Order with PaymentAdvanced with a declined status
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_advanced/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_advanced/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function testResolveWithPaymentAdvancedDeclined(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_advanced';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
|
||||
$exception = new RuntimeException(__('Declined response message from PayPal gateway')->render());
|
||||
//Exception message is transformed into more controlled message
|
||||
$expectedExceptionMessage =
|
||||
"Unable to place order: Payment Gateway is unreachable at the moment. Please use another payment option.";
|
||||
|
||||
$this->paymentRequest->method('setData')
|
||||
->with(
|
||||
[
|
||||
[
|
||||
'invnum' => 'test_quote',
|
||||
'amt' => '40.00',
|
||||
'pnref' => 'TEST123PNREF',
|
||||
'USER2' => '1EncryptedSilentPostHash',
|
||||
'result' => $resultCode,
|
||||
'trxtype' => 'A',
|
||||
|
||||
]
|
||||
]
|
||||
)
|
||||
->willReturnSelf();
|
||||
|
||||
$this->gateway->method('postRequest')->willThrowException($exception);
|
||||
|
||||
$responseData = $this->setPaymentMethodAndPlaceOrder($cartId, $paymentMethod);
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send setPaymentMethodOnCart and placeOrder mutations and return response content
|
||||
*
|
||||
* @param string $cartId
|
||||
* @param string $paymentMethod
|
||||
* @return array
|
||||
*/
|
||||
private function setPaymentMethodAndPlaceOrder(string $cartId, string $paymentMethod): array
|
||||
{
|
||||
$serializer = $this->objectManager->get(SerializerInterface::class);
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$paymentMethod"
|
||||
payflow_link: {
|
||||
cancel_url:"paypal/payflowadvanced/customcancel"
|
||||
return_url:"paypal/payflowadvanced/customreturn"
|
||||
error_url:"paypal/payflowadvanced/customerror"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "$cartId"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseContent = $serializer->unserialize($response->getContent());
|
||||
|
||||
return $responseContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send setPaymentMethodOnCart and placeOrder mutations and return response content
|
||||
*
|
||||
* @param string $cartId
|
||||
* @param string $paymentMethod
|
||||
* @return array
|
||||
*/
|
||||
private function setPaymentMethodWithInValidUrl(string $cartId, string $paymentMethod): array
|
||||
{
|
||||
$serializer = $this->objectManager->get(SerializerInterface::class);
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$paymentMethod"
|
||||
payflow_link: {
|
||||
cancel_url:"paypal/payflowadvanced/cancel"
|
||||
return_url:"http://localhost/paypal/payflowadvanced/return"
|
||||
error_url:"paypal/payflowadvanced/error"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseContent = $serializer->unserialize($response->getContent());
|
||||
|
||||
return $responseContent;
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Guest;
|
||||
|
||||
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test SetPayment method for payflow_link and validate the additional information
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class SetPaymentMethodAsPayflowLinkTest extends TestCase
|
||||
{
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/** @var ObjectManager */
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->graphQlRequest = $this->objectManager->create(GraphQlRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test SetPayment method for payflow_link and validate that the additional information is set on the quote
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_link/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_link/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testSetPayflowLinkAsPaymentMethod(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_link';
|
||||
$maskedCartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$maskedCartId"
|
||||
payment_method: {
|
||||
code: "$paymentMethod"
|
||||
payflow_link: {
|
||||
return_url:"paypal/payflow/link/success"
|
||||
cancel_url:"paypal/payflow/link/cancel"
|
||||
error_url:"paypal/payflow/link/error"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayNotHasKey('errors', $responseData);
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertEquals(
|
||||
$paymentMethod,
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
|
||||
$maskedQuoteIdToQuoteId = $this->objectManager->get(MaskedQuoteIdToQuoteIdInterface::class);
|
||||
$quoteId = $maskedQuoteIdToQuoteId->execute($maskedCartId);
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(QuoteRepository::class);
|
||||
$quote = $quoteRepository->get($quoteId);
|
||||
|
||||
$payment = $quote->getPayment();
|
||||
$this->assertEquals(
|
||||
"paypal/payflow/link/cancel",
|
||||
$payment->getAdditionalInformation('cancel_url')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"paypal/payflow/link/success",
|
||||
$payment->getAdditionalInformation('return_url')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"paypal/payflow/link/error",
|
||||
$payment->getAdditionalInformation('error_url')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid redirect url
|
||||
*
|
||||
* @magentoConfigFixture default_store payment/payflow_link/active 1
|
||||
* @magentoConfigFixture default_store payment/payflow_link/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidUrl(): void
|
||||
{
|
||||
$paymentMethod = 'payflow_link';
|
||||
$cartId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
|
||||
|
||||
$query
|
||||
= <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
cart_id: "$cartId"
|
||||
payment_method: {
|
||||
code: "$paymentMethod"
|
||||
payflow_link: {
|
||||
return_url:"http://magento.com/paypal/payflow/link/success"
|
||||
cancel_url:"paypal/payflow/link/cancel"
|
||||
error_url:"paypal/payflow/link/error"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
$response = $this->graphQlRequest->send($query);
|
||||
$responseData = $this->json->unserialize($response->getContent());
|
||||
|
||||
$this->assertArrayHasKey('errors', $responseData);
|
||||
$expectedExceptionMessage = "Invalid Url.";
|
||||
$actualError = $responseData['errors'][0];
|
||||
$this->assertEquals($expectedExceptionMessage, $actualError['message']);
|
||||
$this->assertEquals(GraphQlInputException::EXCEPTION_CATEGORY, $actualError['extensions']['category']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user