Skip to content

Commit

Permalink
Feature/queue handling (#96)
Browse files Browse the repository at this point in the history
* Fix for different merchant ids error for webhook
  • Loading branch information
andrii-onufriichuk authored Mar 21, 2024
1 parent 1497f21 commit b969a83
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cron/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function execute(): void
$collection = $this->webhookCollectionFactory->create();
$collection->addFieldToSelect('*')
->addFieldToFilter('is_processed', ['eq' => 'false']);
$collection->clear();

$this->processWebhooks($collection);
}
Expand Down Expand Up @@ -186,6 +187,7 @@ private function validatePaymentLink(int $storeId, array $data, int $webhookId):
$webhook = $this->webhookRepository->getById($webhookId);
$webhook->setData('is_processed', true);
$this->webhookRepository->save($webhook);
return false;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion Model/Payment/PaymentDataGet.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function execute(string $rvvupId): array
try {
return $this->sdkProxy->getOrder($rvvupId);
} catch (Throwable $t) {
$this->logger->error('Failed to get data from Rvvup for payment', ['rvvup_order_id' => $rvvupId]);
$this->logger->error('Failed to get data from Rvvup for order id', ['rvvup_order_id' => $rvvupId]);
return [];
}
}
Expand Down
16 changes: 15 additions & 1 deletion Model/Queue/Handler/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
namespace Rvvup\Payments\Model\Queue\Handler;

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\Area;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Model\ResourceModel\Order\Payment;
use Magento\Store\Model\App\Emulation;
use Psr\Log\LoggerInterface;
use Rvvup\Payments\Api\WebhookRepositoryInterface;
use Rvvup\Payments\Gateway\Method;
Expand Down Expand Up @@ -52,6 +54,9 @@ class Handler
/** @var Json */
private $json;

/** @var Emulation */
private $emulation;

/**
* @param WebhookRepositoryInterface $webhookRepository
* @param SerializerInterface $serializer
Expand All @@ -62,6 +67,7 @@ class Handler
* @param Payment $paymentResource
* @param Cache $cacheService
* @param Capture $captureService
* @param Emulation $emulation
* @param Json $json
*/
public function __construct(
Expand All @@ -74,6 +80,7 @@ public function __construct(
Payment $paymentResource,
Cache $cacheService,
Capture $captureService,
Emulation $emulation,
Json $json
) {
$this->webhookRepository = $webhookRepository;
Expand All @@ -85,6 +92,7 @@ public function __construct(
$this->paymentResource = $paymentResource;
$this->cacheService = $cacheService;
$this->logger = $logger;
$this->emulation = $emulation;
$this->json = $json;
}

Expand All @@ -102,7 +110,13 @@ public function execute(string $data)

$rvvupOrderId = $payload['order_id'];
$rvvupPaymentId = $payload['payment_id'];
$storeId = $payload['store_id'];
$storeId = $payload['store_id'] ?? false;

if (!$storeId) {
return;
}

$this->emulation->startEnvironmentEmulation((int) $storeId);

if ($paymentLinkId = $payload['payment_link_id']) {
$order = $this->captureService->getOrderByRvvupPaymentLinkId($paymentLinkId, $storeId);
Expand Down
1 change: 1 addition & 0 deletions Service/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public function getOrderByRvvupPaymentLinkId(string $paymentLinkId, string $stor
'like' => "%\"rvvup_payment_link_id\":\"$paymentLinkId\"%"
]
);
$collection->clear();
$items = $collection->getItems();
if (count($items) !== 1) {
return null;
Expand Down

0 comments on commit b969a83

Please sign in to comment.