resultRedirectFactory->create(); $orderId = (int)$this->getRequest()->getParam('order_id'); try { $order = $this->orderRepository->get($orderId); $payment = $order->getPayment(); $method = $payment ? (string)$payment->getMethod() : ''; if ((int)$order->getCustomerId() !== (int)$this->customerSession->getCustomerId()) { throw new LocalizedException(__('The requested order is not available.')); } if ((string)$order->getStatus() !== 'pending' || (float)$order->getTotalPaid() > 0.0) { throw new LocalizedException(__('This order is no longer awaiting payment.')); } if (!in_array( $method, [OceanpaymentConfig::METHOD_CODE, OceanpaymentConfig::LEGACY_METHOD_CODE], true )) { throw new LocalizedException(__('Online repayment is not available for this payment method.')); } $this->checkoutSession ->setLastQuoteId((int)$order->getQuoteId()) ->setLastSuccessQuoteId((int)$order->getQuoteId()) ->setLastOrderId((int)$order->getEntityId()) ->setLastRealOrderId((string)$order->getIncrementId()); $cachedUrl = (string)$payment->getAdditionalInformation('qianhai_pay_url'); $paymentUrl = $cachedUrl !== '' && $this->client->isAllowedPaymentUrl($cachedUrl) ? $cachedUrl : $this->client->createPaymentUrl($order); return $result->setUrl($paymentUrl); } catch (LocalizedException $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); } catch (\Throwable $exception) { $this->logger->error('Customer order repayment initialization failed', [ 'order_id' => $orderId, 'customer_id' => (int)$this->customerSession->getCustomerId(), 'exception' => $exception, ]); $this->messageManager->addErrorMessage( __('Payment initialization failed. Please try again or contact customer service.') ); } return $result->setPath('sales/order/history', ['status' => 'pending']); } }