|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Paypal\Controller\Adminhtml\Transparent; |
| 9 | + |
| 10 | +use Magento\Checkout\Model\Session; |
| 11 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
| 12 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 13 | +use Magento\Framework\Session\Generic; |
| 14 | +use Magento\Paypal\Model\Payflow\Transparent; |
| 15 | +use Magento\Quote\Api\CartRepositoryInterface; |
| 16 | +use Magento\Quote\Api\Data\CartInterface; |
| 17 | +use Magento\Quote\Api\PaymentMethodManagementInterface; |
| 18 | +use Magento\TestFramework\TestCase\AbstractController; |
| 19 | + |
| 20 | +/** |
| 21 | + * Tests PayPal transparent response controller. |
| 22 | + * |
| 23 | + * @magentoAppArea adminhtml |
| 24 | + */ |
| 25 | +class ResponseTest extends AbstractController |
| 26 | +{ |
| 27 | + /** |
| 28 | + * Tests storing payment information on backend from PayPal response. |
| 29 | + * |
| 30 | + * @throws NoSuchEntityException |
| 31 | + * |
| 32 | + * @magentoConfigFixture current_store payment/payflowpro/active 1 |
| 33 | + * @magentoDataFixture Magento/Sales/_files/quote.php |
| 34 | + */ |
| 35 | + public function testStoringPaymentInformation() |
| 36 | + { |
| 37 | + $reservedOrderId = 'test01'; |
| 38 | + $pnref = 'A10AAD866C87'; |
| 39 | + $postData = [ |
| 40 | + 'EXPDATE' => '0321', |
| 41 | + 'AMT' => '0.00', |
| 42 | + 'RESPMSG' => 'Verified', |
| 43 | + 'CVV2MATCH' => 'Y', |
| 44 | + 'PNREF' => $pnref, |
| 45 | + 'SECURETOKEN' => '3HYEHfG06skydAdBXbpIl8QJZ', |
| 46 | + 'AVSDATA' => 'YNY', |
| 47 | + 'RESULT' => '0', |
| 48 | + 'IAVS' => 'N', |
| 49 | + 'AVSADDR' => 'Y', |
| 50 | + 'SECURETOKENID' => 'yqanLisRZbI0HAG8q3SbbKbhiwjNZAGf', |
| 51 | + ]; |
| 52 | + |
| 53 | + $quote = $this->getQuote($reservedOrderId); |
| 54 | + $this->getRequest()->setPostValue($postData); |
| 55 | + $this->getRequest()->setMethod('POST'); |
| 56 | + /** @var Session $checkoutSession */ |
| 57 | + $checkoutSession = $this->_objectManager->get(Generic::class); |
| 58 | + $checkoutSession->setQuoteId($quote->getId()); |
| 59 | + |
| 60 | + $this->dispatch('backend/paypal/transparent/response'); |
| 61 | + |
| 62 | + /** @var PaymentMethodManagementInterface $paymentManagment */ |
| 63 | + $paymentManagment = $this->_objectManager->get(PaymentMethodManagementInterface::class); |
| 64 | + $payment = $paymentManagment->get($quote->getId()); |
| 65 | + |
| 66 | + $this->assertEquals($pnref, $payment->getAdditionalInformation(Transparent::PNREF)); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Gets quote by reserved order ID. |
| 71 | + * |
| 72 | + * @param string $reservedOrderId |
| 73 | + * @return CartInterface |
| 74 | + */ |
| 75 | + private function getQuote(string $reservedOrderId): CartInterface |
| 76 | + { |
| 77 | + $searchCriteria = $this->_objectManager->get(SearchCriteriaBuilder::class) |
| 78 | + ->addFilter('reserved_order_id', $reservedOrderId) |
| 79 | + ->create(); |
| 80 | + |
| 81 | + /** @var CartRepositoryInterface $quoteRepository */ |
| 82 | + $quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class); |
| 83 | + $items = $quoteRepository->getList($searchCriteria) |
| 84 | + ->getItems(); |
| 85 | + |
| 86 | + return array_pop($items); |
| 87 | + } |
| 88 | +} |
0 commit comments