Skip to content

Commit b969a83

Browse files
Feature/queue handling (#96)
* Fix for different merchant ids error for webhook
1 parent 1497f21 commit b969a83

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

Cron/Webhook.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function execute(): void
6262
$collection = $this->webhookCollectionFactory->create();
6363
$collection->addFieldToSelect('*')
6464
->addFieldToFilter('is_processed', ['eq' => 'false']);
65+
$collection->clear();
6566

6667
$this->processWebhooks($collection);
6768
}
@@ -186,6 +187,7 @@ private function validatePaymentLink(int $storeId, array $data, int $webhookId):
186187
$webhook = $this->webhookRepository->getById($webhookId);
187188
$webhook->setData('is_processed', true);
188189
$this->webhookRepository->save($webhook);
190+
return false;
189191
}
190192

191193
return true;

Model/Payment/PaymentDataGet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function execute(string $rvvupId): array
4242
try {
4343
return $this->sdkProxy->getOrder($rvvupId);
4444
} catch (Throwable $t) {
45-
$this->logger->error('Failed to get data from Rvvup for payment', ['rvvup_order_id' => $rvvupId]);
45+
$this->logger->error('Failed to get data from Rvvup for order id', ['rvvup_order_id' => $rvvupId]);
4646
return [];
4747
}
4848
}

Model/Queue/Handler/Handler.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
namespace Rvvup\Payments\Model\Queue\Handler;
55

66
use Magento\Framework\Api\SearchCriteriaBuilder;
7+
use Magento\Framework\App\Area;
78
use Magento\Framework\Exception\AlreadyExistsException;
89
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Framework\Serialize\SerializerInterface;
1011
use Magento\Sales\Api\Data\OrderInterface;
1112
use Magento\Sales\Model\ResourceModel\Order\Payment;
13+
use Magento\Store\Model\App\Emulation;
1214
use Psr\Log\LoggerInterface;
1315
use Rvvup\Payments\Api\WebhookRepositoryInterface;
1416
use Rvvup\Payments\Gateway\Method;
@@ -52,6 +54,9 @@ class Handler
5254
/** @var Json */
5355
private $json;
5456

57+
/** @var Emulation */
58+
private $emulation;
59+
5560
/**
5661
* @param WebhookRepositoryInterface $webhookRepository
5762
* @param SerializerInterface $serializer
@@ -62,6 +67,7 @@ class Handler
6267
* @param Payment $paymentResource
6368
* @param Cache $cacheService
6469
* @param Capture $captureService
70+
* @param Emulation $emulation
6571
* @param Json $json
6672
*/
6773
public function __construct(
@@ -74,6 +80,7 @@ public function __construct(
7480
Payment $paymentResource,
7581
Cache $cacheService,
7682
Capture $captureService,
83+
Emulation $emulation,
7784
Json $json
7885
) {
7986
$this->webhookRepository = $webhookRepository;
@@ -85,6 +92,7 @@ public function __construct(
8592
$this->paymentResource = $paymentResource;
8693
$this->cacheService = $cacheService;
8794
$this->logger = $logger;
95+
$this->emulation = $emulation;
8896
$this->json = $json;
8997
}
9098

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

103111
$rvvupOrderId = $payload['order_id'];
104112
$rvvupPaymentId = $payload['payment_id'];
105-
$storeId = $payload['store_id'];
113+
$storeId = $payload['store_id'] ?? false;
114+
115+
if (!$storeId) {
116+
return;
117+
}
118+
119+
$this->emulation->startEnvironmentEmulation((int) $storeId);
106120

107121
if ($paymentLinkId = $payload['payment_link_id']) {
108122
$order = $this->captureService->getOrderByRvvupPaymentLinkId($paymentLinkId, $storeId);

Service/Capture.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ public function getOrderByRvvupPaymentLinkId(string $paymentLinkId, string $stor
344344
'like' => "%\"rvvup_payment_link_id\":\"$paymentLinkId\"%"
345345
]
346346
);
347+
$collection->clear();
347348
$items = $collection->getItems();
348349
if (count($items) !== 1) {
349350
return null;

0 commit comments

Comments
 (0)