ltsecurityinc安防产品在线商城代码
This commit is contained in:
+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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user