ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Adminhtml\Paypal;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ReportsTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/active 1
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_ip 127.0.0.1
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_path /tmp
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_login login
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_password password
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_sandbox 0
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testFetchAction()
|
||||
{
|
||||
$this->dispatch('backend/paypal/paypal_reports/fetch');
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['We can't fetch reports from "login@127.0.0.1."']),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Adminhtml\Billing\Agreement\View\Tab;
|
||||
|
||||
class InfoTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testCustomerGridAction()
|
||||
{
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
)->load();
|
||||
$agreementId = $billingAgreementCollection->getFirstItem()->getId();
|
||||
$this->dispatch('backend/paypal/billing_agreement/view/agreement/' . $agreementId);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//a[@name="billing_agreement_info"]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
'Response for billing agreement info doesn\'t contain billing agreement info tab'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//a[contains(text(), "customer@example.com")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
'Response for billing agreement info doesn\'t contain Customer info'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Test for \Magento\Paypal\Block\Billing\Agreement\View
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class ViewTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/** @var \Magento\Paypal\Block\Billing\Agreement\View */
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_block = Bootstrap::getObjectManager()->create(\Magento\Paypal\Block\Billing\Agreement\View::class);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting orders associated with specified billing agreement.
|
||||
*
|
||||
* Create two identical orders, associate one of them with billing agreement and invoke testGetRelatedOrders()
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetRelatedOrders()
|
||||
{
|
||||
/** Customer ID declared in the fixture */
|
||||
$customerId = 1;
|
||||
/** Assign first order to the active customer */
|
||||
/** @var \Magento\Sales\Model\Order $orderA */
|
||||
$orderA = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$orderA->loadByIncrementId('100000001');
|
||||
$orderA->setCustomerIsGuest(false)->setCustomerId($customerId)->save();
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerId($customerId);
|
||||
|
||||
/** Assign second order to the active customer */
|
||||
$orderB = clone $orderA;
|
||||
$orderB->setId(
|
||||
null
|
||||
)->setIncrementId(
|
||||
'100000002'
|
||||
)->setCustomerIsGuest(
|
||||
false
|
||||
)->setCustomerId(
|
||||
$customerId
|
||||
)->save();
|
||||
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerId($customerId);
|
||||
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
);
|
||||
/** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
|
||||
$billingAgreement = $billingAgreementCollection->getFirstItem();
|
||||
$billingAgreement->addOrderRelation($orderA->getId())->save();
|
||||
|
||||
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->register('current_billing_agreement', $billingAgreement);
|
||||
|
||||
$relatedOrders = $this->_block->getRelatedOrders();
|
||||
$this->assertEquals(1, $relatedOrders->count(), "Only one order must be returned.");
|
||||
$this->assertEquals(
|
||||
$orderA->getId(),
|
||||
$relatedOrders->getFirstItem()->getId(),
|
||||
"Invalid order returned as associated with billing agreement."
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Bml;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class BannersTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param int $publisherId
|
||||
* @param int $display
|
||||
* @param int $position
|
||||
* @param int $configPosition
|
||||
* @param bool $isEmptyHtml
|
||||
* @param string $methodWppBml
|
||||
* @param string $methodWppPeBml
|
||||
* @dataProvider toHtmlDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testToHtml(
|
||||
$publisherId,
|
||||
$display,
|
||||
$position,
|
||||
$configPosition,
|
||||
$isEmptyHtml,
|
||||
$methodWppBml,
|
||||
$methodWppPeBml
|
||||
) {
|
||||
/** @var \Magento\Paypal\Model\Config|\PHPUnit\Framework\MockObject\MockObject $paypalConfig */
|
||||
$paypalConfig = $this->createMock(\Magento\Paypal\Model\Config::class);
|
||||
$paypalConfig->expects($this->any())->method('getBmlPublisherId')->willReturn($publisherId);
|
||||
$paypalConfig->expects($this->any())->method('getBmlDisplay')->willReturn($display);
|
||||
$paypalConfig->expects($this->any())->method('getBmlPosition')->willReturn($configPosition);
|
||||
|
||||
$paypalConfig->expects($this->any())
|
||||
->method('isMethodAvailable')
|
||||
->willReturnMap(
|
||||
[
|
||||
[
|
||||
$methodWppBml,
|
||||
true,
|
||||
],
|
||||
[
|
||||
$methodWppPeBml,
|
||||
true,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
/** @var \Magento\Framework\View\LayoutInterface $layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$block = $layout->createBlock(
|
||||
\Magento\Paypal\Block\Bml\Banners::class,
|
||||
'',
|
||||
[
|
||||
'paypalConfig' => $paypalConfig,
|
||||
'data' => ['position' => $position]
|
||||
]
|
||||
);
|
||||
$block->setTemplate('bml.phtml');
|
||||
$html = $block->toHtml();
|
||||
|
||||
if ($isEmptyHtml) {
|
||||
$this->assertEmpty($html);
|
||||
} else {
|
||||
$this->assertStringContainsString('data-pp-pubid="' . $block->getPublisherId() . '"', $html);
|
||||
$this->assertStringContainsString('data-pp-placementtype="' . $block->getSize() . '"', $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toHtmlDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'publisherId' => 1,
|
||||
'display' => 1,
|
||||
'position' => 100,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => false,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
],
|
||||
[
|
||||
'publisherId' => 0,
|
||||
'display' => 1,
|
||||
'position' => 100,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => true,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
],
|
||||
[
|
||||
'publisherId' => 1,
|
||||
'display' => 0,
|
||||
'position' => 100,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => true,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
],
|
||||
[
|
||||
'publisherId' => 1,
|
||||
'display' => 0,
|
||||
'position' => 10,
|
||||
'configPosition' => 100,
|
||||
'isEmptyHtml' => true,
|
||||
'methodWppBml' => 'paypal_express_bml',
|
||||
'methodWppPeBml' => 'payflow_express_bml',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Express\Review;
|
||||
|
||||
use Magento\Customer\Model\Context;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class BillingTest
|
||||
*/
|
||||
class BillingTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Paypal\Block\Express\Review\Billing */
|
||||
protected $_block;
|
||||
|
||||
/** @var \Magento\Customer\Api\AddressRepositoryInterface */
|
||||
protected $_addressRepository;
|
||||
|
||||
/** @var \Magento\Quote\Model\Quote\AddressFactory */
|
||||
protected $_quoteAddressFactory;
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface */
|
||||
protected $_customerRepository;
|
||||
|
||||
const FIXTURE_CUSTOMER_ID = 1;
|
||||
|
||||
const FIXTURE_ADDRESS_ID = 1;
|
||||
|
||||
const SAMPLE_FIRST_NAME = 'UpdatedFirstName';
|
||||
|
||||
const SAMPLE_LAST_NAME = 'UpdatedLastName';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$this->_customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $this->_customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
|
||||
|
||||
$customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->setCustomerData($customer);
|
||||
|
||||
$this->_addressRepository = $objectManager->get(\Magento\Customer\Api\AddressRepositoryInterface::class);
|
||||
//fetch sample address
|
||||
$address = $this->_addressRepository->getById(self::FIXTURE_ADDRESS_ID);
|
||||
|
||||
/** @var \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection */
|
||||
$quoteCollection = $objectManager->get(\Magento\Quote\Model\ResourceModel\Quote\Collection::class);
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $quoteCollection->getLastItem();
|
||||
$quote->setCustomer($customer);
|
||||
/** @var $quoteAddressFactory \Magento\Quote\Model\Quote\AddressFactory */
|
||||
$this->_quoteAddressFactory = $objectManager->get(\Magento\Quote\Model\Quote\AddressFactory::class);
|
||||
$billingAddress = $this->_quoteAddressFactory->create()->importCustomerAddressData($address);
|
||||
$quote->setBillingAddress($billingAddress);
|
||||
$quote->save();
|
||||
|
||||
/** @var \Magento\Checkout\Model\Session $checkoutSession */
|
||||
$checkoutSession = $objectManager->get(\Magento\Checkout\Model\Session::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
$checkoutSession->setLoadInactive(true);
|
||||
|
||||
$objectManager->get(\Magento\Framework\App\Http\Context::class)
|
||||
->setValue(Context::CONTEXT_AUTH, true, false);
|
||||
$this->_block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class)
|
||||
->createBlock(
|
||||
\Magento\Paypal\Block\Express\Review\Billing::class,
|
||||
'',
|
||||
['customerSession' => $customerSession, 'resourceSession' => $checkoutSession]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetAddress()
|
||||
{
|
||||
$addressFromFixture = $this->_addressRepository->getById(self::FIXTURE_ADDRESS_ID);
|
||||
$address = $this->_block->getAddress();
|
||||
$this->assertEquals($addressFromFixture->getFirstname(), $address->getFirstname());
|
||||
$this->assertEquals($addressFromFixture->getLastname(), $address->getLastname());
|
||||
$this->assertEquals($addressFromFixture->getCustomerId(), $address->getCustomerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetAddressNotSetInQuote()
|
||||
{
|
||||
$this->_updateQuoteCustomerName();
|
||||
$address = $this->_block->getAddress();
|
||||
//Make sure the data from sample address was set correctly to the block from customer
|
||||
$this->assertEquals(self::SAMPLE_FIRST_NAME, $address->getFirstname());
|
||||
$this->assertEquals(self::SAMPLE_LAST_NAME, $address->getLastname());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_address.php
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_product_and_payment.php
|
||||
*/
|
||||
public function testGetFirstNameAndLastName()
|
||||
{
|
||||
$this->_updateQuoteCustomerName();
|
||||
//Make sure the data from sample address was set correctly to the block from customer
|
||||
$this->assertEquals(self::SAMPLE_FIRST_NAME, $this->_block->getFirstname());
|
||||
$this->assertEquals(self::SAMPLE_LAST_NAME, $this->_block->getLastname());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Customer name in Quote
|
||||
*/
|
||||
protected function _updateQuoteCustomerName()
|
||||
{
|
||||
/** @var $emptyAddress \Magento\Quote\Model\Quote\Address */
|
||||
$emptyAddress = $this->_quoteAddressFactory->create();
|
||||
$emptyAddress->setFirstname(null);
|
||||
$emptyAddress->setLastname(null);
|
||||
$this->_block->getQuote()->setBillingAddress($emptyAddress);
|
||||
$customer = $this->_customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
|
||||
$customer->setFirstname(
|
||||
self::SAMPLE_FIRST_NAME
|
||||
)->setLastname(
|
||||
self::SAMPLE_LAST_NAME
|
||||
);
|
||||
$this->_block->getQuote()->setCustomer($customer);
|
||||
$this->_block->getQuote()->save();
|
||||
|
||||
$this->assertEquals(self::SAMPLE_FIRST_NAME, $this->_block->getFirstname());
|
||||
$this->assertEquals(self::SAMPLE_LAST_NAME, $this->_block->getLastname());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Paypal\Block\Express\Review
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Express;
|
||||
|
||||
class ReviewTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*/
|
||||
public function testRenderAddress()
|
||||
{
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test01', 'reserved_order_id');
|
||||
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Paypal\Block\Express\Review::class
|
||||
);
|
||||
$addressData = include __DIR__ . '/../../../Sales/_files/address_data.php';
|
||||
$address = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\Quote\Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$address->setAddressType('billing');
|
||||
$address->setQuote($quote);
|
||||
$this->assertStringContainsString('Los Angeles', $block->renderAddress($address));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Block\PayLater;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Framework\App\MutableScopeConfig;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BannerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @dataProvider getJsLayoutDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getJsLayout()
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getStyleAttributesConfig()
|
||||
*/
|
||||
public function testGetJsLayout($systemConfig, $blockConfig, $expectedConfig)
|
||||
{
|
||||
$this->setConfig($systemConfig);
|
||||
|
||||
/** @var LayoutInterface $layout */
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
|
||||
$jsConfig = json_decode($block->getJsLayout(), true);
|
||||
$this->assertArrayHasKey('config', $jsConfig['components']['payLater']);
|
||||
$this->assertArrayHasKey('component', $jsConfig['components']['payLater']);
|
||||
|
||||
$optionsConfig = $jsConfig['components']['payLater']['config'];
|
||||
$this->assertEquals($expectedConfig, array_intersect_key($optionsConfig, $expectedConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getJsLayoutDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test1page_stylelayout' => 'flex',
|
||||
'payment/paypal_paylater/test1page_ratio' => '20x1',
|
||||
'payment/paypal_paylater/test1page_color' => 'blue'
|
||||
],
|
||||
'blockConfig' => [
|
||||
'placement' => 'test1',
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-ratio' => '1x1'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedConfig' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-layout' => 'flex',
|
||||
'data-pp-style-logo-type' => null,
|
||||
'data-pp-style-logo-position' => null,
|
||||
'data-pp-style-text-color' => null,
|
||||
'data-pp-style-text-size' => null,
|
||||
'data-pp-style-color' => 'blue',
|
||||
'data-pp-style-ratio' => '1x1',
|
||||
'data-pp-placement' => 'test1'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test2page_stylelayout' => 'text',
|
||||
'payment/paypal_paylater/test2page_logotype' => 'primary',
|
||||
'payment/paypal_paylater/test2page_logoposition' => 'left',
|
||||
'payment/paypal_paylater/test2page_textcolor' => 'white',
|
||||
'payment/paypal_paylater/test2page_textsize' => '10'
|
||||
|
||||
],
|
||||
'blockConfig' => [
|
||||
'placement' => 'test2',
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-text-color' => 'black'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedConfig' => [
|
||||
'attributes' => [
|
||||
'data-pp-style-layout' => 'text',
|
||||
'data-pp-style-logo-type' => 'primary',
|
||||
'data-pp-style-logo-position' => 'left',
|
||||
'data-pp-style-text-color' => 'black',
|
||||
'data-pp-style-text-size' => '10',
|
||||
'data-pp-style-color' => null,
|
||||
'data-pp-style-ratio' => null,
|
||||
'data-pp-placement' => 'test2'
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @dataProvider sdkUrlDataProvider
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getJsLayout()
|
||||
* @covers \Magento\Paypal\Block\PayLater\Banner::getPayPalSdkUrl()
|
||||
*/
|
||||
public function testSdkUrl($blockConfig, $expectedUrl)
|
||||
{
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
|
||||
$jsConfig = json_decode($block->getJsLayout(), true);
|
||||
$this->assertArrayHasKey('config', $jsConfig['components']['payLater']);
|
||||
$this->assertArrayHasKey('sdkUrl', $jsConfig['components']['payLater']['config']);
|
||||
$this->assertStringContainsString($expectedUrl, $jsConfig['components']['payLater']['config']['sdkUrl']);
|
||||
}
|
||||
|
||||
public function sdkUrlDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'blockConfig' => [
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedUrl' => 'paypal.com/sdk'
|
||||
],
|
||||
[
|
||||
'blockConfig' => [
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'attributes' => ['test1' => 'value1']
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedUrl' => 'paypal.com/sdk'
|
||||
],
|
||||
[
|
||||
'blockConfig' => [
|
||||
'jsLayout' => [
|
||||
'components' => [
|
||||
'payLater' => [
|
||||
'config' => [
|
||||
'sdkUrl' => 'http://mock.url'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'expectedUrl' => 'mock.url'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testToHtml()
|
||||
{
|
||||
$paymentMethod = sprintf('payment/%s/active', Config::METHOD_EXPRESS);
|
||||
$systemConfig = [
|
||||
$paymentMethod => 1,
|
||||
'payment/paypal_paylater/experience_active' => 1,
|
||||
'payment/paypal_paylater/enabled' => 1,
|
||||
'payment/paypal_paylater/test3page_display' => 1,
|
||||
'payment/paypal_paylater/test3page_position' => 'header'
|
||||
];
|
||||
$blockConfig = [
|
||||
'placement' => 'test3',
|
||||
'position' => 'header'
|
||||
];
|
||||
$this->setConfig($systemConfig);
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
|
||||
/** @var Banner $block */
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
$block->setTemplate('Magento_Paypal::paylater/banner.phtml');
|
||||
|
||||
$this->assertNotEmpty($block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check display configuration
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider toHtmlEmptyDataProvider
|
||||
* @param $systemConfig
|
||||
* @param $blockConfig
|
||||
*/
|
||||
public function testToHtmlEmpty($systemConfig, $blockConfig)
|
||||
{
|
||||
//Enable all required options
|
||||
$paymentMethod = sprintf('payment/%s/active', Config::METHOD_EXPRESS);
|
||||
$enableSystemConfig = [
|
||||
$paymentMethod => 1,
|
||||
'payment/paypal_paylater/experience_active' => 1,
|
||||
'payment/paypal_paylater/enabled' => 1,
|
||||
'payment/paypal_paylater/test4page_display' => 1,
|
||||
'payment/paypal_paylater/test4page_position' => 'near_pp_button'
|
||||
];
|
||||
$enableBlockConfig = [
|
||||
'placement' => 'test4',
|
||||
'position' => 'near_pp_button'
|
||||
];
|
||||
//Disable specific system configuration option
|
||||
$systemConfig = array_replace($enableSystemConfig, $systemConfig);
|
||||
// Update block config
|
||||
$blockConfig = array_replace($enableBlockConfig, $blockConfig);
|
||||
$this->setConfig($systemConfig);
|
||||
$layout = Bootstrap::getObjectManager()->get(LayoutInterface::class);
|
||||
/** @var Banner $block */
|
||||
$block = $layout->createBlock(Banner::class, '', ['data' => $blockConfig]);
|
||||
$block->setTemplate('Magento_Paypal::paylater/banner.phtml');
|
||||
|
||||
$this->assertEmpty($block->toHtml());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function toHtmlEmptyDataProvider()
|
||||
{
|
||||
$paymentPath = 'payment/%s/active';
|
||||
return [
|
||||
[
|
||||
'systemConfig' => ['payment/paypal_paylater/experience_active' => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => ['payment/paypal_paylater/enabled' => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => ['payment/paypal_paylater/test4page_display' => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => [],
|
||||
'blockConfig' => ['position' => 'header']
|
||||
],
|
||||
[
|
||||
'systemConfig' => [sprintf($paymentPath, Config::METHOD_EXPRESS) => 0],
|
||||
'blockConfig' => []
|
||||
],
|
||||
[
|
||||
'systemConfig' => ['paypal/style/disable_funding_options' => 'CREDIT'],
|
||||
'blockConfig' => []
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set system configuration value for test
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
private function setConfig($config)
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $scopeConfig MutableScopeConfig */
|
||||
$scopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
|
||||
foreach ($config as $path => $value) {
|
||||
$scopeConfig->setValue($path, $value, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Test for \Magento\Paypal\Block\Payment\Form\Billing\Agreement
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Block\Payment\Form\Billing;
|
||||
|
||||
class AgreementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var \Magento\Paypal\Block\Payment\Form\Billing\Agreement */
|
||||
protected $_block;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\ResourceModel\Quote\Collection::class
|
||||
)->getFirstItem();
|
||||
/** @var \Magento\Framework\View\LayoutInterface $layout */
|
||||
$layout = $this->getMockBuilder(\Magento\Framework\View\LayoutInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$layout->expects(
|
||||
$this->once()
|
||||
)->method(
|
||||
'getBlock'
|
||||
)->willReturn(
|
||||
new \Magento\Framework\DataObject(['quote' => $quote])
|
||||
);
|
||||
$layout->expects($this->once())->method('getParentName')->willReturn('billing_agreement_form');
|
||||
|
||||
$this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Block\Payment\Form\Billing\Agreement::class
|
||||
);
|
||||
$this->_block->setLayout($layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testGetBillingAgreements()
|
||||
{
|
||||
$billingAgreements = $this->_block->getBillingAgreements();
|
||||
$this->assertCount(1, $billingAgreements);
|
||||
$this->assertEquals('REF-ID-TEST-678', array_shift($billingAgreements));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CancelTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::actions_manage';
|
||||
$this->uri = 'backend/paypal/billing_agreement/cancel';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DeleteTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::actions_manage';
|
||||
$this->uri = 'backend/paypal/billing_agreement/delete';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class GridTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::billing_agreement_actions_view';
|
||||
$this->uri = 'backend/paypal/billing_agreement/grid';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testAclHasAccess()
|
||||
{
|
||||
/** @var $session \Magento\Backend\Model\Session */
|
||||
Bootstrap::getObjectManager()->create(\Magento\Backend\Model\Session::class);
|
||||
|
||||
parent::testAclHasAccess();
|
||||
|
||||
$response = $this->getResponse();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//button[@type="button" and @title="Reset Filter"]',
|
||||
$response->getBody()
|
||||
),
|
||||
"Response for billing agreement grid doesn't contain 'Reset Filter' button"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//*[@id="billing_agreements"]',
|
||||
$response->getBody()
|
||||
),
|
||||
"Response for billing agreement grid doesn't contain grid"
|
||||
);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::billing_agreement_actions_view';
|
||||
$this->uri = 'backend/paypal/billing_agreement/index';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ViewTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::billing_agreement_actions_view';
|
||||
$this->uri = 'backend/paypal/billing_agreement/view';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testAclHasAccess()
|
||||
{
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
);
|
||||
$agreementId = $billingAgreementCollection->getFirstItem()->getId();
|
||||
$this->uri = $this->uri . '/agreement/' . $agreementId;
|
||||
|
||||
parent::testAclHasAccess();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//a[@name="billing_agreement_info"]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement info doesn't contain billing agreement info tab"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//a[contains(text(), "customer@example.com")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement info doesn't contain Customer info"
|
||||
);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Billing;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Paypal\Controller\Adminhtml\Billing\Agreement
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AgreementTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testCustomerGrid()
|
||||
{
|
||||
$this->dispatch('backend/paypal/billing_agreement/customergrid/id/1');
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//th[contains(@class,"col-reference_id")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement orders doesn't contain billing agreement customers grid"
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
\Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
|
||||
'//td[contains(text(), "REF-ID-TEST-678")]',
|
||||
$this->getResponse()->getBody()
|
||||
),
|
||||
"Response for billing agreement info doesn't contain reference ID"
|
||||
);
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Express;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\Paypal\Model\Api\Type\Factory as ApiFactory;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\OrderValidatorInterface;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Sales\Model\Order\Payment\Transaction;
|
||||
use Magento\Sales\Model\Order\Validation\CanInvoice;
|
||||
use Magento\Sales\Model\ValidatorResultInterface;
|
||||
|
||||
/**
|
||||
* Makes a test of the payment authorization for Paypal Express when payment action is order.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class AuthorizationTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::authorization';
|
||||
$this->uri = 'backend/paypal/express/authorization';
|
||||
|
||||
parent::setUp();
|
||||
$this->createSharedInstances();
|
||||
}
|
||||
|
||||
/**
|
||||
* Negative scenario for controller calls.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testNoOrderPassed()
|
||||
{
|
||||
$this->dispatch('backend/paypal/express/authorization');
|
||||
$this->assertRedirect($this->stringContains('backend/sales/order/index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of authorization of full order amount.
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/payment_action Order
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_payment_action_order.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @return void
|
||||
*/
|
||||
public function testAuthorization()
|
||||
{
|
||||
/** @var Order $order */
|
||||
$order = $this->_objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$orderValidator = $this->_objectManager->create(OrderValidatorInterface::class);
|
||||
|
||||
/** @var ValidatorResultInterface $validationResult */
|
||||
$validationResult = $orderValidator->validate($order, [CanInvoice::class]);
|
||||
$validationMessages = $validationResult->getMessages();
|
||||
|
||||
$this->assertCount(1, $validationMessages);
|
||||
$this->assertEquals(
|
||||
'An invoice cannot be created when none of authorization transactions available.',
|
||||
$validationMessages[0]
|
||||
);
|
||||
|
||||
/** @var RequestInterface $request */
|
||||
$request = $this->getRequest();
|
||||
$request->setParam('order_id', $order->getId());
|
||||
|
||||
$this->dispatch('backend/paypal/express/authorization');
|
||||
|
||||
$orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
|
||||
$order = $orderRepository->get($order->getId());
|
||||
|
||||
/** @var Payment $payment */
|
||||
$payment = $order->getPayment();
|
||||
|
||||
/** @var ValidatorResultInterface $validationResult */
|
||||
$validationResult = $orderValidator->validate($order, [CanInvoice::class]);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Transaction::class,
|
||||
$payment->getAuthorizationTransaction()
|
||||
);
|
||||
$this->assertEquals($order->getBaseGrandTotal(), $payment->getAmountAuthorized());
|
||||
$this->assertEmpty($validationResult->getMessages());
|
||||
$this->assertRedirect($this->stringContains('backend/sales/order/view/order_id/' . $order->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates required shared instances.
|
||||
*/
|
||||
private function createSharedInstances()
|
||||
{
|
||||
$nvpMock = $this->getMockBuilder(Nvp::class)
|
||||
->setMethods(['call'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$nvpMock->method('call')
|
||||
->willReturn([]);
|
||||
|
||||
$apiFactoryMock = $this->getMockBuilder(ApiFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
|
||||
$apiFactoryMock->method('create')
|
||||
->with(Nvp::class)
|
||||
->willReturn($nvpMock);
|
||||
|
||||
$this->_objectManager->addSharedInstance($apiFactoryMock, ApiFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_objectManager->removeSharedInstance(ApiFactory::class);
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DetailsTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::paypal_settlement_reports_view';
|
||||
$this->uri = 'backend/paypal/paypal_reports/details';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FetchTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::fetch';
|
||||
$this->uri = 'backend/paypal/paypal_reports/fetch';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Paypal\Reports;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resource = 'Magento_Paypal::paypal_settlement_reports_view';
|
||||
$this->uri = 'backend/paypal/paypal_reports/index';
|
||||
parent::setUp();
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Adminhtml\System;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*
|
||||
* @dataProvider saveMerchantCountryDataProvider
|
||||
*
|
||||
* @param string $section
|
||||
* @param array $groups
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveMerchantCountry(string $section, array $groups): void
|
||||
{
|
||||
/** @var ScopeConfigInterface $scopeConfig */
|
||||
$scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$request->setPostValue($groups)
|
||||
->setParam('section', $section)
|
||||
->setMethod(HttpRequest::METHOD_POST);
|
||||
|
||||
$this->dispatch('backend/admin/system_config/save');
|
||||
|
||||
$this->assertSessionMessages($this->equalTo(['You saved the configuration.']));
|
||||
|
||||
$this->assertEquals(
|
||||
'GB',
|
||||
$scopeConfig->getValue('paypal/general/merchant_country')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function saveMerchantCountryDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'section' => 'paypal',
|
||||
'groups' => [
|
||||
'groups' => [
|
||||
'general' => [
|
||||
'fields' => [
|
||||
'merchant_country' => ['value' => 'GB'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'section' => 'payment',
|
||||
'groups' => [
|
||||
'groups' => [
|
||||
'account' => [
|
||||
'fields' => [
|
||||
'merchant_country' => ['value' => 'GB'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Adminhtml\Transparent;
|
||||
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Session\Generic;
|
||||
use Magento\Paypal\Model\Payflow\Transparent;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\PaymentMethodManagementInterface;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Tests PayPal transparent response controller.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ResponseTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Tests storing payment information on backend from PayPal response.
|
||||
*
|
||||
* @throws NoSuchEntityException
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*/
|
||||
public function testStoringPaymentInformation()
|
||||
{
|
||||
$reservedOrderId = 'test01';
|
||||
$pnref = 'A10AAD866C87';
|
||||
$postData = [
|
||||
'EXPDATE' => '0321',
|
||||
'AMT' => '0.00',
|
||||
'RESPMSG' => 'Verified',
|
||||
'CVV2MATCH' => 'Y',
|
||||
'PNREF' => $pnref,
|
||||
'SECURETOKEN' => '3HYEHfG06skydAdBXbpIl8QJZ',
|
||||
'AVSDATA' => 'YNY',
|
||||
'RESULT' => '0',
|
||||
'IAVS' => 'N',
|
||||
'AVSADDR' => 'Y',
|
||||
'SECURETOKENID' => 'yqanLisRZbI0HAG8q3SbbKbhiwjNZAGf',
|
||||
];
|
||||
|
||||
$quote = $this->getQuote($reservedOrderId);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
/** @var Session $checkoutSession */
|
||||
$checkoutSession = $this->_objectManager->get(Generic::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
|
||||
$this->dispatch('backend/paypal/transparent/response');
|
||||
|
||||
/** @var PaymentMethodManagementInterface $paymentManagment */
|
||||
$paymentManagment = $this->_objectManager->get(PaymentMethodManagementInterface::class);
|
||||
$payment = $paymentManagment->get($quote->getId());
|
||||
|
||||
$this->assertEquals($pnref, $payment->getAdditionalInformation(Transparent::PNREF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order ID.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return CartInterface
|
||||
*/
|
||||
private function getQuote(string $reservedOrderId): CartInterface
|
||||
{
|
||||
$searchCriteria = $this->_objectManager->get(SearchCriteriaBuilder::class)
|
||||
->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Billing;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Payment\Helper\Data;
|
||||
use Magento\Paypal\Controller\Billing\Agreement\ReturnWizard;
|
||||
use Magento\Paypal\Model\Express;
|
||||
use Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection;
|
||||
use Magento\Store\Model\StoreManager;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Paypal\Controller\Billing\Agreement
|
||||
*/
|
||||
class AgreementTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Test billing agreement record creation in Magento DB.
|
||||
*
|
||||
* All mocking effort is aimed to disable remote call for billing agreement creation in the external system.
|
||||
* Request parameters and current customer are emulated as well.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReturnWizardAction(): void
|
||||
{
|
||||
$paymentMethod = "paypal_express";
|
||||
$token = "token_value";
|
||||
$referenceId = "Reference-id-1";
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** Mock Request */
|
||||
$requestMock = $this->getMockForAbstractClass(RequestInterface::class, [], '', false);
|
||||
$requestMock->expects($this->any())
|
||||
->method('getParam')
|
||||
->willReturnMap(
|
||||
[
|
||||
['payment_method', null, $paymentMethod],
|
||||
['token', null, $token]
|
||||
]
|
||||
);
|
||||
|
||||
/**
|
||||
* Disable billing agreement placement using calls to remote system
|
||||
* in \Magento\Paypal\Model\Billing\Agreement::place()
|
||||
*/
|
||||
$objectManagerMock = $this->createMock(ObjectManagerInterface::class);
|
||||
$paymentMethodMock = $this->getMockBuilder(Express::class)
|
||||
->disableOriginalConstructor()
|
||||
->disableOriginalClone()
|
||||
->disableArgumentCloning()
|
||||
->disallowMockingUnknownTypes()
|
||||
->onlyMethods(['getTitle', 'setStore'])
|
||||
->addMethods(['placeBillingAgreement'])
|
||||
->getMock();
|
||||
$paymentMethodMock->expects($this->any())->method('placeBillingAgreement')->willReturnSelf();
|
||||
$paymentMethodMock->expects($this->any())->method('getTitle')->willReturn($paymentMethod);
|
||||
|
||||
$paymentHelperMock = $this->createPartialMock(Data::class, ['getMethodInstance']);
|
||||
$paymentHelperMock->expects($this->any())
|
||||
->method('getMethodInstance')
|
||||
->willReturn($paymentMethodMock);
|
||||
$billingAgreement = $objectManager->create(
|
||||
\Magento\Paypal\Model\Billing\Agreement::class,
|
||||
['paymentData' => $paymentHelperMock]
|
||||
);
|
||||
/** Reference ID is normally set by placeBillingAgreement() and is an agreement ID in the external system. */
|
||||
$billingAgreement->setBillingAgreementId($referenceId);
|
||||
$objectManagerMock->expects($this->once())
|
||||
->method('create')
|
||||
->with(\Magento\Paypal\Model\Billing\Agreement::class, [])
|
||||
->willReturn($billingAgreement);
|
||||
$storeManager = $objectManager->get(StoreManager::class);
|
||||
$customerSession = $objectManager->get(Session::class);
|
||||
$objectManagerMock->expects($this->any())
|
||||
->method('get')
|
||||
->willReturnMap(
|
||||
[
|
||||
[StoreManager::class, $storeManager],
|
||||
[Session::class, $customerSession],
|
||||
]
|
||||
);
|
||||
$contextMock = $objectManager->create(
|
||||
Context::class,
|
||||
[
|
||||
'objectManager' => $objectManagerMock,
|
||||
'request' => $requestMock
|
||||
]
|
||||
);
|
||||
/** @var \Magento\Paypal\Controller\Billing\Agreement $billingAgreementController */
|
||||
$billingAgreementController = $objectManager->create(
|
||||
ReturnWizard::class,
|
||||
['context' => $contextMock]
|
||||
);
|
||||
|
||||
/** Initialize current customer */
|
||||
/** @var Session $customerSession */
|
||||
$customerSession = $objectManager->get(Session::class);
|
||||
$fixtureCustomerId = 1;
|
||||
$customerSession->setCustomerId($fixtureCustomerId);
|
||||
|
||||
/** Execute SUT */
|
||||
$billingAgreementController->execute();
|
||||
|
||||
/** Ensure that billing agreement record was created in the DB */
|
||||
/** @var Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = $objectManager->create(
|
||||
Collection::class
|
||||
);
|
||||
/** @var \Magento\Paypal\Model\Billing\Agreement $createdBillingAgreement */
|
||||
$createdBillingAgreement = $billingAgreementCollection->getLastItem();
|
||||
$this->assertEquals($fixtureCustomerId, $createdBillingAgreement->getCustomerId(), "Customer ID is invalid.");
|
||||
$this->assertEquals($referenceId, $createdBillingAgreement->getReferenceId(), "Reference ID is invalid.");
|
||||
$this->assertEquals($paymentMethod, $createdBillingAgreement->getMethodCode(), "Method code is invalid.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller;
|
||||
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\Session\Generic as GenericSession;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\Paypal\Model\Api\Type\Factory as ApiFactory;
|
||||
use Magento\Paypal\Model\Session as PaypalSession;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Tests of Paypal Express actions
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ExpressTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment.php
|
||||
*/
|
||||
public function testReviewAction()
|
||||
{
|
||||
$quote = Bootstrap::getObjectManager()->create(Quote::class);
|
||||
$quote->load('test01', 'reserved_order_id');
|
||||
Bootstrap::getObjectManager()->get(
|
||||
Session::class
|
||||
)->setQuoteId(
|
||||
$quote->getId()
|
||||
);
|
||||
|
||||
$this->dispatch('paypal/express/review');
|
||||
|
||||
$html = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('Simple Product', $html);
|
||||
$this->assertStringContainsString('Review', $html);
|
||||
$this->assertStringContainsString('/paypal/express/placeOrder/', $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
|
||||
* @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com
|
||||
*/
|
||||
public function testCancelAction()
|
||||
{
|
||||
$quote = $this->_objectManager->create(Quote::class);
|
||||
$quote->load('100000002', 'reserved_order_id');
|
||||
$order = $this->_objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->load('100000002', 'increment_id');
|
||||
$session = $this->_objectManager->get(Session::class);
|
||||
$session->setLoadInactive(true);
|
||||
$session->setLastRealOrderId(
|
||||
$order->getRealOrderId()
|
||||
)->setLastOrderId(
|
||||
$order->getId()
|
||||
)->setLastQuoteId(
|
||||
$order->getQuoteId()
|
||||
)->setQuoteId(
|
||||
$order->getQuoteId()
|
||||
);
|
||||
/** @var $paypalSession PaypalSession */
|
||||
$paypalSession = $this->_objectManager->get(PaypalSession::class); // @phpstan-ignore-line
|
||||
$paypalSession->setExpressCheckoutToken('token');
|
||||
|
||||
$this->dispatch('paypal/express/cancel');
|
||||
|
||||
$order->load('100000002', 'increment_id');
|
||||
$this->assertEquals('canceled', $order->getState());
|
||||
$this->assertEquals($session->getQuote()->getGrandTotal(), $quote->getGrandTotal());
|
||||
$this->assertEquals($session->getQuote()->getItemsCount(), $quote->getItemsCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test ensures only that customer data was copied to quote correctly.
|
||||
*
|
||||
* Note that test does not verify communication during remote calls to PayPal.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*/
|
||||
public function testStartActionCustomerToQuote()
|
||||
{
|
||||
$fixtureCustomerId = 1;
|
||||
$fixtureCustomerEmail = 'customer@example.com';
|
||||
$fixtureCustomerFirstname = 'John';
|
||||
$fixtureQuoteReserveId = 'test01';
|
||||
|
||||
/** Preconditions */
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $this->_objectManager->get(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customerData = $customerRepository->getById($fixtureCustomerId);
|
||||
$customerSession->setCustomerDataObject($customerData);
|
||||
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->_objectManager->create(Quote::class);
|
||||
$quote->load($fixtureQuoteReserveId, 'reserved_order_id');
|
||||
|
||||
/** @var Session $checkoutSession */
|
||||
$checkoutSession = $this->_objectManager->get(Session::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
|
||||
/** Preconditions check */
|
||||
$this->assertNotEquals(
|
||||
$fixtureCustomerEmail,
|
||||
$quote->getCustomerEmail(),
|
||||
"Precondition failed: customer email in quote is invalid."
|
||||
);
|
||||
$this->assertNotEquals(
|
||||
$fixtureCustomerFirstname,
|
||||
$quote->getCustomerFirstname(),
|
||||
"Precondition failed: customer first name in quote is invalid."
|
||||
);
|
||||
|
||||
/** Execute SUT */
|
||||
$this->dispatch('paypal/express/start');
|
||||
|
||||
/** Check if customer data was copied to quote correctly */
|
||||
/** @var Quote $updatedQuote */
|
||||
$updatedQuote = $this->_objectManager->create(Quote::class);
|
||||
$updatedQuote->load($fixtureQuoteReserveId, 'reserved_order_id');
|
||||
$this->assertEquals(
|
||||
$fixtureCustomerEmail,
|
||||
$updatedQuote->getCustomer()->getEmail(),
|
||||
"Customer email in quote is invalid."
|
||||
);
|
||||
$this->assertEquals(
|
||||
$fixtureCustomerFirstname,
|
||||
$updatedQuote->getCustomer()->getFirstname(),
|
||||
"Customer first name in quote is invalid."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test return action with configurable product.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_express_configurable.php
|
||||
*/
|
||||
public function testReturnAction()
|
||||
{
|
||||
$quote = $this->_objectManager->create(Quote::class);
|
||||
$quote->load('test_cart_with_configurable', 'reserved_order_id');
|
||||
|
||||
$payment = $quote->getPayment();
|
||||
$payment->setMethod(\Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS)
|
||||
->setAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID, 123);
|
||||
|
||||
$quote->save();
|
||||
|
||||
$this->_objectManager->removeSharedInstance(Session::class);
|
||||
$session = $this->_objectManager->get(Session::class);
|
||||
$session->setQuoteId($quote->getId());
|
||||
|
||||
$nvpMethods = [
|
||||
'setToken',
|
||||
'setPayerId',
|
||||
'setAmount',
|
||||
'setPaymentAction',
|
||||
'setNotifyUrl',
|
||||
'setInvNum',
|
||||
'setCurrencyCode',
|
||||
'setPaypalCart',
|
||||
'setIsLineItemsEnabled',
|
||||
'setAddress',
|
||||
'setBillingAddress',
|
||||
'callDoExpressCheckoutPayment',
|
||||
'callGetExpressCheckoutDetails',
|
||||
'getExportedBillingAddress'
|
||||
];
|
||||
|
||||
$nvpMock = $this->getMockBuilder(Nvp::class)
|
||||
->setMethods($nvpMethods)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
foreach ($nvpMethods as $method) {
|
||||
$nvpMock->method($method)
|
||||
->willReturnSelf();
|
||||
}
|
||||
|
||||
$apiFactoryMock = $this->getMockBuilder(ApiFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
|
||||
$apiFactoryMock->method('create')
|
||||
->with(Nvp::class)
|
||||
->willReturn($nvpMock);
|
||||
|
||||
$this->_objectManager->addSharedInstance($apiFactoryMock, ApiFactory::class);
|
||||
|
||||
$sessionMock = $this->getMockBuilder(GenericSession::class)
|
||||
->setMethods(['getExpressCheckoutToken'])
|
||||
->setConstructorArgs(
|
||||
[
|
||||
$this->_objectManager->get(\Magento\Framework\App\Request\Http::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Session\SidResolverInterface::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Session\Config\ConfigInterface::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Session\SaveHandlerInterface::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Session\ValidatorInterface::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Session\StorageInterface::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Stdlib\CookieManagerInterface::class),
|
||||
$this->_objectManager->get(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class),
|
||||
$this->_objectManager->get(\Magento\Framework\App\State::class),
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
|
||||
$sessionMock->method('getExpressCheckoutToken')
|
||||
->willReturn(true);
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
$this->_objectManager->addSharedInstance($sessionMock, PaypalSession::class);
|
||||
|
||||
$this->dispatch('paypal/express/returnAction');
|
||||
$this->assertRedirect($this->stringContains('checkout/onepage/success'));
|
||||
|
||||
$this->_objectManager->removeSharedInstance(ApiFactory::class);
|
||||
// @phpstan-ignore-next-line
|
||||
$this->_objectManager->removeSharedInstance(PaypalSession::class);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Hostedpro;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
use Laminas\Stdlib\Parameters;
|
||||
|
||||
/**
|
||||
* Tests PayPal HostedPro return controller.
|
||||
*/
|
||||
class ReturnActionTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Tests customer redirect on success page after return from PayPal HostedPro payment.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function testReturnRedirect()
|
||||
{
|
||||
$redirectUri = 'paypal/hostedpro/return';
|
||||
$this->setRequestUri($redirectUri);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
|
||||
$this->dispatch($redirectUri);
|
||||
$this->assertRedirect($this->stringContains('checkout/onepage/success'));
|
||||
|
||||
$this->assertEmpty(
|
||||
$_SESSION,
|
||||
'Session start has to be skipped for current controller'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets REQUEST_URI into request object.
|
||||
*
|
||||
* @param string $requestUri
|
||||
* @return void
|
||||
*/
|
||||
private function setRequestUri(string $requestUri)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$reflection = new \ReflectionClass($request);
|
||||
$property = $reflection->getProperty('requestUri');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($request, null);
|
||||
|
||||
$request->setServer(new Parameters(['REQUEST_URI' => $requestUri]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
class HostedproTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
|
||||
* @magentoConfigFixture current_store payment/paypal_hostedpro/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com
|
||||
*/
|
||||
public function testCancelAction()
|
||||
{
|
||||
$order = $this->_objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$session = $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
|
||||
|
||||
$quote = $this->_objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('100000002', 'reserved_order_id');
|
||||
$session->setQuoteId($quote->getId());
|
||||
$session->setPaypalStandardQuoteId($quote->getId())->setLastRealOrderId('100000002');
|
||||
$this->dispatch('paypal/hostedpro/cancel');
|
||||
|
||||
$order->load('100000002', 'increment_id');
|
||||
$this->assertEquals('canceled', $order->getState());
|
||||
$this->assertEquals($session->getQuote()->getGrandTotal(), $quote->getGrandTotal());
|
||||
$this->assertEquals($session->getQuote()->getItemsCount(), $quote->getItemsCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller\Payflow;
|
||||
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Logger\Monolog;
|
||||
use Magento\Payment\Gateway\Command\CommandException;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Paypal\Model\Payflowlink;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
use PHPUnit\Framework\MockObject_MockObject as MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class SilentPostTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var Gateway|MockObject
|
||||
*/
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* @var OrderSender|MockObject
|
||||
*/
|
||||
private $orderSender;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->gateway = $this->getMockBuilder(Gateway::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->orderSender = $this->getMockBuilder(OrderSender::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->_objectManager->addSharedInstance($this->gateway, Gateway::class);
|
||||
$this->_objectManager->addSharedInstance($this->orderSender, OrderSender::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->_objectManager->removeSharedInstance(Gateway::class);
|
||||
$this->_objectManager->removeSharedInstance(OrderSender::class);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a test case when Payflow Link callback action receives Silent Post notification with transaction details.
|
||||
*
|
||||
* @param int $resultCode
|
||||
* @param string $orderState
|
||||
* @param string $orderStatus
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_payflow_link.php
|
||||
* @dataProvider responseCodeDataProvider
|
||||
*/
|
||||
public function testSuccessfulNotification($resultCode, $orderState, $orderStatus)
|
||||
{
|
||||
$orderIncrementId = '000000045';
|
||||
$this->withRequest($orderIncrementId, $resultCode);
|
||||
$this->withGatewayResponse($orderIncrementId, $resultCode);
|
||||
|
||||
$this->dispatch('paypal/payflow/silentPost');
|
||||
|
||||
self::assertEquals(200, $this->getResponse()->getStatusCode());
|
||||
|
||||
$order = $this->getOrder($orderIncrementId);
|
||||
self::assertEquals($orderState, $order->getState());
|
||||
self::assertEquals($orderStatus, $order->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of different variations for Silent Post action testing,
|
||||
* like different response codes from PayPal.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function responseCodeDataProvider()
|
||||
{
|
||||
return [
|
||||
[Payflowlink::RESPONSE_CODE_APPROVED, Order::STATE_COMPLETE, Order::STATE_COMPLETE],
|
||||
[Payflowlink::RESPONSE_CODE_FRAUDSERVICE_FILTER, Order::STATE_PAYMENT_REVIEW, Order::STATUS_FRAUD],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a test case when Payflow Link callback receives Silent Post notification from PayPal
|
||||
* with fraudulent transaction and PayPal gateway configured to reject this kind of transactions.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_payflow_link.php
|
||||
*/
|
||||
public function testFraudulentNotification()
|
||||
{
|
||||
$orderIncrementId = '000000045';
|
||||
$resultCode = Payflowlink::RESPONSE_CODE_DECLINED_BY_FILTER;
|
||||
$this->withRequest($orderIncrementId, $resultCode);
|
||||
$this->withGatewayResponse($orderIncrementId, $resultCode);
|
||||
|
||||
$logger = $this->getMockBuilder(Monolog::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->_objectManager->addSharedInstance($logger, LoggerInterface::class, true);
|
||||
|
||||
$exception = new CommandException(__('Response message from PayPal gateway'));
|
||||
$logger->expects(self::once())
|
||||
->method('critical')
|
||||
->with(self::equalTo($exception));
|
||||
|
||||
$this->dispatch('paypal/payflow/silentPost');
|
||||
|
||||
self::assertEquals(200, $this->getResponse()->getStatusCode());
|
||||
|
||||
$this->_objectManager->removeSharedInstance(LoggerInterface::class, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imitates real POST request with test data.
|
||||
*
|
||||
* @param string $orderIncrementId
|
||||
* @param int $resultCode
|
||||
* @return void
|
||||
*/
|
||||
private function withRequest($orderIncrementId, $resultCode)
|
||||
{
|
||||
$data = [
|
||||
'INVNUM' => $orderIncrementId,
|
||||
'AMT' => 100,
|
||||
'PNREF' => 'A21CP234KLB8',
|
||||
'USER2' => 'cf7i85d01ed7c92223031afb4rdl2f1f',
|
||||
'RESULT' => $resultCode,
|
||||
'TYPE' => 'A',
|
||||
];
|
||||
$this->getRequest()->setPostValue($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imitates response from PayPal gateway.
|
||||
*
|
||||
* @param string $orderIncrementId
|
||||
* @param int $resultCode
|
||||
* @return void
|
||||
*/
|
||||
private function withGatewayResponse($orderIncrementId, $resultCode)
|
||||
{
|
||||
$response = new DataObject([
|
||||
'custref' => $orderIncrementId,
|
||||
'origresult' => $resultCode,
|
||||
'respmsg' => 'Response message from PayPal gateway'
|
||||
]);
|
||||
$this->gateway->method('postRequest')
|
||||
->willReturn($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets order stored by fixture.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrder($incrementId)
|
||||
{
|
||||
/** @var FilterBuilder $filterBuilder */
|
||||
$filterBuilder = $this->_objectManager->get(FilterBuilder::class);
|
||||
$filters = [
|
||||
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
|
||||
->setValue($incrementId)
|
||||
->create()
|
||||
];
|
||||
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
|
||||
->create();
|
||||
|
||||
$orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
|
||||
$orders = $orderRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
return array_pop($orders);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller;
|
||||
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
class PayflowTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $quoteRepository;
|
||||
|
||||
/**
|
||||
* @var OrderInterface
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/** @var FilterBuilder $filterBuilder */
|
||||
$filterBuilder = $this->_objectManager->get(FilterBuilder::class);
|
||||
$filters = [
|
||||
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
|
||||
->setValue('100000001')
|
||||
->create(),
|
||||
];
|
||||
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
|
||||
->create();
|
||||
|
||||
$this->orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
|
||||
$orders = $this->orderRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
$this->order = array_pop($orders);
|
||||
$this->order->getPayment()->setMethod(Config::METHOD_PAYFLOWLINK);
|
||||
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $this->_objectManager->create(Quote::class)->setStoreid($this->order->getStoreId());
|
||||
|
||||
$this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
|
||||
$this->quoteRepository->save($quote);
|
||||
|
||||
$this->order->setQuoteId($quote->getId());
|
||||
$this->orderRepository->save($this->order);
|
||||
|
||||
$session = $this->_objectManager->get(Session::class);
|
||||
$session->setLastRealOrderId($this->order->getRealOrderId())->setLastQuoteId($this->order->getQuoteId());
|
||||
}
|
||||
|
||||
public function testCancelPaymentActionIsContentGenerated()
|
||||
{
|
||||
$this->dispatch('paypal/payflow/cancelpayment');
|
||||
$this->assertStringContainsString("goToSuccessPage = ''", $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
public function testReturnurlActionIsContentGenerated()
|
||||
{
|
||||
$checkoutHelper = $this->_objectManager->create(\Magento\Paypal\Helper\Checkout::class);
|
||||
$checkoutHelper->cancelCurrentOrder('test');
|
||||
$this->dispatch('paypal/payflow/returnurl');
|
||||
$this->assertStringContainsString("goToSuccessPage = ''", $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
public function testFormActionIsContentGenerated()
|
||||
{
|
||||
$this->dispatch('paypal/payflow/form');
|
||||
$this->assertStringContainsString(
|
||||
'<form id="token_form" method="GET" action="https://payflowlink.paypal.com">',
|
||||
$this->getResponse()->getBody()
|
||||
);
|
||||
// Check P3P header
|
||||
$headerConstraints = [];
|
||||
foreach ($this->getResponse()->getHeaders() as $header) {
|
||||
$headerConstraints[] = new \PHPUnit\Framework\Constraint\IsEqual($header->getFieldName());
|
||||
}
|
||||
$constraint = new \PHPUnit\Framework\Constraint\LogicalOr();
|
||||
$constraint->setConstraints($headerConstraints);
|
||||
$this->assertThat('P3P', $constraint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store payment/paypal_payflow/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com
|
||||
* @return void
|
||||
*/
|
||||
public function testCancelAction(): void
|
||||
{
|
||||
$orderId = $this->order->getEntityId();
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->orderRepository->get($orderId);
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $this->quoteRepository->get($order->getQuoteId());
|
||||
|
||||
$session = $this->_objectManager->get(Session::class);
|
||||
$session->setQuoteId($quote->getId());
|
||||
$session->setPaypalStandardQuoteId($quote->getId())->setLastRealOrderId('100000001');
|
||||
$this->dispatch('paypal/payflow/cancelpayment');
|
||||
|
||||
$order = $this->_objectManager->create(OrderRepositoryInterface::class)->get($orderId);
|
||||
$this->assertEquals('canceled', $order->getState());
|
||||
$this->assertEquals($session->getQuote()->getGrandTotal(), $quote->getGrandTotal());
|
||||
$this->assertEquals($session->getQuote()->getItemsCount(), $quote->getItemsCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Controller;
|
||||
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order.php
|
||||
*/
|
||||
class PayflowadvancedTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @var OrderRepositoryInterface
|
||||
*/
|
||||
private $orderRepository;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $quoteRepository;
|
||||
|
||||
/**
|
||||
* @var OrderInterface
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/** @var FilterBuilder $filterBuilder */
|
||||
$filterBuilder = $this->_objectManager->get(FilterBuilder::class);
|
||||
$filters = [
|
||||
$filterBuilder->setField(OrderInterface::INCREMENT_ID)
|
||||
->setValue('100000001')
|
||||
->create(),
|
||||
];
|
||||
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilters($filters)
|
||||
->create();
|
||||
|
||||
$this->orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
|
||||
$orders = $this->orderRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
$this->order = array_pop($orders);
|
||||
$this->order->getPayment()->setMethod(Config::METHOD_PAYFLOWADVANCED);
|
||||
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $this->_objectManager->create(Quote::class)
|
||||
->setStoreid($this->order->getStoreId());
|
||||
|
||||
$this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
|
||||
$this->quoteRepository->save($quote);
|
||||
|
||||
$this->order->setQuoteId($quote->getId());
|
||||
$this->orderRepository->save($this->order);
|
||||
|
||||
$session = $this->_objectManager->get(Session::class);
|
||||
$session->setLastRealOrderId($this->order->getRealOrderId())->setLastQuoteId($this->order->getQuoteId());
|
||||
}
|
||||
|
||||
public function testCancelPaymentActionIsContentGenerated()
|
||||
{
|
||||
$this->dispatch('paypal/payflowadvanced/cancelpayment');
|
||||
$this->assertStringContainsString("goToSuccessPage = ''", $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
public function testReturnurlActionIsContentGenerated()
|
||||
{
|
||||
$checkoutHelper = $this->_objectManager->create(\Magento\Paypal\Helper\Checkout::class);
|
||||
$checkoutHelper->cancelCurrentOrder('test');
|
||||
$this->dispatch('paypal/payflowadvanced/returnurl');
|
||||
$this->assertStringContainsString("goToSuccessPage = ''", $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
public function testFormActionIsContentGenerated()
|
||||
{
|
||||
$this->dispatch('paypal/payflowadvanced/form');
|
||||
$this->assertStringContainsString(
|
||||
'<form id="token_form" method="GET" action="https://payflowlink.paypal.com">',
|
||||
$this->getResponse()->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store payment/paypal_payflow/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/business_account merchant_2012050718_biz@example.com
|
||||
* @return void
|
||||
*/
|
||||
public function testCancelAction(): void
|
||||
{
|
||||
$orderId = $this->order->getEntityId();
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->orderRepository->get($orderId);
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $this->quoteRepository->get($order->getQuoteId());
|
||||
|
||||
$session = $this->_objectManager->get(Session::class);
|
||||
$session->setQuoteId($quote->getId());
|
||||
$session->setPaypalStandardQuoteId($quote->getId())->setLastRealOrderId('100000001');
|
||||
$this->dispatch('paypal/payflowadvanced/cancelpayment');
|
||||
|
||||
$order = $this->_objectManager->create(OrderRepositoryInterface::class)->get($orderId);
|
||||
$this->assertEquals('canceled', $order->getState());
|
||||
$this->assertEquals($session->getQuote()->getGrandTotal(), $quote->getGrandTotal());
|
||||
$this->assertEquals($session->getQuote()->getItemsCount(), $quote->getItemsCount());
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Transparent;
|
||||
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
use Zend\Stdlib\Parameters;
|
||||
|
||||
/**
|
||||
* Tests PayPal transparent redirect controller.
|
||||
*/
|
||||
class RedirectTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Tests transparent redirect for PayPal PayflowPro payment flow.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function testRequestRedirect()
|
||||
{
|
||||
$redirectUri = 'paypal/transparent/redirect';
|
||||
$postData = [
|
||||
'BILLTOCITY' => 'culver city',
|
||||
'AMT' => '0.00',
|
||||
'BILLTOEMAIL' => 'user_1@example.com',
|
||||
'BILLTOSTREET' => '123 Freedom Blvd. #123 app.111',
|
||||
'VISACARDLEVEL' => '12',
|
||||
'SHIPTOCITY' => 'culver city'
|
||||
];
|
||||
|
||||
$this->setRequestUri($redirectUri);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
|
||||
$this->dispatch($redirectUri);
|
||||
|
||||
$responseHtml = $this->getResponse()->getBody();
|
||||
try {
|
||||
$responseNvp = $this->convertToNvp($responseHtml);
|
||||
$this->assertEquals(
|
||||
$postData,
|
||||
$responseNvp,
|
||||
'POST form should contain all params from POST request'
|
||||
);
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
$this->fail($exception->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEmpty(
|
||||
$_SESSION,
|
||||
'Session start has to be skipped for current controller'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets REQUEST_URI into request object.
|
||||
*
|
||||
* @param string $requestUri
|
||||
* @return void
|
||||
*/
|
||||
private function setRequestUri(string $requestUri)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$reflection = new \ReflectionClass($request);
|
||||
$property = $reflection->getProperty('requestUri');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($request, null);
|
||||
|
||||
$request->setServer(new Parameters(['REQUEST_URI' => $requestUri]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts HTML response to NVP structure
|
||||
*
|
||||
* @param string $response
|
||||
* @return array
|
||||
*/
|
||||
private function convertToNvp(string $response): array
|
||||
{
|
||||
$document = new \DOMDocument();
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
if (!$document->loadHTML($response)) {
|
||||
throw new \InvalidArgumentException(
|
||||
__('The response format was incorrect. Should be valid HTML')
|
||||
);
|
||||
}
|
||||
libxml_use_internal_errors(false);
|
||||
|
||||
$document->getElementsByTagName('input');
|
||||
|
||||
$convertedResponse = [];
|
||||
/** @var \DOMNode $inputNode */
|
||||
foreach ($document->getElementsByTagName('input') as $inputNode) {
|
||||
if (!$inputNode->attributes->getNamedItem('value')
|
||||
|| !$inputNode->attributes->getNamedItem('name')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
$convertedResponse[$inputNode->attributes->getNamedItem('name')->nodeValue]
|
||||
= $inputNode->attributes->getNamedItem('value')->nodeValue;
|
||||
}
|
||||
|
||||
unset($convertedResponse['form_key']);
|
||||
|
||||
return $convertedResponse;
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Controller\Transparent;
|
||||
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Intl\DateTimeFactory;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Quote\Api\PaymentMethodManagementInterface;
|
||||
|
||||
/**
|
||||
* Tests PayPal transparent response controller.
|
||||
*/
|
||||
class ResponseTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* Tests setting credit card expiration month and year to payment from PayPal response.
|
||||
*
|
||||
* @param string $currentDateTime
|
||||
* @param string $paypalExpDate
|
||||
* @param int $expectedCcMonth
|
||||
* @param int $expectedCcYear
|
||||
* @throws NoSuchEntityException
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
* @dataProvider paymentCcExpirationDateDataProvider
|
||||
*/
|
||||
public function testPaymentCcExpirationDate(
|
||||
string $currentDateTime,
|
||||
string $paypalExpDate,
|
||||
int $expectedCcMonth,
|
||||
int $expectedCcYear
|
||||
) {
|
||||
$reservedOrderId = 'test01';
|
||||
$postData = [
|
||||
'EXPDATE' => $paypalExpDate,
|
||||
'AMT' => '0.00',
|
||||
'RESPMSG' => 'Verified',
|
||||
'CVV2MATCH' => 'Y',
|
||||
'PNREF' => 'A10AAD866C87',
|
||||
'SECURETOKEN' => '3HYEHfG06skydAdBXbpIl8QJZ',
|
||||
'AVSDATA' => 'YNY',
|
||||
'RESULT' => '0',
|
||||
'IAVS' => 'N',
|
||||
'AVSADDR' => 'Y',
|
||||
'SECURETOKENID' => 'yqanLisRZbI0HAG8q3SbbKbhiwjNZAGf',
|
||||
];
|
||||
|
||||
$quote = $this->getQuote($reservedOrderId);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
/** @var Session $checkoutSession */
|
||||
$checkoutSession = $this->_objectManager->get(Session::class);
|
||||
$checkoutSession->setQuoteId($quote->getId());
|
||||
$this->setCurrentDateTime($currentDateTime);
|
||||
|
||||
$this->dispatch('paypal/transparent/response');
|
||||
|
||||
/** @var PaymentMethodManagementInterface $paymentManagment */
|
||||
$paymentManagment = $this->_objectManager->get(PaymentMethodManagementInterface::class);
|
||||
$payment = $paymentManagment->get($quote->getId());
|
||||
|
||||
$this->assertEquals($expectedCcMonth, $payment->getCcExpMonth());
|
||||
$this->assertEquals($expectedCcYear, $payment->getCcExpYear());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function paymentCcExpirationDateDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Expiration year in current century' => [
|
||||
'currentDateTime' => '2019-07-05 00:00:00',
|
||||
'paypalExpDate' => '0321',
|
||||
'expectedCcMonth' => 3,
|
||||
'expectedCcYear' => 2021
|
||||
],
|
||||
'Expiration year in next century' => [
|
||||
'currentDateTime' => '2099-01-01 00:00:00',
|
||||
'paypalExpDate' => '1002',
|
||||
'expectedCcMonth' => 10,
|
||||
'expectedCcYear' => 2102
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current date and time.
|
||||
*
|
||||
* @param string $date
|
||||
*/
|
||||
private function setCurrentDateTime(string $dateTime): void
|
||||
{
|
||||
$dateTime = new \DateTime($dateTime, new \DateTimeZone('UTC'));
|
||||
$dateTimeFactory = $this->getMockBuilder(DateTimeFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dateTimeFactory->method('create')
|
||||
->willReturn($dateTime);
|
||||
|
||||
$this->_objectManager->addSharedInstance($dateTimeFactory, DateTimeFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order ID.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return CartInterface
|
||||
*/
|
||||
private function getQuote(string $reservedOrderId): CartInterface
|
||||
{
|
||||
$searchCriteria = $this->_objectManager->get(SearchCriteriaBuilder::class)
|
||||
->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Config\Model\Config;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\Encryption\EncryptorInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var EncryptorInterface $encryptor */
|
||||
$encryptor = $objectManager->get(EncryptorInterface::class);
|
||||
|
||||
// save payment configuration for the default scope
|
||||
$configData = [
|
||||
'payment/payflowpro/partner' => 'def_partner',
|
||||
'payment/payflowpro/vendor' => 'def_vendor',
|
||||
'payment/payflowpro/user' => $encryptor->encrypt('def_user'),
|
||||
'payment/payflowpro/pwd' => $encryptor->encrypt('def_pwd'),
|
||||
];
|
||||
/** @var Config $defConfig */
|
||||
$defConfig = $objectManager->create(Config::class);
|
||||
$defConfig->setScope(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
|
||||
foreach ($configData as $key => $value) {
|
||||
$defConfig->setDataByPath($key, $value);
|
||||
$defConfig->save();
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\App\Config\Storage\WriterInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$configData = [
|
||||
'payment/payflowpro/partner',
|
||||
'payment/payflowpro/vendor',
|
||||
'payment/payflowpro/user',
|
||||
'payment/payflowpro/pwd',
|
||||
];
|
||||
/** @var WriterInterface $configWriter */
|
||||
$configWriter = $objectManager->get(WriterInterface::class);
|
||||
foreach ($configData as $path) {
|
||||
$configWriter->delete($path, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Config\Model\Config;
|
||||
use Magento\Framework\Encryption\EncryptorInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
// save payment configuration per store
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/store.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var EncryptorInterface $encryptor */
|
||||
$encryptor = $objectManager->get(EncryptorInterface::class);
|
||||
|
||||
$storeConfigData = [
|
||||
'payment/payflowpro/partner' => 'store_partner',
|
||||
'payment/payflowpro/vendor' => 'store_vendor',
|
||||
'payment/payflowpro/user' => $encryptor->encrypt('store_user'),
|
||||
'payment/payflowpro/pwd' => $encryptor->encrypt('store_pwd'),
|
||||
];
|
||||
/** @var Config $storeConfig */
|
||||
$storeConfig = $objectManager->create(Config::class);
|
||||
$storeConfig->setScope(ScopeInterface::SCOPE_STORES);
|
||||
$storeConfig->setStore('test');
|
||||
foreach ($storeConfigData as $key => $value) {
|
||||
$storeConfig->setDataByPath($key, $value);
|
||||
$storeConfig->save();
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\Config\Storage\WriterInterface;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$configData = [
|
||||
'payment/payflowpro/partner',
|
||||
'payment/payflowpro/vendor',
|
||||
'payment/payflowpro/user',
|
||||
'payment/payflowpro/pwd',
|
||||
];
|
||||
/** @var WriterInterface $configWriter */
|
||||
$configWriter = $objectManager->get(WriterInterface::class);
|
||||
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $objectManager->get(StoreRepositoryInterface::class);
|
||||
$store = $storeRepository->get('test');
|
||||
foreach ($configData as $path) {
|
||||
$configWriter->delete($path, ScopeInterface::SCOPE_STORES, (int)$store->getId());
|
||||
}
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/store_rollback.php');
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Config\Model\Config;
|
||||
use Magento\Framework\Encryption\EncryptorInterface;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
// save payment website config data
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_website_with_two_stores.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$website = $websiteRepository->get('test');
|
||||
$websiteId = $website->getCode();
|
||||
/** @var EncryptorInterface $encryptor */
|
||||
$encryptor = $objectManager->get(EncryptorInterface::class);
|
||||
$websiteConfigData = [
|
||||
'payment/payflowpro/partner' => 'website_partner',
|
||||
'payment/payflowpro/vendor' => 'website_vendor',
|
||||
'payment/payflowpro/user' => $encryptor->encrypt('website_user'),
|
||||
'payment/payflowpro/pwd' => $encryptor->encrypt('website_pwd'),
|
||||
];
|
||||
/** @var Config $websiteConfig */
|
||||
$websiteConfig = $objectManager->create(Config::class);
|
||||
$websiteConfig->setScope(ScopeInterface::SCOPE_WEBSITES);
|
||||
$websiteConfig->setWebsite($websiteId);
|
||||
foreach ($websiteConfigData as $key => $value) {
|
||||
$websiteConfig->setDataByPath($key, $value);
|
||||
$websiteConfig->save();
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\App\Config\Storage\WriterInterface;
|
||||
use Magento\Store\Api\WebsiteRepositoryInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$configData = [
|
||||
'payment/payflowpro/partner',
|
||||
'payment/payflowpro/vendor',
|
||||
'payment/payflowpro/user',
|
||||
'payment/payflowpro/pwd',
|
||||
];
|
||||
/** @var WriterInterface $configWriter */
|
||||
$configWriter = $objectManager->get(WriterInterface::class);
|
||||
/** @var WebsiteRepositoryInterface $websiteRepository */
|
||||
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
|
||||
$website = $websiteRepository->get('test');
|
||||
foreach ($configData as $path) {
|
||||
$configWriter->delete($path, ScopeInterface::SCOPE_WEBSITES, (int)$website->getId());
|
||||
}
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Store/_files/second_website_with_two_stores_rollback.php');
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Helper;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class DataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Tests if method executes without fatal error when some vault payment method is enabled.
|
||||
*
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
* @magentoConfigFixture current_store payment/payflowpro_cc_vault/active 1
|
||||
*/
|
||||
public function testGetBillingAgreementMethodsWithVaultEnabled()
|
||||
{
|
||||
/** @var Data $model */
|
||||
$model = Bootstrap::getObjectManager()->create(Data::class);
|
||||
|
||||
$this->assertEmpty($model->getBillingAgreementMethods());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model\Api;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\HTTP\Adapter\Curl;
|
||||
use Magento\Framework\HTTP\Adapter\CurlFactory;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Paypal\Model\CartFactory;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject as MockObject;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class NvpTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Nvp
|
||||
*/
|
||||
private $nvpApi;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Curl|MockObject
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var CurlFactory|MockObject $httpFactory */
|
||||
$httpFactory = $this->getMockBuilder(CurlFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->httpClient = $this->getMockBuilder(Curl::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$httpFactory->method('create')
|
||||
->willReturn($this->httpClient);
|
||||
|
||||
$this->nvpApi = $this->objectManager->create(Nvp::class, [
|
||||
'curlFactory' => $httpFactory
|
||||
]);
|
||||
|
||||
/** @var ProductMetadataInterface|MockObject $productMetadata */
|
||||
$productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
|
||||
->getMock();
|
||||
$productMetadata->method('getEdition')
|
||||
->willReturn('');
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $this->objectManager->get(Config::class);
|
||||
$config->setMethodCode(Config::METHOD_EXPRESS);
|
||||
|
||||
$refObject = new \ReflectionObject($config);
|
||||
$refProperty = $refObject->getProperty('productMetadata');
|
||||
$refProperty->setAccessible(true);
|
||||
$refProperty->setValue($config, $productMetadata);
|
||||
|
||||
$this->nvpApi->setConfigObject($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when items with FPT (Fixed Product Tax) are present in the request.
|
||||
*
|
||||
* @magentoConfigFixture current_store tax/weee/enable 1
|
||||
* @magentoConfigFixture current_store tax/weee/include_in_subtotal 0
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_with_fpt.php
|
||||
*/
|
||||
public function testRequestTotalsAndLineItemsWithFPT()
|
||||
{
|
||||
$quote = $this->getQuote('100000016');
|
||||
/** @var CartFactory $cartFactory */
|
||||
$cartFactory = $this->objectManager->get(CartFactory::class);
|
||||
$cart = $cartFactory->create(['salesModel' => $quote]);
|
||||
|
||||
$request = 'PAYMENTACTION=Authorization&AMT=112.70'
|
||||
. '&SHIPPINGAMT=0.00&ITEMAMT=112.70&TAXAMT=0.00'
|
||||
. '&L_NAME0=Simple+Product+FPT&L_QTY0=1&L_AMT0=100.00'
|
||||
. '&L_NAME1=FPT&L_QTY1=1&L_AMT1=12.70'
|
||||
. '&METHOD=SetExpressCheckout&VERSION=72.0&BUTTONSOURCE=Magento_2_';
|
||||
|
||||
$this->httpClient->method('write')
|
||||
->with(
|
||||
'POST',
|
||||
'https://api-3t.paypal.com/nvp',
|
||||
'1.1',
|
||||
[],
|
||||
$this->equalTo($request)
|
||||
);
|
||||
|
||||
$this->httpClient->method('read')
|
||||
->willReturn(
|
||||
"HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nRESULT=0&RESPMSG=Approved"
|
||||
);
|
||||
|
||||
$this->nvpApi->setAmount($quote->getBaseGrandTotal());
|
||||
$this->nvpApi->setPaypalCart($cart);
|
||||
$this->nvpApi->setQuote($quote);
|
||||
$this->nvpApi->setIsLineItemsEnabled(true);
|
||||
$this->nvpApi->callSetExpressCheckout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the refund request to Paypal sends the correct data
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_with_tax.php
|
||||
*/
|
||||
public function testCallRefundTransaction()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Payment $payment */
|
||||
$payment = $order->getPayment();
|
||||
|
||||
$this->nvpApi->setPayment(
|
||||
$payment
|
||||
)->setTransactionId(
|
||||
'fooTransactionId'
|
||||
)->setAmount(
|
||||
$payment->formatAmount($order->getBaseGrandTotal())
|
||||
)->setCurrencyCode(
|
||||
$order->getBaseCurrencyCode()
|
||||
)->setRefundType(
|
||||
Config::REFUND_TYPE_PARTIAL
|
||||
);
|
||||
|
||||
$httpQuery = 'TRANSACTIONID=fooTransactionId&REFUNDTYPE=Partial'
|
||||
.'&CURRENCYCODE=USD&AMT=145.98&METHOD=RefundTransaction'
|
||||
.'&VERSION=72.0&BUTTONSOURCE=Magento_2_';
|
||||
|
||||
$this->httpClient->expects($this->once())->method('write')
|
||||
->with(
|
||||
'POST',
|
||||
'https://api-3t.paypal.com/nvp',
|
||||
'1.1',
|
||||
[],
|
||||
$httpQuery
|
||||
);
|
||||
$this->httpClient->method('read')->willReturn('');
|
||||
|
||||
$this->nvpApi->callRefundTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote($reservedOrderId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->create(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(QuoteRepository::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model\Api;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\HTTP\Adapter\Curl;
|
||||
use Magento\Framework\HTTP\Adapter\CurlFactory;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Paypal\Model\CartFactory;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject_MockObject as MockObject;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PayflowNvpTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var PayflowNvp
|
||||
*/
|
||||
private $nvpApi;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Curl|MockObject
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var CurlFactory|MockObject $httpFactory */
|
||||
$httpFactory = $this->getMockBuilder(CurlFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->httpClient = $this->getMockBuilder(Curl::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$httpFactory->method('create')
|
||||
->willReturn($this->httpClient);
|
||||
|
||||
$this->nvpApi = $this->objectManager->create(PayflowNvp::class, [
|
||||
'curlFactory' => $httpFactory
|
||||
]);
|
||||
|
||||
/** @var ProductMetadataInterface|MockObject $productMetadata */
|
||||
$productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
|
||||
->getMock();
|
||||
$productMetadata->method('getEdition')
|
||||
->willReturn('');
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $this->objectManager->get(Config::class);
|
||||
$config->setMethodCode(Config::METHOD_WPP_PE_EXPRESS);
|
||||
|
||||
$refObject = new \ReflectionObject($config);
|
||||
$refProperty = $refObject->getProperty('productMetadata');
|
||||
$refProperty->setAccessible(true);
|
||||
$refProperty->setValue($config, $productMetadata);
|
||||
|
||||
$this->nvpApi->setConfigObject($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when items and discount are present in the request.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payflowpro.php
|
||||
* @magentoDbIsolation disabled
|
||||
*/
|
||||
public function testRequestLineItems()
|
||||
{
|
||||
$quote = $this->getQuote('100000015');
|
||||
/** @var CartFactory $cartFactory */
|
||||
$cartFactory = $this->objectManager->get(CartFactory::class);
|
||||
$cart = $cartFactory->create(['salesModel' => $quote]);
|
||||
|
||||
$request = 'TENDER=P&AMT=52.14&FREIGHTAMT=0.00&TAXAMT=0.00&'
|
||||
. 'L_NAME0=Simple 1&L_QTY0=1&L_COST0=7.69&'
|
||||
. 'L_NAME1=Simple 2&L_QTY1=2&L_COST1=9.69&'
|
||||
. 'L_NAME2=Simple 3&L_QTY2=3&L_COST2=11.69&'
|
||||
. 'L_NAME3=Discount&L_QTY3=1&L_COST3=-10.00&'
|
||||
. 'TRXTYPE=A&ACTION=S&BUTTONSOURCE=Magento_2_';
|
||||
|
||||
$this->httpClient->method('write')
|
||||
->with(
|
||||
'POST',
|
||||
'https://payflowpro.paypal.com/transaction',
|
||||
'1.1',
|
||||
['PAYPAL-NVP: Y'],
|
||||
self::equalTo($request)
|
||||
);
|
||||
|
||||
$this->httpClient->method('read')
|
||||
->willReturn("HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nRESULT=0&RESPMSG=Approved");
|
||||
|
||||
$this->nvpApi->setAmount($quote->getBaseGrandTotal());
|
||||
$this->nvpApi->setPaypalCart($cart);
|
||||
$this->nvpApi->setQuote($quote);
|
||||
$this->nvpApi->setIsLineItemsEnabled(true);
|
||||
$this->nvpApi->callSetExpressCheckout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote($reservedOrderId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->create(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(QuoteRepository::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,783 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Paypal\Model\Express;
|
||||
|
||||
use Magento\Checkout\Model\Type\Onepage;
|
||||
use Magento\Directory\Model\CountryFactory;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\Paypal\Model\Api\Type\Factory;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Paypal\Model\Info;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\ResourceModel\Quote\Collection;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class CheckoutTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Info|MockObject
|
||||
*/
|
||||
private $paypalInfo;
|
||||
|
||||
/**
|
||||
* @var Config|MockObject
|
||||
*/
|
||||
private $paypalConfig;
|
||||
|
||||
/**
|
||||
* @var Factory|MockObject
|
||||
*/
|
||||
private $apiTypeFactory;
|
||||
|
||||
/**
|
||||
* @var Nvp|MockObject
|
||||
*/
|
||||
private $api;
|
||||
|
||||
/**
|
||||
* @var Checkout
|
||||
*/
|
||||
private $checkoutModel;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->paypalInfo = $this->getMockBuilder(Info::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->paypalConfig = $this->getMockBuilder(Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->api = $this->getMockBuilder(Nvp::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['call', 'getExportedShippingAddress', 'getExportedBillingAddress', 'getShippingRateCode'])
|
||||
->getMock();
|
||||
|
||||
$this->api->expects($this->any())
|
||||
->method('call')
|
||||
->willReturn([]);
|
||||
|
||||
$this->apiTypeFactory = $this->getMockBuilder(Factory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->apiTypeFactory->expects($this->any())
|
||||
->method('create')
|
||||
->willReturn($this->api);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that api has set customer email.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_express.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testCheckoutStartWithBillingAddress()
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$paypalConfig = $this->getMockBuilder(Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$apiTypeFactory = $this->getMockBuilder(Factory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
|
||||
$paypalInfo = $this->getMockBuilder(Info::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$checkoutModel = $this->objectManager->create(
|
||||
Checkout::class,
|
||||
[
|
||||
'params' => ['quote' => $quote, 'config' => $paypalConfig],
|
||||
'apiTypeFactory' => $apiTypeFactory,
|
||||
'paypalInfo' => $paypalInfo
|
||||
]
|
||||
);
|
||||
|
||||
$api = $this->getMockBuilder(Nvp::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['callSetExpressCheckout'])
|
||||
->getMock();
|
||||
|
||||
$api->expects($this->any())
|
||||
->method('callSetExpressCheckout')
|
||||
->willReturn(null);
|
||||
|
||||
$apiTypeFactory->expects($this->any())
|
||||
->method('create')
|
||||
->willReturn($api);
|
||||
|
||||
$checkoutModel->start(
|
||||
'return',
|
||||
'cancel',
|
||||
false
|
||||
);
|
||||
|
||||
$this->assertEquals('test@com.com', $api->getBillingAddress()->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that an order placed with an existing customer can re-use the customer addresses.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_express_with_customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testPrepareCustomerQuote()
|
||||
{
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->getFixtureQuote();
|
||||
$quote->setCheckoutMethod(Onepage::METHOD_CUSTOMER); // to dive into _prepareCustomerQuote() on switch
|
||||
$quote->getShippingAddress()->setSameAsBilling(0);
|
||||
$quote->setReservedOrderId(null);
|
||||
$customer = $this->objectManager->create(\Magento\Customer\Model\Customer::class)->load(1);
|
||||
$customer->setDefaultBilling(false)
|
||||
->setDefaultShipping(false)
|
||||
->save();
|
||||
|
||||
/** @var \Magento\Customer\Model\Session $customerSession */
|
||||
$customerSession = $this->objectManager->get(\Magento\Customer\Model\Session::class);
|
||||
$customerSession->loginById(1);
|
||||
$checkout = $this->getCheckout($quote);
|
||||
$checkout->place('token');
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerService */
|
||||
$customerService = $this->objectManager->get(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $customerService->getById($quote->getCustomerId());
|
||||
|
||||
$this->assertEquals(1, $quote->getCustomerId());
|
||||
$this->assertCount(2, $customer->getAddresses());
|
||||
|
||||
$this->assertEquals(1, $quote->getBillingAddress()->getCustomerAddressId());
|
||||
$this->assertEquals(2, $quote->getShippingAddress()->getCustomerAddressId());
|
||||
|
||||
$order = $checkout->getOrder();
|
||||
$this->assertEquals(1, $order->getBillingAddress()->getCustomerAddressId());
|
||||
$this->assertEquals(2, $order->getShippingAddress()->getCustomerAddressId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that after placing the order, addresses are associated with the order and the quote is a guest quote.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_express.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @param string $accountEmail
|
||||
* @param string $expected
|
||||
* @dataProvider placeGuestQuoteDataProvider
|
||||
*/
|
||||
public function testPlaceGuestQuote($accountEmail, $expected)
|
||||
{
|
||||
/** @var Quote $quote */
|
||||
$quote = $this->getFixtureQuote();
|
||||
$quote->setCheckoutMethod(Onepage::METHOD_GUEST); // to dive into _prepareGuestQuote() on switch
|
||||
$quote->getShippingAddress()->setSameAsBilling(0);
|
||||
$quote->setReservedOrderId(null);
|
||||
|
||||
/* Simulate data returned from PayPal containing email as well
|
||||
as email entered at checkout step */
|
||||
$quote->getBillingAddress()->setEmail('paypal_account@email.com');
|
||||
$quote->getBillingAddress()->setOrigData('email', $accountEmail);
|
||||
|
||||
$checkout = $this->getCheckout($quote);
|
||||
$checkout->place('token');
|
||||
|
||||
$this->assertNull($quote->getCustomerId());
|
||||
$this->assertTrue($quote->getCustomerIsGuest());
|
||||
$this->assertEquals(
|
||||
\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
|
||||
$quote->getCustomerGroupId()
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $quote->getCustomerEmail());
|
||||
$this->assertNotEmpty($quote->getBillingAddress());
|
||||
$this->assertNotEmpty($quote->getShippingAddress());
|
||||
$this->assertEquals($quote->getBillingAddress()->getFirstname(), $quote->getCustomerFirstname());
|
||||
$this->assertEquals($quote->getBillingAddress()->getLastname(), $quote->getCustomerLastname());
|
||||
|
||||
$order = $checkout->getOrder();
|
||||
$this->assertNotEmpty($order->getBillingAddress());
|
||||
$this->assertNotEmpty($order->getShippingAddress());
|
||||
$this->assertEquals($quote->getBillingAddress()->getFirstname(), $order->getCustomerFirstname());
|
||||
$this->assertEquals($quote->getBillingAddress()->getLastname(), $order->getCustomerLastname());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function placeGuestQuoteDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'case with account email absent' => [null, 'paypal_account@email.com'],
|
||||
'case with account email present' => ['magento_account@email.com', 'magento_account@email.com'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Place the order as guest when `Automatic Assignment to Customer Group` is enabled.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_express.php
|
||||
* @magentoConfigFixture current_store customer/create_account/auto_group_assign 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPlaceGuestQuoteAutomaticAssignmentEnabled(): void
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$quote->setCheckoutMethod(Onepage::METHOD_GUEST);
|
||||
$quote->getShippingAddress()->setSameAsBilling(0);
|
||||
$quote->setReservedOrderId(null);
|
||||
|
||||
$checkout = $this->getCheckout($quote);
|
||||
$checkout->place('token');
|
||||
|
||||
$order = $checkout->getOrder();
|
||||
$this->assertNotEmpty($order->getRealOrderId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Quote $quote
|
||||
* @return Checkout
|
||||
*/
|
||||
protected function getCheckout(Quote $quote)
|
||||
{
|
||||
return $this->objectManager->create(
|
||||
Checkout::class,
|
||||
[
|
||||
'params' => [
|
||||
'config' => $this->getMockBuilder(Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock(),
|
||||
'quote' => $quote,
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that an order placed with an existing customer can re-use the customer addresses.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testReturnFromPaypal()
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->checkoutModel = $this->objectManager->create(
|
||||
Checkout::class,
|
||||
[
|
||||
'params' => ['quote' => $quote, 'config' => $this->paypalConfig],
|
||||
'apiTypeFactory' => $this->apiTypeFactory,
|
||||
'paypalInfo' => $this->paypalInfo
|
||||
]
|
||||
);
|
||||
|
||||
$prefix = 'exported';
|
||||
$exportedBillingAddress = $this->getExportedAddressFixture($quote->getBillingAddress()->getData(), $prefix);
|
||||
$this->api->expects($this->any())
|
||||
->method('getExportedBillingAddress')
|
||||
->willReturn($exportedBillingAddress);
|
||||
|
||||
$exportedShippingAddress = $this->getExportedAddressFixture($quote->getShippingAddress()->getData(), $prefix);
|
||||
$this->api->expects($this->any())
|
||||
->method('getExportedShippingAddress')
|
||||
->willReturn($exportedShippingAddress);
|
||||
|
||||
$this->paypalInfo->expects($this->once())->method('importToPayment')->with($this->api, $quote->getPayment());
|
||||
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
|
||||
|
||||
$this->checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
$this->assertStringContainsString($prefix, $billingAddress->getFirstname());
|
||||
$this->assertEquals('note', $billingAddress->getCustomerNote());
|
||||
|
||||
$shippingAddress = $quote->getShippingAddress();
|
||||
$this->assertTrue((bool)$shippingAddress->getSameAsBilling());
|
||||
$this->assertNull($shippingAddress->getPrefix());
|
||||
$this->assertNull($shippingAddress->getMiddlename());
|
||||
$this->assertNull($shippingAddress->getSuffix());
|
||||
$this->assertTrue($shippingAddress->getShouldIgnoreValidation());
|
||||
$this->assertStringContainsString('exported', $shippingAddress->getFirstname());
|
||||
$paymentAdditionalInformation = $quote->getPayment()->getAdditionalInformation();
|
||||
$this->assertArrayHasKey(Checkout::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $paymentAdditionalInformation);
|
||||
$this->assertArrayHasKey(Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID, $paymentAdditionalInformation);
|
||||
$this->assertArrayHasKey(Checkout::PAYMENT_INFO_TRANSPORT_TOKEN, $paymentAdditionalInformation);
|
||||
$this->assertTrue($quote->getPayment()->hasMethod());
|
||||
$this->assertTrue($quote->getTotalsCollectedFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
* The case when handling address data from Paypal button.
|
||||
* System's address fields are replacing from export Paypal data.
|
||||
* Billing and Shipping address are the same
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testReturnFromPaypalButton()
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$quote->getShippingAddress()->setShippingMethod('');
|
||||
|
||||
$this->prepareCheckoutModel($quote);
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
|
||||
|
||||
$this->checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$shippingAddress = $quote->getShippingAddress();
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
$exportedShippingData = $this->getExportedData()['shipping'];
|
||||
|
||||
$this->assertEquals([$exportedShippingData['street']], $shippingAddress->getStreet());
|
||||
$this->assertEquals($exportedShippingData['firstname'], $shippingAddress->getFirstname());
|
||||
$this->assertEquals($exportedShippingData['city'], $shippingAddress->getCity());
|
||||
$this->assertEquals($exportedShippingData['telephone'], $shippingAddress->getTelephone());
|
||||
$this->assertEquals($exportedShippingData['email'], $shippingAddress->getEmail());
|
||||
|
||||
$this->assertEquals('flatrate_flatrate', $shippingAddress->getShippingMethod());
|
||||
|
||||
$this->assertEquals([$exportedShippingData['street']], $billingAddress->getStreet());
|
||||
$this->assertEquals($exportedShippingData['firstname'], $billingAddress->getFirstname());
|
||||
$this->assertEquals($exportedShippingData['city'], $billingAddress->getCity());
|
||||
$this->assertEquals($exportedShippingData['telephone'], $billingAddress->getTelephone());
|
||||
$this->assertEquals($exportedShippingData['email'], $billingAddress->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* The case when handling address data from Paypal button.
|
||||
* System's address fields are replacing from export Paypal data.
|
||||
* Billing and Shipping address are different
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testReturnFromPaypalButtonWithReturnBillingAddress()
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->paypalConfig->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->with('requireBillingAddress')
|
||||
->willReturn(1);
|
||||
$this->prepareCheckoutModel($quote);
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
|
||||
|
||||
$this->checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$shippingAddress = $quote->getShippingAddress();
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
$exportedBillingData = $this->getExportedData()['billing'];
|
||||
$exportedShippingData = $this->getExportedData()['shipping'];
|
||||
|
||||
$this->assertEquals([$exportedShippingData['street']], $shippingAddress->getStreet());
|
||||
$this->assertEquals($exportedShippingData['firstname'], $shippingAddress->getFirstname());
|
||||
$this->assertEquals($exportedShippingData['city'], $shippingAddress->getCity());
|
||||
$this->assertEquals($exportedShippingData['telephone'], $shippingAddress->getTelephone());
|
||||
$this->assertEquals($exportedShippingData['email'], $shippingAddress->getEmail());
|
||||
|
||||
$this->assertEquals([$exportedBillingData['street']], $billingAddress->getStreet());
|
||||
$this->assertEquals($exportedBillingData['firstname'], $billingAddress->getFirstname());
|
||||
$this->assertEquals($exportedBillingData['city'], $billingAddress->getCity());
|
||||
$this->assertEquals($exportedBillingData['telephone'], $billingAddress->getTelephone());
|
||||
$this->assertEquals($exportedBillingData['email'], $billingAddress->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* The case when handling address data from the checkout.
|
||||
* System's address fields are not replacing from export PayPal data.
|
||||
* Billing and Shipping address are the same
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testReturnFromPaypalIfCheckout()
|
||||
{
|
||||
$prefix = 'exported';
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->prepareCheckoutModel($quote, $prefix);
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0);
|
||||
|
||||
$originalShippingAddress = $quote->getShippingAddress();
|
||||
$originalBillingAddress = $quote->getBillingAddress();
|
||||
|
||||
$this->checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$shippingAddress = $quote->getShippingAddress();
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
|
||||
$this->assertEquals($originalShippingAddress->getStreet(), $shippingAddress->getStreet());
|
||||
$this->assertEquals($originalShippingAddress->getFirstname(), $shippingAddress->getFirstname());
|
||||
$this->assertEquals($originalShippingAddress->getCity(), $shippingAddress->getCity());
|
||||
$this->assertEquals($originalShippingAddress->getTelephone(), $shippingAddress->getTelephone());
|
||||
|
||||
$this->assertEquals($originalBillingAddress->getStreet(), $billingAddress->getStreet());
|
||||
$this->assertEquals($originalBillingAddress->getFirstname(), $billingAddress->getFirstname());
|
||||
$this->assertEquals($originalBillingAddress->getCity(), $billingAddress->getCity());
|
||||
$this->assertEquals($originalBillingAddress->getTelephone(), $billingAddress->getTelephone());
|
||||
}
|
||||
|
||||
/**
|
||||
* The case when handling address data from the checkout.
|
||||
* System's address fields are replacing billing address from export PayPal data.
|
||||
* Billing and Shipping address are different
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express_with_customer.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testReturnFromPaypalIfCheckoutWithReturnBillingAddress()
|
||||
{
|
||||
$prefix = 'exported';
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->paypalConfig->expects($this->exactly(2))
|
||||
->method('getValue')
|
||||
->with('requireBillingAddress')
|
||||
->willReturn(1);
|
||||
$this->prepareCheckoutModel($quote, $prefix);
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0);
|
||||
|
||||
$originalShippingAddress = $quote->getShippingAddress();
|
||||
|
||||
$this->checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$shippingAddress = $quote->getShippingAddress();
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
$exportedBillingData = $this->getExportedData()['billing'];
|
||||
|
||||
$this->assertEquals($originalShippingAddress->getStreet(), $shippingAddress->getStreet());
|
||||
$this->assertEquals($originalShippingAddress->getFirstname(), $shippingAddress->getFirstname());
|
||||
$this->assertEquals($originalShippingAddress->getCity(), $shippingAddress->getCity());
|
||||
$this->assertEquals($originalShippingAddress->getTelephone(), $shippingAddress->getTelephone());
|
||||
|
||||
$this->assertEquals([$prefix . $exportedBillingData['street']], $billingAddress->getStreet());
|
||||
$this->assertEquals($prefix . $exportedBillingData['firstname'], $billingAddress->getFirstname());
|
||||
$this->assertEquals($prefix . $exportedBillingData['city'], $billingAddress->getCity());
|
||||
$this->assertEquals($prefix . $exportedBillingData['telephone'], $billingAddress->getTelephone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when customer doesn't have either billing or shipping addresses.
|
||||
* Customer add virtual product to quote and place order using PayPal Express method.
|
||||
* After return from PayPal quote billing address have to be updated by PayPal Express address.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/virtual_quote_with_empty_billing_address.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoDbIsolation enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReturnFromPayPalForCustomerWithEmptyAddresses(): void
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->prepareCheckoutModel($quote);
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 0);
|
||||
|
||||
$this->checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$billingAddress = $quote->getBillingAddress();
|
||||
|
||||
$this->performQuoteAddressAssertions($billingAddress, $this->getExportedData()['billing']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when customer doesn't have either billing or shipping addresses.
|
||||
* Customer add virtual product to quote and place order using PayPal Express method.
|
||||
* Default store country is in PayPal Express allowed specific country list.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/virtual_quote_with_empty_billing_address.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/allowspecific 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/specificcountry US,GB
|
||||
* @magentoConfigFixture current_store general/country/default US
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPaymentValidationWithAllowedSpecificCountry(): void
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->prepareCheckoutModel($quote);
|
||||
|
||||
$quote->getPayment()->getMethodInstance()->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case when customer doesn't have either billing or shipping addresses.
|
||||
* Customer add virtual product to quote and place order using PayPal Express method.
|
||||
* PayPal Express allowed specific country list doesn't contain default store country.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/virtual_quote_with_empty_billing_address.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/allowspecific 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/specificcountry US,GB
|
||||
* @magentoConfigFixture current_store general/country/default CA
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPaymentValidationWithAllowedSpecificCountryNegative(): void
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage(
|
||||
'You can\'t use the payment type you selected to make payments to the billing country.'
|
||||
);
|
||||
|
||||
$quote = $this->getFixtureQuote();
|
||||
$this->prepareCheckoutModel($quote);
|
||||
$quote->getPayment()->getMethodInstance()->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs quote address assertions.
|
||||
*
|
||||
* @param Address $address
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
private function performQuoteAddressAssertions(Address $address, array $expected): void
|
||||
{
|
||||
foreach ($expected as $key => $item) {
|
||||
$methodName = 'get' . ucfirst($key);
|
||||
if ($key === 'street') {
|
||||
$item = [$item];
|
||||
}
|
||||
|
||||
$this->assertEquals($item, $address->$methodName(), 'The "' . $key . '" does not match.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a checkout model mock.
|
||||
*
|
||||
* @param Quote $quote
|
||||
*/
|
||||
private function prepareCheckoutModel(Quote $quote, $prefix = '')
|
||||
{
|
||||
$this->checkoutModel = $this->objectManager->create(
|
||||
Checkout::class,
|
||||
[
|
||||
'params' => ['quote' => $quote, 'config' => $this->paypalConfig],
|
||||
'apiTypeFactory' => $this->apiTypeFactory,
|
||||
'paypalInfo' => $this->paypalInfo
|
||||
]
|
||||
);
|
||||
|
||||
$exportedBillingAddress = $this->getExportedAddressFixture($this->getExportedData()['billing'], $prefix);
|
||||
$this->api->method('getExportedBillingAddress')
|
||||
->willReturn($exportedBillingAddress);
|
||||
|
||||
$exportedShippingAddress = $this->getExportedAddressFixture($this->getExportedData()['shipping'], $prefix);
|
||||
$this->api->method('getExportedShippingAddress')
|
||||
->willReturn($exportedShippingAddress);
|
||||
|
||||
$this->api->method('getShippingRateCode')
|
||||
->willReturn('flatrate_flatrate Flat Rate - Fixed');
|
||||
|
||||
$this->paypalInfo->method('importToPayment')
|
||||
->with($this->api, $quote->getPayment());
|
||||
}
|
||||
|
||||
/**
|
||||
* A Paypal response stub.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getExportedData(): array
|
||||
{
|
||||
return [
|
||||
'shipping' => [
|
||||
'email' => 'customer@example.com',
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Doe',
|
||||
'country' => 'US',
|
||||
'region' => 'Colorado',
|
||||
'region_id' => '13',
|
||||
'city' => 'Denver',
|
||||
'street' => '66 Pearl St',
|
||||
'postcode' => '80203',
|
||||
'telephone' => '555-555-555',
|
||||
],
|
||||
'billing' => [
|
||||
'email' => 'customer@example.com',
|
||||
'firstname' => 'Jane',
|
||||
'lastname' => 'Doe',
|
||||
'country' => 'US',
|
||||
'region' => 'Texas',
|
||||
'region_id' => '13',
|
||||
'city' => 'Austin',
|
||||
'street' => '1100 Congress Ave',
|
||||
'postcode' => '78701',
|
||||
'telephone' => '555-555-555'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that guest customer quota has set type of checkout.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testGuestReturnFromPaypal()
|
||||
{
|
||||
$quote = $this->getFixtureQuote();
|
||||
$paypalConfig = $this->getMockBuilder(Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$apiTypeFactory = $this->getMockBuilder(Factory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
|
||||
$paypalInfo = $this->getMockBuilder(Info::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['importToPayment'])
|
||||
->getMock();
|
||||
|
||||
$checkoutModel = $this->objectManager->create(
|
||||
Checkout::class,
|
||||
[
|
||||
'params' => ['quote' => $quote, 'config' => $paypalConfig],
|
||||
'apiTypeFactory' => $apiTypeFactory,
|
||||
'paypalInfo' => $paypalInfo
|
||||
]
|
||||
);
|
||||
|
||||
$api = $this->getMockBuilder(Nvp::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['call', 'getExportedShippingAddress', 'getExportedBillingAddress'])
|
||||
->getMock();
|
||||
|
||||
$apiTypeFactory->expects($this->any())
|
||||
->method('create')
|
||||
->willReturn($api);
|
||||
|
||||
$exportedBillingAddress = $this->getExportedAddressFixture($quote->getBillingAddress()->getData());
|
||||
$api->expects($this->any())
|
||||
->method('getExportedBillingAddress')
|
||||
->willReturn($exportedBillingAddress);
|
||||
|
||||
$exportedShippingAddress = $this->getExportedAddressFixture($quote->getShippingAddress()->getData());
|
||||
$api->expects($this->any())
|
||||
->method('getExportedShippingAddress')
|
||||
->willReturn($exportedShippingAddress);
|
||||
|
||||
$this->addCountryFactory($api);
|
||||
$data = [
|
||||
'COUNTRYCODE' => $quote->getShippingAddress()->getCountryId(),
|
||||
'STATE' => 'unknown'
|
||||
];
|
||||
$api->method('call')
|
||||
->willReturn($data);
|
||||
|
||||
$paypalInfo->expects($this->once())
|
||||
->method('importToPayment')
|
||||
->with($api, $quote->getPayment());
|
||||
|
||||
$quote->getPayment()->setAdditionalInformation(Checkout::PAYMENT_INFO_BUTTON, 1);
|
||||
|
||||
$checkoutModel->returnFromPaypal('token');
|
||||
|
||||
$this->assertEquals(Onepage::METHOD_GUEST, $quote->getCheckoutMethod());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare fixture for exported address.
|
||||
*
|
||||
* @param array $addressData
|
||||
* @param string $prefix
|
||||
* @return \Magento\Framework\DataObject
|
||||
*/
|
||||
private function getExportedAddressFixture(array $addressData, string $prefix = ''): \Magento\Framework\DataObject
|
||||
{
|
||||
$addressDataKeys = [
|
||||
'country',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'street',
|
||||
'city',
|
||||
'telephone',
|
||||
'postcode',
|
||||
'region',
|
||||
'region_id',
|
||||
'email',
|
||||
];
|
||||
$result = [];
|
||||
foreach ($addressDataKeys as $key) {
|
||||
if (isset($addressData[$key])) {
|
||||
$result[$key] = $prefix . $addressData[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$fixture = new \Magento\Framework\DataObject($result);
|
||||
$fixture->setExportedKeys($addressDataKeys);
|
||||
$fixture->setData('note', 'note');
|
||||
|
||||
return $fixture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote.
|
||||
*
|
||||
* @return Quote
|
||||
*/
|
||||
private function getFixtureQuote(): Quote
|
||||
{
|
||||
/** @var Collection $quoteCollection */
|
||||
$quoteCollection = $this->objectManager->create(Collection::class);
|
||||
|
||||
return $quoteCollection->getLastItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds countryFactory to a mock.
|
||||
*
|
||||
* @param MockObject $api
|
||||
* @return void
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function addCountryFactory(MockObject $api): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($api);
|
||||
$property = $reflection->getProperty('_countryFactory');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($api, $this->objectManager->get(CountryFactory::class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model\Hostedpro;
|
||||
|
||||
use Magento\Paypal\Model\Hostedpro\Request;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Sales\Model\Order;
|
||||
|
||||
/**
|
||||
* Class RequestTest
|
||||
* @package Magento\Paypal\Model
|
||||
*/
|
||||
class RequestTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Paypal\Model\Hostedpro\Request
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->model = $this->objectManager->create(Request::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Paypal\Model\Hostedpro\Request::setOrder()
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_hostedpro.php
|
||||
*/
|
||||
public function testSetOrder()
|
||||
{
|
||||
$incrementId = '100000001';
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(Order::class);
|
||||
$order->loadByIncrementId($incrementId);
|
||||
|
||||
$this->model->setOrder($order);
|
||||
$addressData = require(__DIR__ . '/../../_files/address_data.php');
|
||||
static::assertEquals($incrementId, $this->model->getInvoice());
|
||||
|
||||
$this->assertAddress($addressData, 'billing');
|
||||
$this->assertAddress($addressData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert address details
|
||||
*
|
||||
* @param array $address
|
||||
* @param string $type
|
||||
*/
|
||||
protected function assertAddress(array $address, $type = '')
|
||||
{
|
||||
$type = !empty($type) ? $type . '_' : '';
|
||||
|
||||
static::assertEquals($address['firstname'], $this->model->getData($type.'first_name'));
|
||||
static::assertEquals($address['lastname'], $this->model->getData($type.'last_name'));
|
||||
static::assertEquals($address['city'], $this->model->getData($type.'city'));
|
||||
static::assertEquals($address['region'], $this->model->getData($type.'state'));
|
||||
static::assertEquals($address['country_id'], $this->model->getData($type.'country'));
|
||||
static::assertEquals($address['postcode'], $this->model->getData($type.'zip'));
|
||||
static::assertEquals($address['street'], $this->model->getData($type.'address1'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Paypal\Model\Api\Nvp;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Paypal\Model\Hostedpro;
|
||||
use Magento\Paypal\Model\Hostedpro\RequestFactory;
|
||||
use Magento\Paypal\Model\ProFactory;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class HostedproTest
|
||||
* @package Magento\Paypal\Model
|
||||
*/
|
||||
class HostedproTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Paypal\Model\Hostedpro
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var \Magento\Paypal\Model\Api\Nvp|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
private $api;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->api = $this->getMockBuilder(Nvp::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['call'])
|
||||
->getMock();
|
||||
|
||||
$proFactory = $this->getProFactory();
|
||||
|
||||
$this->model = $this->objectManager
|
||||
->create(Hostedpro::class, [
|
||||
'proFactory' => $proFactory
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\Paypal\Model\Hostedpro::initialize
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_hostedpro.php
|
||||
*/
|
||||
public function testInitialize()
|
||||
{
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $this->objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$payment = $order->getPayment();
|
||||
|
||||
$this->model->setInfoInstance($payment);
|
||||
|
||||
$this->api->expects(static::once())
|
||||
->method('call')
|
||||
->willReturn([
|
||||
'EMAILLINK' => 'https://securepayments.sandbox.paypal.com/webapps/HostedSoleSolutionApp/webflow/'
|
||||
]);
|
||||
|
||||
$state = $this->objectManager->create(DataObject::class);
|
||||
$this->model->initialize(Config::PAYMENT_ACTION_AUTH, $state);
|
||||
|
||||
static::assertEquals(Order::STATE_PENDING_PAYMENT, $state->getState());
|
||||
static::assertEquals(Order::STATE_PENDING_PAYMENT, $state->getStatus());
|
||||
static::assertFalse($state->getIsNotified());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mock for config
|
||||
* @return \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected function getConfig()
|
||||
{
|
||||
$config = $this->getMockBuilder(Config::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getValue'])
|
||||
->getMock();
|
||||
$config->expects(static::any())
|
||||
->method('getValue')
|
||||
->with('payment_action')
|
||||
->willReturn(Config::PAYMENT_ACTION_AUTH);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create mock for Pro factory
|
||||
* @return \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected function getProFactory()
|
||||
{
|
||||
$pro = $this->getMockBuilder(Pro::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['getApi', 'setMethod', 'getConfig', '__wakeup'])
|
||||
->getMock();
|
||||
|
||||
$config = $this->getConfig();
|
||||
$pro->expects(static::any())
|
||||
->method('getConfig')
|
||||
->willReturn($config);
|
||||
$pro->expects(static::any())
|
||||
->method('getApi')
|
||||
->willReturn($this->api);
|
||||
|
||||
$proFactory = $this->getMockBuilder(ProFactory::class)
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['create'])
|
||||
->getMock();
|
||||
$proFactory->expects(static::once())
|
||||
->method('create')
|
||||
->willReturn($pro);
|
||||
return $proFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Creditmemo;
|
||||
use Magento\Sales\Model\Order\Invoice;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class IpnTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currencyCode
|
||||
* @dataProvider currencyProvider
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express.php
|
||||
* @magentoConfigFixture current_store payment/paypal_direct/active 1
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/merchant_country US
|
||||
*/
|
||||
public function testProcessIpnRequestExpressCurrency($currencyCode)
|
||||
{
|
||||
$this->_processIpnRequestCurrency($currencyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refund full order amount by Paypal Express IPN message service.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_and_shipping.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/merchant_country US
|
||||
*/
|
||||
public function testProcessIpnRequestFullRefund()
|
||||
{
|
||||
$ipnData = require __DIR__ . '/../_files/ipn_refund.php';
|
||||
$ipnFactory = $this->_objectManager->create(IpnFactory::class);
|
||||
$ipnModel = $ipnFactory->create(
|
||||
[
|
||||
'data' => $ipnData,
|
||||
'curlFactory' => $this->_createMockedHttpAdapter()
|
||||
]
|
||||
);
|
||||
|
||||
$ipnModel->processIpnRequest();
|
||||
|
||||
$order = $this->_objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$creditmemoItems = $order->getCreditmemosCollection()->getItems();
|
||||
$creditmemo = current($creditmemoItems);
|
||||
|
||||
$this->assertEquals(Order::STATE_CLOSED, $order->getState()) ;
|
||||
$this->assertCount(1, $creditmemoItems);
|
||||
$this->assertEquals(Creditmemo::STATE_REFUNDED, $creditmemo->getState());
|
||||
$this->assertEquals(10, $order->getSubtotalRefunded());
|
||||
$this->assertEquals(10, $order->getBaseSubtotalRefunded());
|
||||
$this->assertEquals(20, $order->getShippingRefunded());
|
||||
$this->assertEquals(20, $order->getBaseShippingRefunded());
|
||||
$this->assertEquals(30, $order->getTotalRefunded());
|
||||
$this->assertEquals(30, $order->getBaseTotalRefunded());
|
||||
$this->assertEquals(30, $order->getTotalOnlineRefunded());
|
||||
$this->assertEmpty($order->getTotalOfflineRefunded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial refund of order amount by Paypal Express IPN message service.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_and_shipping.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/merchant_country US
|
||||
*/
|
||||
public function testProcessIpnRequestPartialRefund()
|
||||
{
|
||||
$ipnData = require __DIR__ . '/../_files/ipn_refund.php';
|
||||
|
||||
$refundAmount = -15;
|
||||
$ipnData['mc_gross'] = $refundAmount;
|
||||
|
||||
$ipnFactory = $this->_objectManager->create(IpnFactory::class);
|
||||
$ipnModel = $ipnFactory->create(
|
||||
[
|
||||
'data' => $ipnData,
|
||||
'curlFactory' => $this->_createMockedHttpAdapter()
|
||||
]
|
||||
);
|
||||
|
||||
$ipnModel->processIpnRequest();
|
||||
|
||||
$order = $this->_objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$creditmemoItems = $order->getCreditmemosCollection()->getItems();
|
||||
$comments = $order->load($order->getId())->getAllStatusHistory();
|
||||
$commentData = reset($comments);
|
||||
$commentOrigin = sprintf(
|
||||
'IPN "Refunded". Refund issued by merchant. Registered notification about refunded amount of $%d.00. '.
|
||||
'Transaction ID: "%s". Credit Memo has not been created. Please create offline Credit Memo.',
|
||||
abs($refundAmount),
|
||||
$ipnData['txn_id']
|
||||
);
|
||||
|
||||
$this->assertEquals(Order::STATE_PROCESSING, $order->getState()) ;
|
||||
$this->assertEmpty(count($creditmemoItems));
|
||||
$this->assertCount(1, $comments);
|
||||
$this->assertEquals($commentOrigin, $commentData->getComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Refund rest of order amount by Paypal Express IPN message service.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_and_shipping.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/merchant_country US
|
||||
*/
|
||||
public function testProcessIpnRequestRestRefund()
|
||||
{
|
||||
$ipnData = require __DIR__ . '/../_files/ipn_refund.php';
|
||||
|
||||
$ipnFactory = $this->_objectManager->create(IpnFactory::class);
|
||||
$ipnModel = $ipnFactory->create(
|
||||
[
|
||||
'data' => $ipnData,
|
||||
'curlFactory' => $this->_createMockedHttpAdapter()
|
||||
]
|
||||
);
|
||||
|
||||
$ipnModel->processIpnRequest();
|
||||
|
||||
$order = $this->_objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$creditmemoItems = $order->getCreditmemosCollection()->getItems();
|
||||
|
||||
$this->assertEquals(Order::STATE_CLOSED, $order->getState()) ;
|
||||
$this->assertCount(1, $creditmemoItems);
|
||||
$this->assertEquals(10, $order->getSubtotalRefunded());
|
||||
$this->assertEquals(10, $order->getBaseSubtotalRefunded());
|
||||
$this->assertEquals(20, $order->getShippingRefunded());
|
||||
$this->assertEquals(20, $order->getBaseShippingRefunded());
|
||||
$this->assertEquals(30, $order->getTotalRefunded());
|
||||
$this->assertEquals(30, $order->getBaseTotalRefunded());
|
||||
$this->assertEquals(30, $order->getTotalOnlineRefunded());
|
||||
$this->assertEmpty($order->getTotalOfflineRefunded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies canceling an order that was in payment review state by PayPal Express IPN message service.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_express_with_invoice_payment_review.php
|
||||
* @magentoConfigFixture current_store payment/paypal_express/active 1
|
||||
* @magentoConfigFixture current_store paypal/general/merchant_country US
|
||||
*/
|
||||
public function testProcessIpnRequestWithFailedStatus()
|
||||
{
|
||||
$ipnData = require __DIR__ . '/../_files/ipn_failed.php';
|
||||
|
||||
/** @var IpnFactory $ipnFactory */
|
||||
$ipnFactory = $this->_objectManager->create(IpnFactory::class);
|
||||
$ipnModel = $ipnFactory->create(
|
||||
[
|
||||
'data' => $ipnData,
|
||||
'curlFactory' => $this->_createMockedHttpAdapter()
|
||||
]
|
||||
);
|
||||
|
||||
$ipnModel->processIpnRequest();
|
||||
|
||||
$order = $this->getOrder($ipnData['invoice']);
|
||||
$invoiceItems = $order->getInvoiceCollection()
|
||||
->getItems();
|
||||
/** @var Invoice $invoice */
|
||||
$invoice = array_pop($invoiceItems);
|
||||
$invoice->getState();
|
||||
|
||||
$this->assertEquals(Order::STATE_CANCELED, $order->getState());
|
||||
$this->assertEquals(Invoice::STATE_CANCELED, $invoice->getState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processIpnRequest() currency check for paypal_express and paypal_standard payment methods
|
||||
*
|
||||
* @param string $currencyCode
|
||||
*/
|
||||
protected function _processIpnRequestCurrency($currencyCode)
|
||||
{
|
||||
$ipnData = require __DIR__ . '/../_files/ipn.php';
|
||||
$ipnData['mc_currency'] = $currencyCode;
|
||||
|
||||
/** @var $ipnFactory \Magento\Paypal\Model\IpnFactory */
|
||||
$ipnFactory = $this->_objectManager->create(\Magento\Paypal\Model\IpnFactory::class);
|
||||
|
||||
$model = $ipnFactory->create(['data' => $ipnData, 'curlFactory' => $this->_createMockedHttpAdapter()]);
|
||||
$model->processIpnRequest();
|
||||
|
||||
$order = $this->_objectManager->create(\Magento\Sales\Model\Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
$this->_assertOrder($order, $currencyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform order state and status assertions depending on currency code
|
||||
*
|
||||
* @param \Magento\Sales\Model\Order $order
|
||||
* @param string $currencyCode
|
||||
*/
|
||||
protected function _assertOrder($order, $currencyCode)
|
||||
{
|
||||
if ($currencyCode == 'USD') {
|
||||
$this->assertEquals('complete', $order->getState());
|
||||
$this->assertEquals('complete', $order->getStatus());
|
||||
} else {
|
||||
$this->assertEquals('payment_review', $order->getState());
|
||||
$this->assertEquals('fraud', $order->getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for currency check tests
|
||||
*
|
||||
* @static
|
||||
* @return array
|
||||
*/
|
||||
public static function currencyProvider()
|
||||
{
|
||||
return [['USD'], ['EUR']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocked HTTP adapter to get VERIFIED PayPal IPN postback result
|
||||
*
|
||||
* @return \Magento\Framework\HTTP\Adapter\Curl
|
||||
*/
|
||||
protected function _createMockedHttpAdapter()
|
||||
{
|
||||
$factory = $this->createPartialMock(\Magento\Framework\HTTP\Adapter\CurlFactory::class, ['create']);
|
||||
$adapter = $this->createPartialMock(\Magento\Framework\HTTP\Adapter\Curl::class, ['read', 'write']);
|
||||
|
||||
$adapter->expects($this->once())->method('read')->with()->willReturn("\nVERIFIED");
|
||||
|
||||
$adapter->expects($this->once())->method('write');
|
||||
|
||||
$factory->expects($this->once())->method('create')->with()->willReturn($adapter);
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored order.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrder(string $incrementId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->_objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter(OrderInterface::INCREMENT_ID, $incrementId)
|
||||
->create();
|
||||
|
||||
$orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class);
|
||||
$orders = $orderRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
return array_pop($orders);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Model;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Framework\App\MutableScopeConfig;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PayLaterConfigTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getStyleDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Paypal\Model\PayLaterConfig::getSectionConfig()
|
||||
*/
|
||||
public function testGetStyleConfig($systemConfig, $expectedConfig)
|
||||
{
|
||||
$this->setConfig($systemConfig);
|
||||
|
||||
/** @var PayLaterConfig $config */
|
||||
$config = Bootstrap::getObjectManager()->get(PayLaterConfig::class);
|
||||
$this->assertEquals($expectedConfig, $config->getSectionConfig('test1', PayLaterConfig::CONFIG_KEY_STYLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStyleDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test1page_stylelayout' => 'flex',
|
||||
'payment/paypal_paylater/test1page_ratio' => '20x1',
|
||||
'payment/paypal_paylater/test1page_color' => 'blue'
|
||||
],
|
||||
'expectedConfig' => [
|
||||
'data-pp-style-layout' => 'flex',
|
||||
'data-pp-style-logo-type' => null,
|
||||
'data-pp-style-logo-position' => null,
|
||||
'data-pp-style-text-color' => null,
|
||||
'data-pp-style-text-size' => null,
|
||||
'data-pp-style-color' => 'blue',
|
||||
'data-pp-style-ratio' => '20x1',
|
||||
]
|
||||
],
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test1page_stylelayout' => 'text',
|
||||
'payment/paypal_paylater/test1page_logotype' => 'primary',
|
||||
'payment/paypal_paylater/test1page_logoposition' => 'left',
|
||||
'payment/paypal_paylater/test1page_textcolor' => 'white',
|
||||
'payment/paypal_paylater/test1page_textsize' => '10'
|
||||
|
||||
],
|
||||
'expectedConfig' => [
|
||||
'data-pp-style-layout' => 'text',
|
||||
'data-pp-style-logo-type' => 'primary',
|
||||
'data-pp-style-logo-position' => 'left',
|
||||
'data-pp-style-text-color' => 'white',
|
||||
'data-pp-style-text-size' => '10',
|
||||
'data-pp-style-color' => null,
|
||||
'data-pp-style-ratio' => null,
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPositionDataProvider
|
||||
* @magentoAppIsolation enabled
|
||||
* @covers \Magento\Paypal\Model\PayLaterConfig::getSectionConfig()
|
||||
*/
|
||||
public function testGetPositionConfig($systemConfig, $expectedConfig)
|
||||
{
|
||||
$this->setConfig($systemConfig);
|
||||
|
||||
/** @var PayLaterConfig $config */
|
||||
$config = Bootstrap::getObjectManager()->get(PayLaterConfig::class);
|
||||
$this->assertEquals($expectedConfig, $config->getSectionConfig('test1', PayLaterConfig::CONFIG_KEY_POSITION));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function getPositionDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test1page_position' => 'header',
|
||||
],
|
||||
'expectedConfig' => 'header'
|
||||
],
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test1page_position' => 'sidebar',
|
||||
],
|
||||
'expectedConfig' => 'sidebar'
|
||||
],
|
||||
[
|
||||
'systemConfig' => [
|
||||
'payment/paypal_paylater/test2page_position' => 'sidebar',
|
||||
],
|
||||
'expectedConfig' => ''
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @dataProvider isEnabledDataProvider
|
||||
*/
|
||||
public function testIsEnabled($systemConfig, $expected)
|
||||
{
|
||||
$systemConfig = array_replace([
|
||||
'payment/paypal_paylater/experience_active' => 1,
|
||||
'payment/paypal_paylater/enabled' => 1,
|
||||
'payment/paypal_paylater/test1page_display' => 1
|
||||
], $systemConfig);
|
||||
|
||||
$this->setConfig($systemConfig);
|
||||
/** @var PayLaterConfig $config */
|
||||
$config = Bootstrap::getObjectManager()->get(PayLaterConfig::class);
|
||||
$this->assertEquals($expected, $config->isEnabled('test1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function isEnabledDataProvider()
|
||||
{
|
||||
$paymentPath = 'payment/%s/active';
|
||||
return [
|
||||
'PayPal Express' => [
|
||||
[sprintf($paymentPath, Config::METHOD_EXPRESS) => 1],
|
||||
true
|
||||
],
|
||||
'PayPal Express - Disabled' => [
|
||||
[sprintf($paymentPath, Config::METHOD_EXPRESS) => 0],
|
||||
false
|
||||
],
|
||||
'PayPal Express - Disabled funding' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_EXPRESS) => 1,
|
||||
'paypal/style/disable_funding_options' => 'CARD,ELV'
|
||||
],
|
||||
true
|
||||
],
|
||||
'PayPal Express - Disabled funding CREDIT' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_EXPRESS) => 1,
|
||||
'paypal/style/disable_funding_options' => 'CREDIT,CARD,ELV'
|
||||
],
|
||||
false
|
||||
],
|
||||
'PayPal Standard Bml' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_WPS_EXPRESS) => 1,
|
||||
sprintf($paymentPath, Config::METHOD_WPS_BML) => 1,
|
||||
],
|
||||
true
|
||||
],
|
||||
'PayPal Standard Bml - Disabled' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_WPS_EXPRESS) => 0,
|
||||
sprintf($paymentPath, Config::METHOD_WPS_BML) => 1,
|
||||
],
|
||||
false
|
||||
],
|
||||
'PayPal Standard Bml - Disabled PP Credit' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_WPS_EXPRESS) => 1,
|
||||
sprintf($paymentPath, Config::METHOD_WPS_BML) => 0,
|
||||
],
|
||||
false
|
||||
],
|
||||
'PayPal Bill Me Later - Express Checkout (Payflow Edition)' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_WPP_PE_EXPRESS) => 1,
|
||||
sprintf($paymentPath, Config::METHOD_WPP_PE_BML) => 1,
|
||||
],
|
||||
true
|
||||
],
|
||||
'PayPal Bill Me Later - Express Checkout (Payflow Edition) - Disabled' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_WPP_PE_EXPRESS) => 0,
|
||||
sprintf($paymentPath, Config::METHOD_WPP_PE_BML) => 1,
|
||||
],
|
||||
false
|
||||
],
|
||||
'PayPal Bill Me Later - Express Checkout (Payflow Edition) - Disabled PP Credit' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_WPP_PE_EXPRESS) => 1,
|
||||
sprintf($paymentPath, Config::METHOD_WPP_PE_BML) => 0,
|
||||
],
|
||||
false
|
||||
],
|
||||
'PayLater disabled' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_EXPRESS) => 1,
|
||||
'payment/paypal_paylater/enabled' => 0
|
||||
],
|
||||
false
|
||||
],
|
||||
'"Display" for page disabled' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_EXPRESS) => 1,
|
||||
'payment/paypal_paylater/test1page_display' => 0
|
||||
],
|
||||
false
|
||||
],
|
||||
'PayLater experience not active' => [
|
||||
[
|
||||
sprintf($paymentPath, Config::METHOD_EXPRESS) => 1,
|
||||
'payment/paypal_paylater/experience_active' => 0
|
||||
],
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set system configuration value for test
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
private function setConfig($config)
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $scopeConfig MutableScopeConfig */
|
||||
$scopeConfig = $objectManager->get(MutableScopeConfigInterface::class);
|
||||
foreach ($config as $path => $value) {
|
||||
$scopeConfig->setValue($path, $value, ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Model\Payflow\Service\Request;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Math\Random;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Store\Api\Data\StoreInterface;
|
||||
use Magento\Store\Api\StoreRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject as MockObject;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation disabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class SecureTokenTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var SecureToken
|
||||
*/
|
||||
private $service;
|
||||
|
||||
/**
|
||||
* @var Gateway|MockObject
|
||||
*/
|
||||
private $gateway;
|
||||
|
||||
/**
|
||||
* @var CartRepositoryInterface
|
||||
*/
|
||||
private $quoteRepository;
|
||||
|
||||
/**
|
||||
* @var Random|MockObject;
|
||||
*/
|
||||
private $mathRandom;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$this->gateway = $this->getMockBuilder(Gateway::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
$this->objectManager->addSharedInstance($this->gateway, Gateway::class);
|
||||
|
||||
$this->mathRandom = $this->getMockBuilder(Random::class)
|
||||
->getMock();
|
||||
|
||||
$this->service = $this->objectManager->create(
|
||||
SecureToken::class,
|
||||
[
|
||||
'mathRandom' => $this->mathRandom,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->objectManager->removeSharedInstance(Gateway::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when secure token can be obtained with credentials for the default scope.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payflowpro.php
|
||||
* @magentoDataFixture Magento/Paypal/Fixtures/default_payment_configuration.php
|
||||
* @magentoAppArea adminhtml
|
||||
* @return void
|
||||
*/
|
||||
public function testRequestToken(): void
|
||||
{
|
||||
$quote = $this->getQuote('100000015');
|
||||
$quote->setStoreId(null);
|
||||
$this->execute($quote, 'def_partner', 'def_vendor', 'def_user', 'def_pwd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when secure token can be obtained with credentials specified per store.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payflowpro.php
|
||||
* @magentoDataFixture Magento/Paypal/Fixtures/store_payment_configuration.php
|
||||
* @magentoAppArea adminhtml
|
||||
* @return void
|
||||
*/
|
||||
public function testRequestTokenWithStoreConfiguration(): void
|
||||
{
|
||||
$quote = $this->getQuote('100000015');
|
||||
$store = $this->getStore('test');
|
||||
$quote->setStoreId($store->getId());
|
||||
$this->execute($quote, 'store_partner', 'store_vendor', 'store_user', 'store_pwd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when secure token can be obtained with credentials specified per website.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/quote_payflowpro.php
|
||||
* @magentoDataFixture Magento/Paypal/Fixtures/website_payment_configuration.php
|
||||
* @magentoAppArea adminhtml
|
||||
* @return void
|
||||
*/
|
||||
public function testRequestTokenWithWebsiteConfiguration(): void
|
||||
{
|
||||
$quote = $this->getQuote('100000015');
|
||||
$store = $this->getStore('fixture_second_store');
|
||||
$quote->setStoreId($store->getId());
|
||||
$this->execute($quote, 'website_partner', 'website_vendor', 'website_user', 'website_pwd');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves secure token and perform test assertions.
|
||||
*
|
||||
* @param Quote $quote
|
||||
* @param string $expPartner
|
||||
* @param string $expVendor
|
||||
* @param string $expUser
|
||||
* @param string $expPwd
|
||||
* @return void
|
||||
*/
|
||||
private function execute(
|
||||
Quote $quote,
|
||||
string $expPartner,
|
||||
string $expVendor,
|
||||
string $expUser,
|
||||
string $expPwd
|
||||
): void {
|
||||
$secureTokenId = '31f2a7c8d257c70b1c9eb9051b90e0';
|
||||
$token = '80IgSbabyj0CtBDWHZZeQN3';
|
||||
|
||||
$this->mathRandom->method('getUniqueHash')
|
||||
->willReturn($secureTokenId);
|
||||
|
||||
$response = new DataObject([
|
||||
'result' => '0',
|
||||
'respmsg' => 'Approved',
|
||||
'securetoken' => $token,
|
||||
'securetokenid' => $secureTokenId,
|
||||
'result_code' => '0',
|
||||
]);
|
||||
$self = $this;
|
||||
$this->gateway->method('postRequest')
|
||||
/** @var DataObject $request */
|
||||
->with(self::callback(function ($request) use ($self, $expPartner, $expVendor, $expUser, $expPwd) {
|
||||
$self->performAssertion($expPartner, $request->getPartner(), '{Partner}');
|
||||
$self->performAssertion($expVendor, $request->getVendor(), '{Vendor}');
|
||||
$self->performAssertion($expUser, $request->getUser(), '{User}');
|
||||
$self->performAssertion($expPwd, $request->getPwd(), '{Password}');
|
||||
|
||||
return true;
|
||||
}))
|
||||
->willReturn($response);
|
||||
|
||||
$response = $this->service->requestToken($quote);
|
||||
$this->performAssertion($token, $response->getData('securetoken'), '{Secure Token}');
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform assertions test assertions.
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $actual
|
||||
* @param string $property
|
||||
* @return void
|
||||
*/
|
||||
private function performAssertion(string $expected, string $actual, string $property): void
|
||||
{
|
||||
self::assertEquals($expected, $actual, "$property should match.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads quote by order increment id.
|
||||
*
|
||||
* @param string $orderIncrementId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote(string $orderIncrementId): Quote
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $orderIncrementId)
|
||||
->create();
|
||||
|
||||
$items = $this->quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads store by provided code.
|
||||
*
|
||||
* @param string $code
|
||||
* @return StoreInterface
|
||||
*/
|
||||
private function getStore(string $code): StoreInterface
|
||||
{
|
||||
/** @var StoreRepositoryInterface $storeRepository */
|
||||
$storeRepository = $this->objectManager->get(StoreRepositoryInterface::class);
|
||||
return $storeRepository->get($code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Model\Payflow;
|
||||
|
||||
use Magento\Checkout\Api\PaymentInformationManagementInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Paypal\Model\Payflowpro;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Sales\Api\Data\TransactionInterface;
|
||||
use Magento\Sales\Api\OrderManagementInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Api\TransactionRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class TransparentTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var PaymentInformationManagementInterface
|
||||
*/
|
||||
private $management;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->management = $this->objectManager->get(PaymentInformationManagementInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a case when order should be placed in "Suspected Fraud" status based on account verification.
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
* @magentoConfigFixture current_store payment/payflowpro/payment_action Authorization
|
||||
* @magentoConfigFixture current_store payment/payflowpro/fmf 1
|
||||
*/
|
||||
public function testPlaceOrderSuspectedFraud(): void
|
||||
{
|
||||
$quote = $this->getQuote('test_order_1');
|
||||
$this->addFraudPayment($quote);
|
||||
$payment = $quote->getPayment();
|
||||
$pnref = $payment->getAdditionalInformation(Payflowpro::PNREF);
|
||||
|
||||
$orderId = (int)$this->management->savePaymentInformationAndPlaceOrder($quote->getId(), $payment);
|
||||
self::assertNotEmpty($orderId);
|
||||
|
||||
/** @var OrderRepositoryInterface $orderManagement */
|
||||
$orderManagement = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$order = $orderManagement->get($orderId);
|
||||
|
||||
self::assertEquals(Order::STATUS_FRAUD, $order->getStatus());
|
||||
self::assertEquals(Order::STATE_PAYMENT_REVIEW, $order->getState());
|
||||
|
||||
$transactions = $this->getPaymentTransactionList((int) $orderId);
|
||||
self::assertCount(1, $transactions, 'Only one transaction should be present.');
|
||||
|
||||
/** @var TransactionInterface $transaction */
|
||||
$transaction = array_pop($transactions);
|
||||
self::assertEquals(
|
||||
$pnref,
|
||||
$transaction->getTxnId(),
|
||||
'Authorization transaction id should be equal to PNREF.'
|
||||
);
|
||||
|
||||
self::assertStringContainsString(
|
||||
'Order is suspended as an account verification transaction is suspected to be fraudulent.',
|
||||
$this->getOrderComment($orderId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves quote by provided order ID.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return CartInterface
|
||||
*/
|
||||
private function getQuote(string $reservedOrderId): CartInterface
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
$items = $quoteRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets payment with fraud to quote.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addFraudPayment(CartInterface $quote): void
|
||||
{
|
||||
$payment = $quote->getPayment();
|
||||
$payment->setMethod(Config::METHOD_PAYFLOWPRO);
|
||||
$payment->setAdditionalInformation(Payflowpro::PNREF, 'A90A0D1B361D');
|
||||
$payment->setAdditionalInformation('result_code', Payflowpro::RESPONSE_CODE_FRAUDSERVICE_FILTER);
|
||||
$payment->setCcType('VI');
|
||||
$payment->setCcLast4('1111');
|
||||
$payment->setCcExpMonth('3');
|
||||
$payment->setCcExpYear('2025');
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of order transactions.
|
||||
*
|
||||
* @param int $orderId
|
||||
* @return TransactionInterface[]
|
||||
*/
|
||||
private function getPaymentTransactionList(int $orderId): array
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('order_id', $orderId)
|
||||
->create();
|
||||
|
||||
/** @var TransactionRepositoryInterface $transactionRepository */
|
||||
$transactionRepository = $this->objectManager->get(TransactionRepositoryInterface::class);
|
||||
return $transactionRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order comment.
|
||||
*
|
||||
* @param int $orderId
|
||||
* @return string
|
||||
*/
|
||||
private function getOrderComment(int $orderId): string
|
||||
{
|
||||
/** @var OrderManagementInterface $orderManagement */
|
||||
$orderManagement = $this->objectManager->get(OrderManagementInterface::class);
|
||||
$comments = $orderManagement->getCommentsList($orderId)->getItems();
|
||||
$comment = reset($comments);
|
||||
|
||||
return $comment ? $comment->getComment() : '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Paypal\Model;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\HTTP\LaminasClient;
|
||||
use Magento\Framework\HTTP\LaminasClientFactory;
|
||||
use Magento\Framework\Math\Random;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Payment\Model\Method\Logger;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PayflowproTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
/**
|
||||
* @var Payflowpro
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var LaminasClient
|
||||
*/
|
||||
protected $_httpClientMock;
|
||||
|
||||
/**
|
||||
* @var Gateway
|
||||
*/
|
||||
protected $gatewayMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_objectManager = Bootstrap::getObjectManager();
|
||||
$httpClientFactoryMock = $this->getMockBuilder(LaminasClientFactory::class)
|
||||
->setMethods(['create'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->_httpClientMock = $this->getMockBuilder(LaminasClient::class)->setMethods([])
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->_httpClientMock->expects($this->any())->method('setUri')->willReturnSelf();
|
||||
$this->_httpClientMock->expects($this->any())->method('setOptions')->willReturnSelf();
|
||||
$this->_httpClientMock->expects($this->any())->method('setMethod')->willReturnSelf();
|
||||
$this->_httpClientMock->expects($this->any())->method('setParameterPost')->willReturnSelf();
|
||||
$this->_httpClientMock->expects($this->any())->method('setHeaders')->willReturnSelf();
|
||||
$this->_httpClientMock->expects($this->any())->method('setUrlEncodeBody')->willReturnSelf();
|
||||
|
||||
$httpClientFactoryMock->expects($this->any())->method('create')
|
||||
->willReturn($this->_httpClientMock);
|
||||
|
||||
$mathRandomMock = $this->createMock(Random::class);
|
||||
$loggerMock = $this->createMock(Logger::class);
|
||||
$this->gatewayMock =$this->_objectManager->create(
|
||||
Gateway::class,
|
||||
[
|
||||
'httpClientFactory' => $httpClientFactoryMock,
|
||||
'mathRandom' => $mathRandomMock,
|
||||
'logger' => $loggerMock,
|
||||
]
|
||||
);
|
||||
$this->_model = $this->_objectManager->create(
|
||||
Payflowpro::class,
|
||||
['gateway' => $this->gatewayMock]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/order_paid_with_payflowpro.php
|
||||
*/
|
||||
public function testReviewPaymentNullResponce()
|
||||
{
|
||||
/** @var Order $order */
|
||||
$order = $this->_objectManager->create(Order::class);
|
||||
$order->loadByIncrementId('100000001');
|
||||
|
||||
$this->_httpClientMock->expects($this->any())->method('send')
|
||||
->willReturn(new DataObject(['body' => 'RESULTval=12&val2=34']));
|
||||
$expectedResult = ['resultval' => '12', 'val2' => '34', 'result_code' => null];
|
||||
|
||||
$this->assertEquals($expectedResult, $this->_model->acceptPayment($order->getPayment()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Paypal\Model;
|
||||
|
||||
use Magento\Framework\Api\AttributeValueFactory;
|
||||
use Magento\Framework\Api\ExtensionAttributesFactory;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Model\Context;
|
||||
use Magento\Framework\Module\ModuleListInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
|
||||
use Magento\Payment\Gateway\Command\CommandException;
|
||||
use Magento\Payment\Helper\Data;
|
||||
use Magento\Payment\Model\InfoInterface;
|
||||
use Magento\Payment\Model\Method\ConfigInterfaceFactory;
|
||||
use Magento\Payment\Model\Method\Logger;
|
||||
use Magento\Paypal\Model\Payflow\Service\Gateway;
|
||||
use Magento\Paypal\Model\Payflow\Service\Response\Handler\HandlerInterface;
|
||||
use Magento\Quote\Api\Data\PaymentMethodInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PayflowproVoidTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests PayflowPro payment void operation.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_payflowpro.php
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
*/
|
||||
public function testPaymentVoid(): void
|
||||
{
|
||||
$response = new DataObject(
|
||||
[
|
||||
'result' => '0',
|
||||
'pnref' => 'V19A3D27B61E',
|
||||
'respmsg' => 'Approved',
|
||||
'authcode' => '510PNI',
|
||||
'hostcode' => 'A',
|
||||
'request_id' => 'f930d3dc6824c1f7230c5529dc37ae5e',
|
||||
'result_code' => '0',
|
||||
]
|
||||
);
|
||||
|
||||
$order = $this->getOrder();
|
||||
$payment = $order->getPayment();
|
||||
$instance = $this->getPaymentMethodInstance($response);
|
||||
$payment->setMethodInstance($instance);
|
||||
|
||||
$this->assertTrue($order->canVoidPayment());
|
||||
|
||||
$payment->void(new DataObject());
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$orderRepository->save($order);
|
||||
|
||||
$order = $this->getOrderByIncrementId('100000001');
|
||||
$this->assertFalse($order->canVoidPayment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests canceling order with acceptable void transaction results.
|
||||
*
|
||||
* @param DataObject $response
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_payflowpro.php
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
* @dataProvider orderCancelSuccessDataProvider
|
||||
*/
|
||||
public function testOrderCancelSuccess(DataObject $response): void
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
$payment = $order->getPayment();
|
||||
$instance = $this->getPaymentMethodInstance($response);
|
||||
$payment->setMethodInstance($instance);
|
||||
$order->cancel();
|
||||
|
||||
$this->assertEquals(Order::STATE_CANCELED, $order->getState());
|
||||
$this->assertEquals(Order::STATE_CANCELED, $order->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function orderCancelSuccessDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Authorization has expired' => [
|
||||
new DataObject(
|
||||
[
|
||||
'respmsg' => 'Declined: 10601-Authorization has expired.',
|
||||
'result_code' => '10601',
|
||||
]
|
||||
)
|
||||
],
|
||||
'Authorization voided successfully' => [
|
||||
new DataObject(
|
||||
[
|
||||
'respmsg' => 'Approved',
|
||||
'result_code' => '0',
|
||||
]
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests canceling the order when got an error during transaction voiding.
|
||||
*
|
||||
* @magentoDataFixture Magento/Paypal/_files/order_payflowpro.php
|
||||
* @magentoConfigFixture current_store payment/payflowpro/active 1
|
||||
*/
|
||||
public function testOrderCancelWithVoidError(): void
|
||||
{
|
||||
$response = new DataObject(
|
||||
[
|
||||
'respmsg' => 'Declined: for some reason other then expired authorization',
|
||||
'result_code' => '111',
|
||||
]
|
||||
);
|
||||
$order = $this->getOrder();
|
||||
$payment = $order->getPayment();
|
||||
$instance = $this->getPaymentMethodInstance($response);
|
||||
$payment->setMethodInstance($instance);
|
||||
|
||||
$this->expectException(CommandException::class);
|
||||
$order->cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns prepared order.
|
||||
*
|
||||
* @return Order
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function getOrder(): Order
|
||||
{
|
||||
/** @var $order Order */
|
||||
$order = $this->getOrderByIncrementId('100000001');
|
||||
$orderItem = $this->createMock(Item::class);
|
||||
$orderItem->method('getQtyToInvoice')
|
||||
->willReturn(true);
|
||||
$order->setItems([$orderItem]);
|
||||
|
||||
$payment = $order->getPayment();
|
||||
$canVoidLookupProperty = new \ReflectionProperty(get_class($payment), '_canVoidLookup');
|
||||
$canVoidLookupProperty->setAccessible(true);
|
||||
$canVoidLookupProperty->setValue($payment, true);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns payment method instance.
|
||||
*
|
||||
* @param DataObject $response
|
||||
* @return PaymentMethodInterface
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function getPaymentMethodInstance(DataObject $response): PaymentMethodInterface
|
||||
{
|
||||
$gatewayMock = $this->createMock(Gateway::class);
|
||||
$gatewayMock->expects($this->once())
|
||||
->method('postRequest')
|
||||
->willReturn($response);
|
||||
|
||||
$configMock = $this->createMock(PayflowConfig::class);
|
||||
$configFactoryMock = $this->createPartialMock(
|
||||
ConfigInterfaceFactory::class,
|
||||
['create']
|
||||
);
|
||||
|
||||
$configFactoryMock->expects($this->once())
|
||||
->method('create')
|
||||
->willReturn($configMock);
|
||||
|
||||
$configMock->expects($this->any())
|
||||
->method('getValue')
|
||||
->willReturnMap(
|
||||
[
|
||||
['use_proxy', false],
|
||||
['sandbox_flag', '1'],
|
||||
['transaction_url_test_mode', 'https://test_transaction_url']
|
||||
]
|
||||
);
|
||||
|
||||
/** @var Payflowpro|MockObject $instance */
|
||||
$instance = $this->getMockBuilder(Payflowpro::class)
|
||||
->setMethods(['setStore', 'getInfoInstance'])
|
||||
->setConstructorArgs(
|
||||
[
|
||||
$this->objectManager->get(Context::class),
|
||||
$this->objectManager->get(Registry::class),
|
||||
$this->objectManager->get(ExtensionAttributesFactory::class),
|
||||
$this->objectManager->get(AttributeValueFactory::class),
|
||||
$this->objectManager->get(Data::class),
|
||||
$this->objectManager->get(ScopeConfigInterface::class),
|
||||
$this->objectManager->get(Logger::class),
|
||||
$this->objectManager->get(ModuleListInterface::class),
|
||||
$this->objectManager->get(TimezoneInterface::class),
|
||||
$this->objectManager->get(StoreManagerInterface::class),
|
||||
$configFactoryMock,
|
||||
$gatewayMock,
|
||||
$this->objectManager->get(HandlerInterface::class),
|
||||
null,
|
||||
null,
|
||||
[]
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
|
||||
$instance->expects($this->once())
|
||||
->method('setStore')
|
||||
->willReturnSelf();
|
||||
$paymentInfoInstance = $this->createMock(InfoInterface::class);
|
||||
$instance->method('getInfoInstance')
|
||||
->willReturn($paymentInfoInstance);
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored order.
|
||||
*
|
||||
* @param string $incrementId
|
||||
* @return OrderInterface
|
||||
*/
|
||||
private function getOrderByIncrementId(string $incrementId): OrderInterface
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter(OrderInterface::INCREMENT_ID, $incrementId)
|
||||
->create();
|
||||
|
||||
$orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
|
||||
$orders = $orderRepository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
return array_pop($orders);
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model\Payment\Method\Billing;
|
||||
|
||||
use Magento\Quote\Api\Data\PaymentInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class AbstractAgreementTest extends \Magento\TestFramework\Indexer\TestCase
|
||||
{
|
||||
/** @var \Magento\Paypal\Model\Method\Agreement */
|
||||
protected $_model;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$db = Bootstrap::getInstance()->getBootstrap()
|
||||
->getApplication()
|
||||
->getDbInstance();
|
||||
if (!$db->isDbDumpExists()) {
|
||||
throw new \LogicException('DB dump does not exist.');
|
||||
}
|
||||
$db->restoreFromDbDump();
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$config = $this->getMockBuilder(\Magento\Paypal\Model\Config::class)->disableOriginalConstructor()->getMock();
|
||||
$config->expects($this->any())->method('isMethodAvailable')->willReturn(true);
|
||||
$proMock = $this->getMockBuilder(\Magento\Paypal\Model\Pro::class)->disableOriginalConstructor()->getMock();
|
||||
$proMock->expects($this->any())->method('getConfig')->willReturn($config);
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\Method\Agreement::class,
|
||||
['data' => [$proMock]]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testIsActive()
|
||||
{
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\ResourceModel\Quote\Collection::class
|
||||
)->getFirstItem();
|
||||
$this->assertTrue($this->_model->isAvailable($quote));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testAssignData()
|
||||
{
|
||||
/** @var \Magento\Quote\Model\ResourceModel\Quote\Collection $collection */
|
||||
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\ResourceModel\Quote\Collection::class
|
||||
);
|
||||
/** @var \Magento\Quote\Model\Quote $quote */
|
||||
$quote = $collection->getFirstItem();
|
||||
|
||||
/** @var \Magento\Payment\Model\Info $info */
|
||||
$info = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Payment\Model\Info::class
|
||||
)->setQuote(
|
||||
$quote
|
||||
);
|
||||
$this->_model->setData('info_instance', $info);
|
||||
$billingAgreement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
)->getFirstItem();
|
||||
$data = new \Magento\Framework\DataObject(
|
||||
[
|
||||
PaymentInterface::KEY_ADDITIONAL_DATA => [
|
||||
AbstractAgreement::TRANSPORT_BILLING_AGREEMENT_ID => $billingAgreement->getId()
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->_model->assignData($data);
|
||||
$this->assertEquals(
|
||||
'REF-ID-TEST-678',
|
||||
$info->getAdditionalInformation(AbstractAgreement::PAYMENT_INFO_REFERENCE_ID)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* teardown
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model\Report;
|
||||
|
||||
class SettlementTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testFetchAndSave()
|
||||
{
|
||||
/** @var $model \Magento\Paypal\Model\Report\Settlement; */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\Report\Settlement::class
|
||||
);
|
||||
$connection = $this->createPartialMock(\Magento\Framework\Filesystem\Io\Sftp::class, ['rawls', 'read']);
|
||||
$filename = 'STL-00000000.00.abc.CSV';
|
||||
$connection->expects($this->once())->method('rawls')->willReturn([$filename => []]);
|
||||
$connection->expects($this->once())->method('read')->with($filename, $this->anything());
|
||||
$model->fetchAndSave($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @dataProvider createConnectionExceptionDataProvider
|
||||
*/
|
||||
public function testCreateConnectionException($config)
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
\Magento\Paypal\Model\Report\Settlement::createConnection($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $automaticMode
|
||||
* @param array $expectedResult
|
||||
*
|
||||
* @dataProvider createAutomaticModeDataProvider
|
||||
*
|
||||
* @magentoConfigFixture default_store paypal/fetch_reports/active 0
|
||||
* @magentoConfigFixture default_store paypal/fetch_reports/ftp_ip 192.168.0.1
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/active 1
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_ip 127.0.0.1
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_path /tmp
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_login login
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_password password
|
||||
* @magentoConfigFixture current_store paypal/fetch_reports/ftp_sandbox 0
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testGetSftpCredentials($automaticMode, $expectedResult)
|
||||
{
|
||||
/** @var $model \Magento\Paypal\Model\Report\Settlement; */
|
||||
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\Report\Settlement::class
|
||||
);
|
||||
|
||||
$result = $model->getSftpCredentials($automaticMode);
|
||||
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function createConnectionExceptionDataProvider()
|
||||
{
|
||||
return [
|
||||
[[]],
|
||||
[['username' => 'test', 'password' => 'test', 'path' => '/']],
|
||||
[['hostname' => 'example.com', 'password' => 'test', 'path' => '/']],
|
||||
[['hostname' => 'example.com', 'username' => 'test', 'path' => '/']],
|
||||
[['hostname' => 'example.com', 'username' => 'test', 'password' => 'test']]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function createAutomaticModeDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
true,
|
||||
[
|
||||
[
|
||||
'hostname' => '127.0.0.1',
|
||||
'path' => '/tmp',
|
||||
'username' => 'login',
|
||||
'password' => 'password',
|
||||
'sandbox' => '0'
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
false,
|
||||
[
|
||||
[
|
||||
'hostname' => '127.0.0.1',
|
||||
'path' => '/tmp',
|
||||
'username' => 'login',
|
||||
'password' => 'password',
|
||||
'sandbox' => '0'
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Paypal\Model\ResourceModel\Billing\Agreement;
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
|
||||
*/
|
||||
public function testAddCustomerDetails()
|
||||
{
|
||||
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
|
||||
$billingAgreementCollection = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection::class
|
||||
);
|
||||
|
||||
$billingAgreementCollection->addCustomerDetails();
|
||||
|
||||
$this->assertEquals(1, $billingAgreementCollection->count(), "Invalid collection items quantity.");
|
||||
/** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
|
||||
$billingAgreement = $billingAgreementCollection->getFirstItem();
|
||||
|
||||
$expectedData = [
|
||||
'customer_id' => 1,
|
||||
'method_code' => 'paypal_express',
|
||||
'reference_id' => 'REF-ID-TEST-678',
|
||||
'status' => 'active',
|
||||
'store_id' => 1,
|
||||
'agreement_label' => 'TEST',
|
||||
'customer_email' => 'customer@example.com',
|
||||
'customer_firstname' => 'John',
|
||||
'customer_lastname' => 'Smith',
|
||||
];
|
||||
foreach ($expectedData as $field => $expectedValue) {
|
||||
$this->assertEquals(
|
||||
$expectedValue,
|
||||
$billingAgreement->getData($field),
|
||||
"'{$field}' field value is invalid."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
return [
|
||||
'firstname' => 'guest',
|
||||
'lastname' => 'guest',
|
||||
'email' => 'customer@example.com',
|
||||
'street' => 'street',
|
||||
'city' => 'Los Angeles',
|
||||
'region' => 'CA',
|
||||
'postcode' => '1',
|
||||
'country_id' => 'US',
|
||||
'telephone' => '1'
|
||||
];
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
/** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
|
||||
$billingAgreement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Paypal\Model\Billing\Agreement::class
|
||||
)->setAgreementLabel(
|
||||
'TEST'
|
||||
)->setCustomerId(
|
||||
1
|
||||
)->setMethodCode(
|
||||
'paypal_express'
|
||||
)->setReferenceId(
|
||||
'REF-ID-TEST-678'
|
||||
)->setStatus(
|
||||
Magento\Paypal\Model\Billing\Agreement::STATUS_ACTIVE
|
||||
)->setStoreId(
|
||||
1
|
||||
)->save();
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\SalesRule\Api\CouponRepositoryInterface;
|
||||
use Magento\SalesRule\Api\Data\CouponInterface;
|
||||
use Magento\SalesRule\Api\Data\RuleInterface;
|
||||
use Magento\SalesRule\Api\RuleRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var RuleInterface $rule */
|
||||
$rule = $objectManager->create(RuleInterface::class);
|
||||
$rule->setName('10$ discount')
|
||||
->setIsAdvanced(true)
|
||||
->setStopRulesProcessing(false)
|
||||
->setDiscountQty(10)
|
||||
->setCustomerGroupIds([0])
|
||||
->setWebsiteIds([1])
|
||||
->setCouponType(RuleInterface::COUPON_TYPE_SPECIFIC_COUPON)
|
||||
->setSimpleAction(RuleInterface::DISCOUNT_ACTION_FIXED_AMOUNT_FOR_CART)
|
||||
->setDiscountAmount(10)
|
||||
->setIsActive(true);
|
||||
|
||||
/** @var RuleRepositoryInterface $ruleRepository */
|
||||
$ruleRepository = $objectManager->get(RuleRepositoryInterface::class);
|
||||
$rule = $ruleRepository->save($rule);
|
||||
|
||||
/** @var CouponInterface $coupon */
|
||||
$coupon = $objectManager->create(CouponInterface::class);
|
||||
$coupon->setCode('10_discount')
|
||||
->setRuleId($rule->getRuleId());
|
||||
|
||||
/** @var CouponRepositoryInterface $couponRepository */
|
||||
$couponRepository = $objectManager->get(CouponRepositoryInterface::class);
|
||||
$coupon = $couponRepository->save($coupon);
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\SalesRule\Api\Data\RuleInterface;
|
||||
use Magento\SalesRule\Api\RuleRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var RuleRepositoryInterface $ruleRepository */
|
||||
$ruleRepository = $objectManager->get(RuleRepositoryInterface::class);
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('name', '10$ discount')->create();
|
||||
$items = $ruleRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
/** @var RuleInterface $item */
|
||||
foreach ($items as $item) {
|
||||
$ruleRepository->deleteById($item->getRuleId());
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
return [
|
||||
'mc_gross' => '100.00',
|
||||
'invoice' => '100000001',
|
||||
'payment_status' => 'Completed',
|
||||
'auth_status' => 'Completed',
|
||||
'mc_currency' => 'USD',
|
||||
'receiver_email' => 'merchant_2012050718_biz@example.com'
|
||||
];
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
'invoice' => '100000002',
|
||||
'payment_status' => 'Failed',
|
||||
'receiver_email' => 'merchant_2012050718_biz@example.com',
|
||||
'parent_txn_id' => '84J11393WC835693U',
|
||||
'payer_status' => 'verified',
|
||||
'payment_type' => 'instant',
|
||||
'txn_id' => '1P566839F9694230H',
|
||||
'txn_type' => 'cart'
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
return [
|
||||
'mc_gross' => -30.00,
|
||||
'invoice' => '100000001',
|
||||
'payment_status' => 'Refunded',
|
||||
'auth_status' => 'Completed',
|
||||
'reason_code' => 'refund',
|
||||
'receiver_email' => 'merchant_2012050718_biz@example.com',
|
||||
'parent_txn_id' => '84J11393WC835693U',
|
||||
'txn_id' => '1P566839F9694230H'
|
||||
];
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$addressData = include __DIR__ . '/address_data.php';
|
||||
$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$billingAddress->setAddressType('billing');
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Payment::class
|
||||
);
|
||||
$payment->setMethod(\Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS);
|
||||
|
||||
$amount = 100;
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Magento\Sales\Model\Order::class);
|
||||
$order->setCustomerEmail('co@co.co')
|
||||
->setIncrementId('100000001')
|
||||
->setSubtotal($amount)
|
||||
->setBaseSubtotal($amount)
|
||||
->setBaseGrandTotal($amount)
|
||||
->setGrandTotal($amount)
|
||||
->setBaseCurrencyCode('USD')
|
||||
->setCustomerIsGuest(true)
|
||||
->setStoreId(1)
|
||||
->setEmailSent(true)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setPayment($payment);
|
||||
$order->save();
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Api\TransactionRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Sales\Model\Order\Payment\Transaction;
|
||||
use Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface as TransactionBuilder;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/order_express.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
/** @var Order $order */
|
||||
$order = $objectManager->get(Order::class)->loadByIncrementId('100000001');
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
/** @var TransactionBuilder $transactionBuilder */
|
||||
$transactionBuilder = $objectManager->create(TransactionBuilder::class);
|
||||
$transaction = $transactionBuilder->setPayment($order->getPayment())
|
||||
->setOrder($order)
|
||||
->setTransactionId(1)
|
||||
->build(Transaction::TYPE_ORDER);
|
||||
|
||||
$transactionRepository = $objectManager->create(TransactionRepositoryInterface::class);
|
||||
$transactionRepository->save($transaction);
|
||||
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $objectManager->create(Item::class);
|
||||
$orderItem->setProductId($product->getId())->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setRowTotalInclTax($product->getPrice());
|
||||
$orderItem->setBaseRowTotal($product->getPrice());
|
||||
$orderItem->setBaseRowTotalInclTax($product->getPrice());
|
||||
$orderItem->setBaseRowInvoiced($product->getPrice());
|
||||
$orderItem->setProductType('simple');
|
||||
|
||||
$totalAmount = $product->getPrice();
|
||||
|
||||
/** @var Order $order */
|
||||
$order->addItem($orderItem)
|
||||
->setSubtotal($totalAmount)
|
||||
->setBaseSubtotal($totalAmount)
|
||||
->setBaseGrandTotal($totalAmount)
|
||||
->setGrandTotal($totalAmount);
|
||||
|
||||
$orderRepository->save($order);
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Sales\Api\CreditmemoRepositoryInterface;
|
||||
use Magento\Sales\Model\Order\Creditmemo;
|
||||
use Magento\Sales\Model\Order\CreditmemoFactory;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/order_express_with_invoice_and_shipping.php');
|
||||
|
||||
/** @var CreditmemoFactory $creditmemoFactory */
|
||||
$creditmemoFactory = $objectManager->create(CreditmemoFactory::class);
|
||||
/** @var Creditmemo $creditmemo */
|
||||
$creditmemo = $creditmemoFactory->createByInvoice($invoice, $invoice->getData());
|
||||
|
||||
$creditmemo->setOrder($order);
|
||||
$creditmemo->setState(Creditmemo::STATE_REFUNDED);
|
||||
$creditmemo->setIncrementId('100000001');
|
||||
$creditmemo->setGrandTotal($itemsAmount);
|
||||
|
||||
/** @var CreditmemoRepositoryInterface $creditMemoRepository */
|
||||
$creditMemoRepository = $objectManager->get(CreditmemoRepositoryInterface::class);
|
||||
$creditMemoRepository->save($creditmemo);
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\DB\Transaction;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Sales\Api\InvoiceManagementInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Sales\Model\Order\Address;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Sales\Model\Service\InvoiceService;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
$addressData = include __DIR__ . '/address_data.php';
|
||||
$billingAddress = $objectManager->create(
|
||||
Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$billingAddress->setAddressType('billing');
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$payment = $objectManager->create(Payment::class);
|
||||
$payment->setMethod(Config::METHOD_WPP_EXPRESS);
|
||||
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $objectManager->create(Item::class);
|
||||
$orderItem->setProductId($product->getId())->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setRowTotalInclTax($product->getPrice());
|
||||
$orderItem->setBaseRowTotal($product->getPrice());
|
||||
$orderItem->setBaseRowTotalInclTax($product->getPrice());
|
||||
$orderItem->setBaseRowInvoiced($product->getPrice());
|
||||
$orderItem->setProductType('simple');
|
||||
|
||||
$itemsAmount = $product->getPrice();
|
||||
$shippingAmount = 20;
|
||||
$totalAmount = $itemsAmount + $shippingAmount;
|
||||
|
||||
/** @var Order $order */
|
||||
$order = $objectManager->create(Order::class);
|
||||
$order->setCustomerEmail('co@co.co')
|
||||
->setIncrementId('100000001')
|
||||
->addItem($orderItem)
|
||||
->setSubtotal($itemsAmount)
|
||||
->setBaseSubtotal($itemsAmount)
|
||||
->setBaseGrandTotal($totalAmount)
|
||||
->setGrandTotal($totalAmount)
|
||||
->setBaseCurrencyCode('USD')
|
||||
->setCustomerIsGuest(true)
|
||||
->setStoreId(1)
|
||||
->setEmailSent(true)
|
||||
->setState(Order::STATE_PROCESSING)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setBaseTotalPaid($totalAmount)
|
||||
->setTotalPaid($totalAmount)
|
||||
->setData('base_to_global_rate', 1)
|
||||
->setData('base_to_order_rate', 1)
|
||||
->setData('shipping_amount', $shippingAmount)
|
||||
->setData('base_shipping_amount', $shippingAmount)
|
||||
->setPayment($payment);
|
||||
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
$orderRepository->save($order);
|
||||
|
||||
/** @var InvoiceService $invoiceService */
|
||||
$invoiceService = $objectManager->create(InvoiceManagementInterface::class);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $objectManager->create(Transaction::class);
|
||||
|
||||
$invoice = $invoiceService->prepareInvoice($order, [$orderItem->getId() => 1]);
|
||||
$invoice->register();
|
||||
|
||||
$transaction->addObject($invoice)->addObject($order)->save();
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\DB\Transaction;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Sales\Api\InvoiceManagementInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Magento\Sales\Model\Order\Address;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Sales\Model\Service\InvoiceService;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
$addressData = include __DIR__ . '/address_data.php';
|
||||
$billingAddress = $objectManager->create(
|
||||
Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$billingAddress->setAddressType('billing');
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$payment = $objectManager->create(Payment::class);
|
||||
$payment->setMethod(Config::METHOD_WPP_EXPRESS);
|
||||
|
||||
/** @var Item $orderItem */
|
||||
$orderItem = $objectManager->create(Item::class);
|
||||
$orderItem->setProductId($product->getId())->setQtyOrdered(1);
|
||||
$orderItem->setBasePrice($product->getPrice());
|
||||
$orderItem->setPrice($product->getPrice());
|
||||
$orderItem->setRowTotal($product->getPrice());
|
||||
$orderItem->setRowTotalInclTax($product->getPrice());
|
||||
$orderItem->setBaseRowTotal($product->getPrice());
|
||||
$orderItem->setBaseRowTotalInclTax($product->getPrice());
|
||||
$orderItem->setBaseRowInvoiced($product->getPrice());
|
||||
$orderItem->setProductType('simple');
|
||||
|
||||
$itemsAmount = $product->getPrice();
|
||||
$shippingAmount = 20;
|
||||
$totalAmount = $itemsAmount + $shippingAmount;
|
||||
|
||||
/** @var Order $order */
|
||||
$order = $objectManager->create(Order::class);
|
||||
$order->setCustomerEmail('co@co.co')
|
||||
->setIncrementId('100000002')
|
||||
->addItem($orderItem)
|
||||
->setSubtotal($itemsAmount)
|
||||
->setBaseSubtotal($itemsAmount)
|
||||
->setBaseGrandTotal($totalAmount)
|
||||
->setGrandTotal($totalAmount)
|
||||
->setBaseCurrencyCode('USD')
|
||||
->setCustomerIsGuest(true)
|
||||
->setStoreId(1)
|
||||
->setEmailSent(true)
|
||||
->setState(Order::STATE_PAYMENT_REVIEW)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setBaseTotalPaid($totalAmount)
|
||||
->setTotalPaid($totalAmount)
|
||||
->setData('base_to_global_rate', 1)
|
||||
->setData('base_to_order_rate', 1)
|
||||
->setData('shipping_amount', $shippingAmount)
|
||||
->setData('base_shipping_amount', $shippingAmount)
|
||||
->setPayment($payment);
|
||||
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
$orderRepository->save($order);
|
||||
|
||||
/** @var InvoiceService $invoiceService */
|
||||
$invoiceService = $objectManager->create(InvoiceManagementInterface::class);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $objectManager->create(Transaction::class);
|
||||
|
||||
$invoice = $invoiceService->prepareInvoice($order, [$orderItem->getId() => 1]);
|
||||
$invoice->register();
|
||||
|
||||
$transaction->addObject($invoice)->addObject($order)->save();
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterfaceFactory;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\OrderRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/order_express.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$order = $objectManager->get(OrderInterfaceFactory::class)->create()->loadByIncrementId('100000001');
|
||||
$subTotal = 121;
|
||||
$taxRate = .0825;
|
||||
$taxAmount = $subTotal * $taxRate;
|
||||
$shippingAmount = 15;
|
||||
$totalAmount = $subTotal + $taxAmount + $shippingAmount;
|
||||
|
||||
$order->setSubtotal($subTotal);
|
||||
$order->setBaseSubtotal($subTotal);
|
||||
$order->setGrandTotal($totalAmount);
|
||||
$order->setBaseGrandTotal($totalAmount);
|
||||
$order->setTaxAmount($taxAmount);
|
||||
|
||||
/** @var OrderRepository $orderRepository */
|
||||
$orderRepository = $objectManager->get(OrderRepository::class);
|
||||
$orderRepository->save($order);
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Address;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$addressData = require(__DIR__ . '/address_data.php');
|
||||
$objManager = Bootstrap::getObjectManager();
|
||||
|
||||
$billingAddress = $objManager
|
||||
->create(Address::class, ['data' => $addressData])
|
||||
->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)
|
||||
->setAddressType('shipping');
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Payment $payment */
|
||||
$payment = $objManager->create(Payment::class);
|
||||
$payment->setMethod(Config::METHOD_HOSTEDPRO);
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $objManager->create(Order::class);
|
||||
$order->setCustomerEmail('wpphs.co@co.com')
|
||||
->setIncrementId('100000001')
|
||||
->setSubtotal(100)
|
||||
->setBaseSubtotal(100)
|
||||
->setBaseGrandTotal(100)
|
||||
->setBaseCurrencyCode('USD')
|
||||
->setCustomerIsGuest(true)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setPayment($payment);
|
||||
|
||||
$order->save();
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Api\Data\CartInterface;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Store\Api\Data\StoreInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var StoreInterface $store */
|
||||
$store = $objManager->get(StoreManagerInterface::class)
|
||||
->getStore();
|
||||
|
||||
/** @var CartInterface $quote */
|
||||
$quote = $objManager->create(CartInterface::class);
|
||||
$quote->setReservedOrderId('000000045')
|
||||
->setStoreId($store->getId());
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objManager->get(CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
|
||||
/** @var Payment $payment */
|
||||
$payment = $objManager->create(Payment::class);
|
||||
$payment->setMethod(Config::METHOD_PAYFLOWLINK)
|
||||
->setBaseAmountAuthorized(100)
|
||||
->setAdditionalInformation(
|
||||
[
|
||||
'secure_silent_post_hash' => 'cf7i85d01ed7c92223031afb4rdl2f1f'
|
||||
]
|
||||
);
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
$order = $objManager->create(OrderInterface::class);
|
||||
$order->setIncrementId('000000045')
|
||||
->setBaseGrandTotal(100)
|
||||
->setQuoteId($quote->getId())
|
||||
->setStoreId($store->getId())
|
||||
->setState(Order::STATE_PENDING_PAYMENT)
|
||||
->setPayment($payment);
|
||||
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $objManager->get(OrderRepositoryInterface::class);
|
||||
$orderRepository->save($order);
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\Sales\Api\Data\OrderInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Store\Api\Data\StoreInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/guest/create_empty_cart.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/PaypalGraphQl/_files/add_simple_product_payflowLink.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/guest/set_guest_email.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/set_new_shipping_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/set_new_billing_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php');
|
||||
|
||||
$objManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\UrlInterface $url */
|
||||
$url = $objManager->get(\Magento\Framework\UrlInterface::class);
|
||||
$baseUrl = $url->getBaseUrl();
|
||||
|
||||
/** @var StoreInterface $store */
|
||||
$store = $objManager->get(StoreManagerInterface::class)
|
||||
->getStore();
|
||||
|
||||
/** @var \Magento\Quote\Model\QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(\Magento\Quote\Model\QuoteFactory::class);
|
||||
/** @var CartRepositoryInterface $cartRepository */
|
||||
$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
|
||||
$quote->setStoreId($store->getId());
|
||||
$cartRepository->save($quote);
|
||||
|
||||
/** @var Payment $payment */
|
||||
$payment = $objManager->create(Payment::class);
|
||||
$payment->setMethod(Config::METHOD_PAYFLOWLINK)
|
||||
->setBaseAmountAuthorized(30)
|
||||
->setAdditionalInformation(
|
||||
[
|
||||
'cancel_url'=> $baseUrl . 'paypal/payflow/cancelPayment',
|
||||
'return_url'=> $baseUrl . 'paypal/payflow/returnUrl',
|
||||
'secure_token_id' => 'mysecuretokenId',
|
||||
'secure_token' => 'mysecuretoken'
|
||||
]
|
||||
);
|
||||
|
||||
/** @var OrderInterface $order */
|
||||
$order = $objManager->create(OrderInterface::class);
|
||||
$order->setIncrementId('test_quote')
|
||||
->setBaseGrandTotal(30)
|
||||
->setQuoteId($quote->getId())
|
||||
->setStoreId($store->getId())
|
||||
->setState(Order::STATE_PENDING_PAYMENT)
|
||||
->setStatus(Order::STATE_PENDING_PAYMENT)
|
||||
->setPayment($payment);
|
||||
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $objManager->get(OrderRepositoryInterface::class);
|
||||
$orderRepository->save($order);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Collection;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Framework\Registry $registry */
|
||||
$registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
/** @var $order \Magento\Sales\Model\Order */
|
||||
$orderCollection = $objectManager->create(Collection::class);
|
||||
foreach ($orderCollection as $order) {
|
||||
$order->delete();
|
||||
}
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$addressData = include __DIR__ . '/address_data.php';
|
||||
$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Address::class,
|
||||
['data' => $addressData]
|
||||
);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
|
||||
$payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Payment::class
|
||||
);
|
||||
$payment->setMethod(\Magento\Paypal\Model\Config::METHOD_PAYFLOWPRO);
|
||||
|
||||
$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
|
||||
$order->setCustomerEmail('co@co.co')
|
||||
->setIncrementId('100000001')
|
||||
->setSubtotal(100)
|
||||
->setBaseSubtotal(100)
|
||||
->setBaseGrandTotal(100)
|
||||
->setBaseCurrencyCode('USD')
|
||||
->setCustomerIsGuest(true)
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->setPayment($payment);
|
||||
$order->save();
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
|
||||
)->setValue(
|
||||
'carriers/flatrate/active',
|
||||
1,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
|
||||
)->setValue(
|
||||
'payment/paypal_express/active',
|
||||
1,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('simple')
|
||||
->setId(1)
|
||||
->setAttributeSetId(4)
|
||||
->setName('Simple Product')
|
||||
->setSku('simple')
|
||||
->setPrice(10)
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->setStockData(
|
||||
[
|
||||
'qty' => 100,
|
||||
'is_in_stock' => 1,
|
||||
'manage_stock' => 1,
|
||||
]
|
||||
)->save();
|
||||
$product->load(1);
|
||||
|
||||
$billingData = [
|
||||
'firstname' => 'testname',
|
||||
'lastname' => 'lastname',
|
||||
'company' => '',
|
||||
'email' => 'test@com.com',
|
||||
'street' => [
|
||||
0 => 'test1',
|
||||
1 => '',
|
||||
],
|
||||
'city' => 'Test',
|
||||
'region_id' => '1',
|
||||
'region' => '',
|
||||
'postcode' => '9001',
|
||||
'country_id' => 'US',
|
||||
'telephone' => '11111111',
|
||||
'fax' => '',
|
||||
'confirm_password' => '',
|
||||
'save_in_address_book' => '1',
|
||||
'use_for_shipping' => '1',
|
||||
];
|
||||
|
||||
$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Model\Quote\Address::class, ['data' => $billingData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
$shippingAddress->setShippingMethod('flatrate_flatrate');
|
||||
$shippingAddress->setCollectShippingRates(true);
|
||||
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setCustomerIsGuest(
|
||||
true
|
||||
)->setStoreId(
|
||||
$objectManager->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setReservedOrderId(
|
||||
'100000002'
|
||||
)->setBillingAddress(
|
||||
$billingAddress
|
||||
)->setShippingAddress(
|
||||
$shippingAddress
|
||||
)->addProduct(
|
||||
$product,
|
||||
10
|
||||
);
|
||||
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
|
||||
$quote->getShippingAddress()->setCollectShippingRates(true);
|
||||
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);
|
||||
|
||||
$quoteRepository = $objectManager->get(\Magento\Quote\Api\CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
$quote = $quoteRepository->get($quote->getId());
|
||||
$quote->setCustomerEmail('admin@example.com');
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Checkout\Model\Cart;
|
||||
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\Quote\Address\Rate;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/ConfigurableProduct/_files/product_configurable.php');
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('configurable');
|
||||
/** @var \Magento\Eav\Model\Config $eavConfig */
|
||||
$eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
|
||||
$attribute = $eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'test_configurable');
|
||||
/** @var $options Collection */
|
||||
$options = $objectManager->create(Collection::class);
|
||||
$option = $options->setAttributeFilter($attribute->getId())->getFirstItem();
|
||||
|
||||
$requestInfo = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'product' => 1,
|
||||
'selected_configurable_option' => 1,
|
||||
'qty' => 100,
|
||||
'super_attribute' => [
|
||||
$attribute->getId() => $option->getId()
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
/** @var $cart Cart */
|
||||
$cart = $objectManager->create(Cart::class);
|
||||
$cart->addProduct($product, $requestInfo);
|
||||
|
||||
/** @var $rate Rate */
|
||||
$rate = $objectManager->create(Rate::class);
|
||||
$rate->setCode('flatrate_flatrate');
|
||||
$rate->setPrice(1);
|
||||
|
||||
$addressData = include __DIR__ . '/address_data.php';
|
||||
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)
|
||||
->setAddressType('shipping')
|
||||
->setShippingMethod('flatrate_flatrate')
|
||||
->addShippingRate($rate);
|
||||
|
||||
$cart->getQuote()
|
||||
->setReservedOrderId('test_cart_with_configurable')
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress);
|
||||
|
||||
$cart->save();
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_two_addresses.php');
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$objectManager->get(
|
||||
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
|
||||
)->setValue('carriers/flatrate/active', 1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
|
||||
$objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
|
||||
->setValue('payment/paypal_express/active', 1, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
|
||||
|
||||
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->getById(1);
|
||||
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId('simple')
|
||||
->setId(1)
|
||||
->setAttributeSetId(4)
|
||||
->setName('Simple Product')
|
||||
->setSku('simple')
|
||||
->setPrice(10)
|
||||
->setStockData([
|
||||
'use_config_manage_stock' => 1,
|
||||
'qty' => 100,
|
||||
'is_qty_decimal' => 0,
|
||||
'is_in_stock' => 100,
|
||||
])
|
||||
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
|
||||
->save();
|
||||
$product->load(1);
|
||||
|
||||
$customerBillingAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
|
||||
$customerBillingAddress->load(1);
|
||||
$billingAddressDataObject = $customerBillingAddress->getDataModel();
|
||||
$billingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
|
||||
$billingAddress->importCustomerAddressData($billingAddressDataObject);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
/** @var \Magento\Customer\Model\Address $customerShippingAddress */
|
||||
$customerShippingAddress = $objectManager->create(\Magento\Customer\Model\Address::class);
|
||||
$customerShippingAddress->load(2);
|
||||
$shippingAddressDataObject = $customerShippingAddress->getDataModel();
|
||||
$shippingAddress = $objectManager->create(\Magento\Quote\Model\Quote\Address::class);
|
||||
$shippingAddress->importCustomerAddressData($shippingAddressDataObject);
|
||||
$shippingAddress->setAddressType('shipping');
|
||||
|
||||
$shippingAddress->setShippingMethod('flatrate_flatrate');
|
||||
$shippingAddress->setCollectShippingRates(true);
|
||||
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = $objectManager->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setCustomerIsGuest(false)
|
||||
->setCustomerId($customer->getId())
|
||||
->setCustomer($customer)
|
||||
->setStoreId($objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId())
|
||||
->setReservedOrderId('test02')
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress)
|
||||
->addProduct($product, 10);
|
||||
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
|
||||
$quote->getShippingAddress()->setCollectShippingRates(true);
|
||||
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);
|
||||
|
||||
/** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->create(\Magento\Quote\Api\CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
$quote = $quoteRepository->get($quote->getId());
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Sales\Model\Order\Payment;
|
||||
use Magento\Paypal\Model\Config;
|
||||
use Magento\Sales\Model\Order;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/guest/create_empty_cart.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/PaypalGraphQl/_files/add_simple_product_payflowLink.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/guest/set_guest_email.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/set_new_shipping_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/set_new_billing_address.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
$store = $objectManager->get(StoreManagerInterface::class)->getStore();
|
||||
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test_quote', 'reserved_order_id');
|
||||
|
||||
/** @var \Magento\Sales\Model\Order\Payment $payment */
|
||||
$payment = $objectManager->create(Payment::class);
|
||||
$payment->setMethod(Config::METHOD_HOSTEDPRO)
|
||||
->setBaseAmountAuthorized(30)
|
||||
->setAdditionalInformation('secure_form_url', 'https://hostedpro.paypal.com');
|
||||
|
||||
/** @var \Magento\Sales\Model\Order $order */
|
||||
$order = $objectManager->create(Order::class);
|
||||
$order->setCustomerEmail('wpphs.co@co.com')
|
||||
->setIncrementId('100000017')
|
||||
->setQuoteId($quote->getId())
|
||||
->setStoreId($store->getId())
|
||||
->setState(Order::STATE_PENDING_PAYMENT)
|
||||
->setStatus(Order::STATE_PENDING_PAYMENT)
|
||||
->setCustomerIsGuest(true)
|
||||
->setPayment($payment);
|
||||
|
||||
/** @var OrderRepositoryInterface $orderRepository */
|
||||
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
|
||||
$orderRepository->save($order);
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\SalesRule\Model\ResourceModel\Coupon\Collection;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/fixed_discount.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$addressData = [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Doe',
|
||||
'company' => '',
|
||||
'email' => 'test@com.com',
|
||||
'street' => [
|
||||
0 => 'test1',
|
||||
],
|
||||
'city' => 'Test',
|
||||
'region_id' => '1',
|
||||
'region' => '',
|
||||
'postcode' => '9001',
|
||||
'country_id' => 'US',
|
||||
'telephone' => '11111111',
|
||||
];
|
||||
/** @var Address $billingAddress */
|
||||
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setAddressType('shipping')
|
||||
->setId(null);
|
||||
|
||||
/** @var Quote $quote */
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$quote->setCustomerIsGuest(true)
|
||||
->setReservedOrderId('100000015')
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress);
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
/** @var ProductInterface $product */
|
||||
$product = $objectManager->create(ProductInterface::class);
|
||||
$product->setTypeId('simple')
|
||||
->setName('Simple ' . $i)
|
||||
->setSku('simple' . $i)
|
||||
->setAttributeSetId(4)
|
||||
->setPrice(5.69 + $i * 2)
|
||||
->setWeight(1);
|
||||
|
||||
/** @var StockItemInterface $stockItem */
|
||||
$stockItem = $objectManager->create(StockItemInterface::class);
|
||||
$stockItem->setQty(10)
|
||||
->setIsInStock(true);
|
||||
$extensionAttributes = $product->getExtensionAttributes();
|
||||
$extensionAttributes->setStockItem($stockItem);
|
||||
|
||||
$item = $productRepository->save($product);
|
||||
$quote->addProduct($item, $i);
|
||||
}
|
||||
|
||||
$quote->setCouponCode('10_discount');
|
||||
$quote->collectTotals();
|
||||
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(QuoteRepository::class);
|
||||
$quoteRepository->save($quote);
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/fixed_discount_rollback.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var SearchCriteriaBuilder $productSearchCriteriaBuilder */
|
||||
$productSearchCriteriaBuilder = $objectManager->create(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $productSearchCriteriaBuilder->addFilter('sku', ['simple1', 'simple2', 'simple3'], 'in')
|
||||
->create();
|
||||
$productList = $productRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', true);
|
||||
|
||||
if (!empty($productList)) {
|
||||
foreach ($productList as $product) {
|
||||
$productRepository->delete($product);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $objectManager->create(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', '100000015')->create();
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
if (!empty($items)) {
|
||||
$quote = array_pop($items);
|
||||
$quoteRepository->delete($quote);
|
||||
}
|
||||
|
||||
$registry->unregister('isSecureArea');
|
||||
$registry->register('isSecureArea', false);
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->load('test01', 'reserved_order_id');
|
||||
|
||||
$payment = $quote->getPayment();
|
||||
$payment->setMethod(\Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS)
|
||||
->setAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID, 123);
|
||||
$quote->collectTotals()->save();
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/quote_express.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var Quote $quote */
|
||||
$quote = $objectManager->get(QuoteFactory::class)->create();
|
||||
$quote->load('100000002', 'reserved_order_id');
|
||||
$quote->setCustomerEmail('admin@example.com');
|
||||
/** @var $service \Magento\Quote\Api\CartManagementInterface */
|
||||
$service = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Api\CartManagementInterface::class);
|
||||
$order = $service->submit($quote, ['increment_id' => '100000002']);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
use Magento\Quote\Model\QuoteFactory;
|
||||
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Paypal/_files/quote_express_with_customer.php');
|
||||
|
||||
/** @var QuoteFactory $quoteFactory */
|
||||
$quoteFactory = Bootstrap::getObjectManager()->get(QuoteFactory::class);
|
||||
/** @var QuoteResource $quoteResource */
|
||||
$quoteResource = Bootstrap::getObjectManager()->get(QuoteResource::class);
|
||||
$quote = $quoteFactory->create();
|
||||
$quoteResource->load($quote, 'test02', 'reserved_order_id');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var $service \Magento\Quote\Api\CartManagementInterface */
|
||||
$service = $objectManager->create(\Magento\Quote\Api\CartManagementInterface::class);
|
||||
$order = $service->submit($quote, ['increment_id' => '100000002']);
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('adminhtml');
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
|
||||
)->setValue(
|
||||
'carriers/flatrate/active',
|
||||
1,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
/** @var $product \Magento\Catalog\Model\Product */
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
'simple'
|
||||
)->setId(
|
||||
1
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'Simple Product'
|
||||
)->setSku(
|
||||
'simple'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setStockData(
|
||||
['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 100]
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->save();
|
||||
$product->load(1);
|
||||
|
||||
$addressData = [
|
||||
'region' => 'CA',
|
||||
'postcode' => '11111',
|
||||
'lastname' => 'lastname',
|
||||
'firstname' => 'firstname',
|
||||
'street' => 'street',
|
||||
'city' => 'Los Angeles',
|
||||
'email' => 'admin@example.com',
|
||||
'telephone' => '11111111',
|
||||
'country_id' => 'US',
|
||||
];
|
||||
|
||||
$billingData = [
|
||||
'address_id' => '',
|
||||
'firstname' => 'testname',
|
||||
'lastname' => 'lastname',
|
||||
'company' => '',
|
||||
'email' => 'test@com.com',
|
||||
'street' => [0 => 'test1', 1 => ''],
|
||||
'city' => 'Test',
|
||||
'region_id' => '1',
|
||||
'region' => '',
|
||||
'postcode' => '9001',
|
||||
'country_id' => 'US',
|
||||
'telephone' => '11111111',
|
||||
'fax' => '',
|
||||
'confirm_password' => '',
|
||||
'save_in_address_book' => '1',
|
||||
'use_for_shipping' => '1',
|
||||
];
|
||||
|
||||
$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Quote\Model\Quote\Address::class,
|
||||
['data' => $billingData]
|
||||
);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setId(null)->setAddressType('shipping');
|
||||
$shippingAddress->setShippingMethod('flatrate_flatrate');
|
||||
$shippingAddress->setCollectShippingRates(true);
|
||||
|
||||
/** @var $quote \Magento\Quote\Model\Quote */
|
||||
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
|
||||
$quote->setCustomerIsGuest(
|
||||
true
|
||||
)->setStoreId(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setReservedOrderId(
|
||||
'test02'
|
||||
)->setBillingAddress(
|
||||
$billingAddress
|
||||
)->setShippingAddress(
|
||||
$shippingAddress
|
||||
)->addProduct(
|
||||
$product,
|
||||
10
|
||||
);
|
||||
$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate');
|
||||
$quote->getShippingAddress()->setCollectShippingRates(true);
|
||||
$quote->collectTotals()->save();
|
||||
|
||||
$payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Sales\Model\Order\Payment::class
|
||||
);
|
||||
$payment->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS);
|
||||
|
||||
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_WPS_EXPRESS)->save();
|
||||
|
||||
/** @var $service \Magento\Quote\Api\CartManagementInterface */
|
||||
$service = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Quote\Api\CartManagementInterface::class);
|
||||
$order = $service->submit($quote, ['increment_id' => '100000001']);
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\QuoteRepository;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Weee/_files/product_with_fpt.php');
|
||||
|
||||
/** @var ObjectManagerInterface $objectManager */
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple-with-ftp');
|
||||
$addressData = [
|
||||
'firstname' => 'John',
|
||||
'lastname' => 'Doe',
|
||||
'company' => '',
|
||||
'email' => 'test@com.com',
|
||||
'street' => [
|
||||
0 => 'test1',
|
||||
],
|
||||
'city' => 'Test',
|
||||
'region_id' => '1',
|
||||
'region' => '',
|
||||
'postcode' => '9001',
|
||||
'country_id' => 'US',
|
||||
'telephone' => '11111111',
|
||||
];
|
||||
/** @var Address $billingAddress */
|
||||
$billingAddress = $objectManager->create(Address::class, ['data' => $addressData]);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
$shippingAddress = clone $billingAddress;
|
||||
$shippingAddress->setAddressType('shipping')
|
||||
->setId(null);
|
||||
|
||||
/** @var Quote $quote */
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$quote->setCustomerIsGuest(true)
|
||||
->setReservedOrderId('100000016')
|
||||
->setBillingAddress($billingAddress)
|
||||
->setShippingAddress($shippingAddress);
|
||||
|
||||
$quote->addProduct($product, 1);
|
||||
$quote->collectTotals();
|
||||
|
||||
/** @var QuoteRepository $quoteRepository */
|
||||
$quoteRepository = $objectManager->get(QuoteRepository::class);
|
||||
$quoteRepository->save($quote);
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type;
|
||||
use Magento\Catalog\Model\Product\Visibility;
|
||||
use Magento\CatalogInventory\Api\Data\StockItemInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
|
||||
Bootstrap::getInstance()->loadArea('adminhtml');
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var CustomerRepositoryInterface $customerRepository */
|
||||
$customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
|
||||
$customer = $customerRepository->get('customer@example.com');
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $objectManager->create(Product::class);
|
||||
$product->isObjectNew(true);
|
||||
$product->setTypeId(Type::TYPE_VIRTUAL)
|
||||
->setAttributeSetId(4)
|
||||
->setWebsiteIds([1])
|
||||
->setName('Virtual Product')
|
||||
->setSku('virtual-product-express')
|
||||
->setPrice(10)
|
||||
->setWeight(1)
|
||||
->setVisibility(Visibility::VISIBILITY_BOTH)
|
||||
->setStatus(Status::STATUS_ENABLED);
|
||||
|
||||
/** @var StockItemInterface $stockItem */
|
||||
$stockItem = $objectManager->create(StockItemInterface::class);
|
||||
$stockItem->setQty(100)
|
||||
->setIsInStock(true);
|
||||
$extensionAttributes = $product->getExtensionAttributes();
|
||||
$extensionAttributes->setStockItem($stockItem);
|
||||
|
||||
/** @var $productRepository ProductRepositoryInterface */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->save($product);
|
||||
|
||||
$billingAddress = $objectManager->create(Address::class);
|
||||
$billingAddress->setAddressType('billing');
|
||||
|
||||
/** @var $quote Quote */
|
||||
$quote = $objectManager->create(Quote::class);
|
||||
$quote->setCustomerIsGuest(false)
|
||||
->setCustomerId($customer->getId())
|
||||
->setCustomer($customer)
|
||||
->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId())
|
||||
->setReservedOrderId('test02')
|
||||
->setBillingAddress($billingAddress);
|
||||
$item = $objectManager->create(Item::class);
|
||||
$item->setProduct($product)
|
||||
->setPrice($product->getPrice())
|
||||
->setQty(1);
|
||||
$quote->addItem($item);
|
||||
$quote->getPayment()->setMethod(\Magento\Paypal\Model\Config::METHOD_EXPRESS);
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $objectManager->create(CartRepositoryInterface::class);
|
||||
$quoteRepository->save($quote);
|
||||
$quote = $quoteRepository->get($quote->getId());
|
||||
Reference in New Issue
Block a user