init
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?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\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\Result\Raw;
|
||||
use Magento\Framework\Controller\Result\RawFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Notify extends AbstractCallback implements HttpPostActionInterface
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
private readonly Parser $parser,
|
||||
private readonly Processor $processor,
|
||||
private readonly RawFactory $rawFactory,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute(): Raw
|
||||
{
|
||||
$result = $this->rawFactory->create();
|
||||
try {
|
||||
$data = $this->parser->parse(
|
||||
(string)$this->getRequest()->getContent(),
|
||||
(array)$this->getRequest()->getParams()
|
||||
);
|
||||
$this->processor->process($data, true);
|
||||
return $result->setContents('receive-ok');
|
||||
} catch (\Throwable $exception) {
|
||||
$this->logger->warning('Oceanpayment asynchronous callback was rejected', [
|
||||
'exception' => $exception,
|
||||
]);
|
||||
$this->getResponse()->setHttpResponseCode(400);
|
||||
return $result->setContents('invalid');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user