Skip to content

Commit

Permalink
Fix error with wrong token
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinwy committed Jul 5, 2024
1 parent 205760e commit 4868034
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Komoju\Payments\Model\ExternalPayment;

use Psr\Log\LoggerInterface;
use Exception;

class ProcessToken extends Action
{
Expand Down Expand Up @@ -51,11 +52,7 @@ public function execute()
$result = $this->jsonResultFactory->create();
$order = $this->getOrder();

if ($order) {
$this->logger->debug('Order Data' . json_encode($order->getEntityId()));
$externalPayment = $this->createExternalPayment($order);
$this->logger->info('ExternalPayment: ' . $externalPayment);
} else {
if (!$order) {
$this->logger->debug('Executing KomojuSessionData controller' . 'No order found');
return $result->setData(['success' => false, 'message' => 'No order found']);
}
Expand All @@ -64,9 +61,8 @@ public function execute()
$postData = $this->getRequest()->getContent();
$tokenData = json_decode($postData);

// $this->logger->debug('Executing KomojuSessionData controller' . json_encode($tokenData));

$currencyCode = $order->getOrderCurrencyCode();
$externalPayment = $this->createExternalPayment($order);

$session = $this->komojuApi->createSession([
'amount' => $order->getGrandTotal(),
Expand All @@ -82,12 +78,16 @@ public function execute()
],
]);

$data = $this->komojuApi->paySession($session->id, [
'customer_email' => $order->getCustomerEmail(),
'payment_details' => $tokenData->token->id
]);
try {
$data = $this->komojuApi->paySession($session->id, [
'payment_details' => (string) $tokenData->token->id
]);

return $result->setData(['success' => true, 'message' => 'Token processed successfully', 'data' => $data]);
return $result->setData(['success' => true, 'message' => 'Token processed successfully', 'data' => $data]);
} catch (Exception $e) {
$data = ['redirect_url' => $session->session_url];
return $result->setData(['success' => true, 'message' => 'Cannot process token, redirect', 'data' => $data]);
}
}

return $result->setData(['success' => false, 'message' => 'Invalid request']);
Expand Down

0 comments on commit 4868034

Please sign in to comment.