init
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Oceanpayment\Controller\Payment;
|
||||
|
||||
use Esun\Oceanpayment\Model\Callback\Parser;
|
||||
use Esun\Oceanpayment\Model\Callback\Processor;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Back extends AbstractCallback implements HttpGetActionInterface, HttpPostActionInterface
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
private readonly Parser $parser,
|
||||
private readonly Processor $processor,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute(): ResultRedirect
|
||||
{
|
||||
/** @var ResultRedirect $result */
|
||||
$result = $this->resultRedirectFactory->create();
|
||||
|
||||
try {
|
||||
$data = $this->parser->parse(
|
||||
(string)$this->getRequest()->getContent(),
|
||||
(array)$this->getRequest()->getParams()
|
||||
);
|
||||
$paymentResult = $this->processor->process($data, false);
|
||||
if ($paymentResult === Processor::FAILURE) {
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('Payment was not completed: %1', $data['payment_details'])
|
||||
);
|
||||
} elseif ($paymentResult === Processor::PENDING) {
|
||||
$this->messageManager->addNoticeMessage(
|
||||
__('Your payment is being confirmed. The order will update automatically.')
|
||||
);
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
$this->logger->warning('Oceanpayment browser callback was rejected', ['exception' => $exception]);
|
||||
$this->messageManager->addErrorMessage(
|
||||
__('The payment result could not be verified. Please contact customer service if you were charged.')
|
||||
);
|
||||
}
|
||||
|
||||
return $result->setPath('checkout/onepage/success');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user