Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-onufriichuk committed Jan 16, 2024
1 parent 6cd447e commit 9fdae8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 10 additions & 2 deletions Controller/Redirect/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function execute()
{
$rvvupId = $this->request->getParam('rvvup-order-id');
$quote = $this->checkoutSession->getQuote();

if (!$quote->getId()) {
$quote = $this->captureService->getQuoteByRvvupId($rvvupId);
}

$payment = $quote->getPayment();
$rvvupPaymentId = $payment->getAdditionalInformation(Method::PAYMENT_ID);
$lastTransactionId = (string)$payment->getAdditionalInformation(Method::TRANSACTION_ID);
Expand All @@ -106,11 +111,14 @@ public function execute()
return $this->redirectToCart();
}
if ($validate['already_exists']) {
if ($quote->getId()) {
$this->checkoutSession->setLastSuccessQuoteId($quote->getId());
}

if (!$quote->getReservedOrderId()) {
if ($this->checkoutSession->getLastOrderId()) {
$id = $this->checkoutSession->getLastOrderId();
$this->checkoutSession->setLastSuccessQuoteId($id);
return $this->captureService->processOrderResult(null, $rvvupId);
return $this->captureService->processOrderResult($id, $rvvupId);
}
}
return $this->captureService->processOrderResult((string)$quote->getReservedOrderId(), $rvvupId, true);
Expand Down
16 changes: 4 additions & 12 deletions Controller/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function execute(): ResultInterface
{
try {
$merchantId = $this->request->getParam('merchant_id', false);
$rvvupOrderId = $this->request->getParam('order_id', false);
$rvvupOrderId = 'OR01HM8QYGY1GGC4ZHTKGZF55G02';
$eventType = $this->request->getParam('event_type', false);
$paymentId = $this->request->getParam('payment_id', false);
$refundId = $this->request->getParam('refund_id', false);
Expand All @@ -111,12 +111,12 @@ public function execute(): ResultInterface
* so returning a 400 should be fine to indicate the request is invalid and won't cause
* Rvvup to make repeated requests to the webhook.
*/
return $this->returnInvalidResponse();
// return $this->returnInvalidResponse();
}

// Merchant ID does not match, no need to process
if ($merchantId !== $this->config->getMerchantId()) {
return $this->returnInvalidResponse();
//return $this->returnInvalidResponse();
}

$payload = [
Expand All @@ -127,15 +127,7 @@ public function execute(): ResultInterface
'event_type' => $eventType,
];

if ($payload['event_type'] == Complete::TYPE) {
$this->refundPool->getProcessor($eventType)->execute($payload);
return $this->returnSuccessfulResponse();
} elseif ($payload['event_type'] == self::PAYMENT_COMPLETED) {
$webhook = $this->webhookRepository->new(['payload' => $this->serializer->serialize($payload)]);
$this->webhookRepository->save($webhook);
$this->publisher->publish('rvvup.webhook', (int)$webhook->getId());
return $this->returnSuccessfulResponse();
} elseif ($payload['event_type'] == Method::STATUS_PAYMENT_AUTHORIZED) {
if (true) {
$quote = $this->captureService->getQuoteByRvvupId($rvvupOrderId);
if (!$quote) {
$this->logger->debug(
Expand Down
2 changes: 1 addition & 1 deletion Service/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public function getQuoteByRvvupId(string $rvvupId): ?Quote
]
);
$items = $collection->getItems();
if (count($items) > 1) {
if (count($items) !== 1) {
return null;
}
$quoteId = end($items)->getQuoteId();
Expand Down

0 comments on commit 9fdae8a

Please sign in to comment.