ltsecurityinc安防产品在线商城代码
This commit is contained in:
+220
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Customer;
|
||||
|
||||
use Magento\Integration\Api\CustomerTokenServiceInterface;
|
||||
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 customer
|
||||
*
|
||||
* @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
|
||||
* @magentoConfigFixture default_store paypal/wpp/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 testResolve(string $paymentMethod): void
|
||||
{
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
if ($paymentMethod === 'payflow_express') {
|
||||
$this->enablePaymentMethod('payflow_link');
|
||||
}
|
||||
|
||||
$payerId = 'PAYER123456';
|
||||
$token = 'EC-TOKEN1234';
|
||||
$correlationId = 'c123456789';
|
||||
$reservedQuoteId = 'test_quote';
|
||||
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
$cartId = $cart->getId();
|
||||
$maskedCartId = $this->quoteIdToMaskedId->execute((int) $cartId);
|
||||
|
||||
$query = <<<QUERY
|
||||
mutation {
|
||||
createPaypalExpressToken(input: {
|
||||
cart_id: "{$maskedCartId}",
|
||||
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: "{$maskedCartId}"})
|
||||
{
|
||||
cart {
|
||||
selected_payment_method {
|
||||
code
|
||||
}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "{$maskedCartId}"}) {
|
||||
order {
|
||||
order_number
|
||||
}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
|
||||
$paypalRequest = include __DIR__ . '/../../../_files/customer_paypal_create_token_request.php';
|
||||
$paypalResponse = [
|
||||
'TOKEN' => $payerId,
|
||||
'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';
|
||||
$paypalRequestPlaceOrder['EMAIL'] = 'customer@example.com';
|
||||
|
||||
$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, [], '', $requestHeaders);
|
||||
$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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Customer;
|
||||
|
||||
use Magento\Integration\Api\CustomerTokenServiceInterface;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\PaypalGraphQl\PaypalExpressAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
|
||||
/**
|
||||
* Test createPaypalExpressToken graphql endpoint for customer
|
||||
*
|
||||
* @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 customer
|
||||
*
|
||||
* @param string $paymentMethod
|
||||
* @dataProvider getPaypalCodesProvider
|
||||
* @magentoConfigFixture default_store paypal/wpp/sandbox_flag 1
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 = $cart->getId();
|
||||
$maskedCartId = $this->quoteIdToMaskedId->execute((int) $cartId);
|
||||
|
||||
$query = $this->getCreateTokenMutation($maskedCartId, $paymentMethod);
|
||||
|
||||
$paypalRequest = include __DIR__ . '/../../../_files/customer_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);
|
||||
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
|
||||
$response = $this->graphQlRequest->send($query, [], '', $requestHeaders);
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paypal method codes provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaypalCodesProvider(): array
|
||||
{
|
||||
return [
|
||||
['paypal_express'],
|
||||
['payflow_express'],
|
||||
];
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Customer;
|
||||
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Math\Random;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
|
||||
use Magento\GraphQl\Service\GraphQlRequest;
|
||||
use Magento\Integration\Api\CustomerTokenServiceInterface;
|
||||
use Magento\Integration\Model\Oauth\Token;
|
||||
use Magento\Paypal\Model\Payflow\Request;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Paypal\Model\Payflow\RequestFactory;
|
||||
|
||||
/**
|
||||
* End to end place order test using payflow_link via graphql endpoint for registered customer
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PlaceOrderWithPayflowLinkTest extends TestCase
|
||||
{
|
||||
/** @var GraphQlRequest */
|
||||
private $graphQlRequest;
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var QuoteIdToMaskedQuoteId */
|
||||
private $quoteIdToMaskedId;
|
||||
|
||||
/** @var GetMaskedQuoteIdByReservedOrderId */
|
||||
private $getMaskedQuoteIdByReservedOrderId;
|
||||
|
||||
/** @var ObjectManager */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Gateway|MockObject */
|
||||
private $gateway;
|
||||
|
||||
/** @var Random|MockObject */
|
||||
private $mathRandom;
|
||||
|
||||
/** @var Request|MockObject */
|
||||
private $payflowRequest;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->json = $this->objectManager->get(SerializerInterface::class);
|
||||
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
|
||||
$this->quoteIdToMaskedId = $this->objectManager->get(QuoteIdToMaskedQuoteId::class);
|
||||
$this->graphQlRequest = $this->objectManager->create(GraphQlRequest::class);
|
||||
|
||||
$this->mathRandom = $this->getMockBuilder(Random::class)
|
||||
->getMock();
|
||||
$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()
|
||||
->getMock();
|
||||
$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 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/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 testResolvePlaceOrderWithPayflowLinkForCustomer(): 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/errorUrl"
|
||||
}
|
||||
}
|
||||
}) {
|
||||
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()]
|
||||
);
|
||||
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
$response = $this->graphQlRequest->send($query, [], '', $requestHeaders);
|
||||
$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']
|
||||
);
|
||||
}
|
||||
}
|
||||
+364
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Customer;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterface;
|
||||
use Magento\Checkout\Api\Data\ShippingInformationInterfaceFactory;
|
||||
use Magento\Checkout\Api\ShippingInformationManagementInterface;
|
||||
use Magento\Framework\Api\DataObjectHelper;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Integration\Api\CustomerTokenServiceInterface;
|
||||
use Magento\Integration\Model\Oauth\Token;
|
||||
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
|
||||
use Magento\Quote\Api\BillingAddressManagementInterface;
|
||||
use Magento\Quote\Api\CartManagementInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterface;
|
||||
use Magento\Quote\Api\Data\AddressInterfaceFactory;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\QuoteIdMask;
|
||||
use Magento\Quote\Model\QuoteIdMaskFactory;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\Quote\Model\ShippingAddressManagementInterface;
|
||||
use Magento\Vault\Api\Data\PaymentTokenInterface;
|
||||
use Magento\Vault\Model\PaymentTokenManagement;
|
||||
use Magento\Vault\Model\PaymentTokenRepository;
|
||||
|
||||
/**
|
||||
* End to end place order test using payflowpro_cc_vault via graphql endpoint for customer
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PlaceOrderWithPayflowProCCVaultTest 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place order use payflowpro method and save cart data to future
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 testPlaceOrderWithCCVault(): void
|
||||
{
|
||||
$this->placeOrderPayflowPro('is_active_payment_token_enabler: true');
|
||||
$publicHash = $this->getVaultCartData()->getPublicHash();
|
||||
/** @var CartManagementInterface $cartManagement */
|
||||
$cartManagement = $this->objectManager->get(CartManagementInterface::class);
|
||||
/** @var CartRepositoryInterface $cartRepository */
|
||||
$cartRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var QuoteIdMaskFactory $quoteIdMaskFactory */
|
||||
$quoteIdMaskFactory = $this->objectManager->get(QuoteIdMaskFactory::class);
|
||||
$cartId = $cartManagement->createEmptyCartForCustomer(1);
|
||||
$cart = $cartRepository->get($cartId);
|
||||
$cart->setReservedOrderId('test_quote_1');
|
||||
$cartRepository->save($cart);
|
||||
/** @var QuoteIdMask $quoteIdMask */
|
||||
$quoteIdMask = $quoteIdMaskFactory->create();
|
||||
$quoteIdMask->setQuoteId($cartId)
|
||||
->save();
|
||||
|
||||
$reservedQuoteId = 'test_quote_1';
|
||||
$cart = $this->getQuoteByReservedOrderId($reservedQuoteId);
|
||||
$cartId = $this->quoteIdToMaskedId->execute((int)$cart->getId());
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = $this->objectManager->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = $this->objectManager->get(QuoteResource::class);
|
||||
$product = $productRepository->get('simple_product');
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_quote_1', 'reserved_order_id');
|
||||
$quote->addProduct($product, 2);
|
||||
$cartRepository->save($quote);
|
||||
|
||||
/** @var AddressInterfaceFactory $quoteAddressFactory */
|
||||
$quoteAddressFactory = $this->objectManager->get(AddressInterfaceFactory::class);
|
||||
/** @var DataObjectHelper $dataObjectHelper */
|
||||
$dataObjectHelper = $this->objectManager->get(DataObjectHelper::class);
|
||||
/** @var ShippingAddressManagementInterface $shippingAddressManagement */
|
||||
$shippingAddressManagement = $this->objectManager->get(ShippingAddressManagementInterface::class);
|
||||
|
||||
$quoteAddressData = [
|
||||
AddressInterface::KEY_TELEPHONE => 3468676,
|
||||
AddressInterface::KEY_POSTCODE => '75477',
|
||||
AddressInterface::KEY_COUNTRY_ID => 'US',
|
||||
AddressInterface::KEY_CITY => 'CityM',
|
||||
AddressInterface::KEY_COMPANY => 'CompanyName',
|
||||
AddressInterface::KEY_STREET => 'Green str, 67',
|
||||
AddressInterface::KEY_LASTNAME => 'Smith',
|
||||
AddressInterface::KEY_FIRSTNAME => 'John',
|
||||
AddressInterface::KEY_REGION_ID => 1,
|
||||
];
|
||||
$quoteAddress = $quoteAddressFactory->create();
|
||||
$dataObjectHelper->populateWithArray($quoteAddress, $quoteAddressData, AddressInterfaceFactory::class);
|
||||
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_quote_1', 'reserved_order_id');
|
||||
$shippingAddressManagement->assign($quote->getId(), $quoteAddress);
|
||||
|
||||
/** @var BillingAddressManagementInterface $billingAddressManagement */
|
||||
$billingAddressManagement = $this->objectManager->get(BillingAddressManagementInterface::class);
|
||||
$billingAddressManagement->assign($quote->getId(), $quoteAddress);
|
||||
|
||||
/** @var ShippingInformationInterfaceFactory $shippingInformationFactory */
|
||||
$shippingInformationFactory = $this->objectManager->get(ShippingInformationInterfaceFactory::class);
|
||||
/** @var ShippingInformationManagementInterface $shippingInformationManagement */
|
||||
$shippingInformationManagement = $this->objectManager->get(ShippingInformationManagementInterface::class);
|
||||
$quoteAddress = $quote->getShippingAddress();
|
||||
|
||||
/** @var ShippingInformationInterface $shippingInformation */
|
||||
$shippingInformation = $shippingInformationFactory->create([
|
||||
'data' => [
|
||||
ShippingInformationInterface::SHIPPING_ADDRESS => $quoteAddress,
|
||||
ShippingInformationInterface::SHIPPING_CARRIER_CODE => 'flatrate',
|
||||
ShippingInformationInterface::SHIPPING_METHOD_CODE => 'flatrate',
|
||||
],
|
||||
]);
|
||||
$shippingInformationManagement->saveAddressInformation($quote->getId(), $shippingInformation);
|
||||
|
||||
$secondQuery = <<<QUERY
|
||||
mutation {
|
||||
setPaymentMethodOnCart(input: {
|
||||
payment_method: {
|
||||
code: "payflowpro_cc_vault",
|
||||
payflowpro_cc_vault: {
|
||||
public_hash:"{$publicHash}"
|
||||
}
|
||||
},
|
||||
cart_id: "{$cartId}"})
|
||||
{
|
||||
cart {
|
||||
selected_payment_method {code}
|
||||
}
|
||||
}
|
||||
placeOrder(input: {cart_id: "{$cartId}"}) {
|
||||
order {order_number}
|
||||
}
|
||||
}
|
||||
QUERY;
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
$vaultResponse = $this->graphQlRequest->send($secondQuery, [], '', $requestHeaders);
|
||||
|
||||
$responseData = $this->json->unserialize($vaultResponse->getContent());
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
'payflowpro_cc_vault',
|
||||
$responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']
|
||||
);
|
||||
$this->assertTrue(
|
||||
isset($responseData['data']['placeOrder']['order']['order_number'])
|
||||
);
|
||||
$this->assertEquals(
|
||||
'test_quote_1',
|
||||
$responseData['data']['placeOrder']['order']['order_number']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $isActivePaymentTokenEnabler
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
private function placeOrderPayflowPro($isActivePaymentTokenEnabler)
|
||||
{
|
||||
$paymentMethod = 'payflowpro';
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
$this->enablePaymentMethod('payflowpro_cc_vault');
|
||||
$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: {
|
||||
{$isActivePaymentTokenEnabler}
|
||||
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;
|
||||
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
$paypalResponse = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'securetoken' => 'mysecuretoken',
|
||||
'securetokenid' => 'mysecuretokenid',
|
||||
'respmsg' => 'Approved',
|
||||
'result_code' => '0',
|
||||
]
|
||||
);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willReturn($paypalResponse);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willReturn(
|
||||
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, [], '', $requestHeaders);
|
||||
|
||||
return $this->json->unserialize($response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get saved cart data
|
||||
*
|
||||
* @return PaymentTokenInterface
|
||||
*/
|
||||
private function getVaultCartData()
|
||||
{
|
||||
/** @var PaymentTokenManagement $tokenManagement */
|
||||
$tokenManagement = $this->objectManager->get(PaymentTokenManagement::class);
|
||||
$token = $tokenManagement->getByGatewayToken(
|
||||
'B70CCC236815',
|
||||
'payflowpro',
|
||||
1
|
||||
);
|
||||
/** @var PaymentTokenRepository $tokenRepository */
|
||||
$tokenRepository = $this->objectManager->get(PaymentTokenRepository::class);
|
||||
return $tokenRepository->getById($token->getEntityId());
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Customer;
|
||||
|
||||
use Magento\Integration\Api\CustomerTokenServiceInterface;
|
||||
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
/**
|
||||
* End to end place order test using payflowpro via graphql endpoint for customer
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class PlaceOrderWithPayflowProTest 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/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 testResolveCustomer(): 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;
|
||||
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
$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, [], '', $requestHeaders);
|
||||
$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']
|
||||
);
|
||||
}
|
||||
}
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\PaypalGraphQl\Model\Resolver\Customer;
|
||||
|
||||
use Magento\Integration\Api\CustomerTokenServiceInterface;
|
||||
use Magento\Integration\Model\Oauth\Token;
|
||||
use Magento\PaypalGraphQl\PaypalPayflowProAbstractTest;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Vault\Api\Data\PaymentTokenInterface;
|
||||
use Magento\Vault\Model\PaymentTokenManagement;
|
||||
use Magento\Vault\Model\PaymentTokenRepository;
|
||||
|
||||
/**
|
||||
* End to end place order test using payflowpro via graphql endpoint for customer
|
||||
*
|
||||
* @magentoAppArea graphql
|
||||
*/
|
||||
class SaveCartDataWithPayflowProTest 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place order use payflowpro method and save cart data to future
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 testPlaceOrderAndSaveDataForFuturePayflowPro(): void
|
||||
{
|
||||
$responseData = $this->placeOrderPayflowPro('is_active_payment_token_enabler: true');
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertArrayHasKey('createPayflowProToken', $responseData['data']);
|
||||
$this->assertNotEmpty($this->getVaultCartData()->getPublicHash());
|
||||
$this->assertNotEmpty($this->getVaultCartData()->getTokenDetails());
|
||||
$this->assertNotEmpty($this->getVaultCartData()->getGatewayToken());
|
||||
$this->assertTrue($this->getVaultCartData()->getIsActive());
|
||||
$this->assertTrue($this->getVaultCartData()->getIsVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* Place order use payflowpro method and not save cart data to future
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
|
||||
* @magentoDataFixture Magento/GraphQl/Quote/_files/add_simple_product.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 testPlaceOrderAndNotSaveDataForFuturePayflowPro(): void
|
||||
{
|
||||
$responseData = $this->placeOrderPayflowPro('is_active_payment_token_enabler: false');
|
||||
$this->assertArrayHasKey('data', $responseData);
|
||||
$this->assertArrayHasKey('createPayflowProToken', $responseData['data']);
|
||||
$this->assertNotEmpty($this->getVaultCartData()->getPublicHash());
|
||||
$this->assertNotEmpty($this->getVaultCartData()->getTokenDetails());
|
||||
$this->assertNotEmpty($this->getVaultCartData()->getGatewayToken());
|
||||
$this->assertTrue($this->getVaultCartData()->getIsActive());
|
||||
$this->assertFalse($this->getVaultCartData()->getIsVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $isActivePaymentTokenEnabler
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
private function placeOrderPayflowPro($isActivePaymentTokenEnabler)
|
||||
{
|
||||
$paymentMethod = 'payflowpro';
|
||||
$this->enablePaymentMethod($paymentMethod);
|
||||
$this->enablePaymentMethod('payflowpro_cc_vault');
|
||||
$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: {
|
||||
{$isActivePaymentTokenEnabler}
|
||||
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;
|
||||
|
||||
/** @var CustomerTokenServiceInterface $tokenService */
|
||||
$tokenService = $this->objectManager->get(CustomerTokenServiceInterface::class);
|
||||
$customerToken = $tokenService->createCustomerAccessToken('customer@example.com', 'password');
|
||||
|
||||
$requestHeaders = [
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $customerToken
|
||||
];
|
||||
$paypalResponse = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'securetoken' => 'mysecuretoken',
|
||||
'securetokenid' => 'mysecuretokenid',
|
||||
'respmsg' => 'Approved',
|
||||
'result_code' => '0',
|
||||
]
|
||||
);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willReturn($paypalResponse);
|
||||
|
||||
$this->gatewayMock
|
||||
->method('postRequest')
|
||||
->willReturn(
|
||||
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, [], '', $requestHeaders);
|
||||
|
||||
return $this->json->unserialize($response->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get saved cart data
|
||||
*
|
||||
* @return PaymentTokenInterface
|
||||
*/
|
||||
private function getVaultCartData()
|
||||
{
|
||||
/** @var PaymentTokenManagement $tokenManagement */
|
||||
$tokenManagement = $this->objectManager->get(PaymentTokenManagement::class);
|
||||
$token = $tokenManagement->getByGatewayToken(
|
||||
'B70CCC236815',
|
||||
'payflowpro',
|
||||
1
|
||||
);
|
||||
/** @var PaymentTokenRepository $tokenRepository */
|
||||
$tokenRepository = $this->objectManager->get(PaymentTokenRepository::class);
|
||||
return $tokenRepository->getById($token->getEntityId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user