diff --git a/Controller/Checkout/Exchange.php b/Controller/Checkout/Exchange.php index 0dbf9f14..1633df58 100755 --- a/Controller/Checkout/Exchange.php +++ b/Controller/Checkout/Exchange.php @@ -204,7 +204,10 @@ public function execute() $order = $this->createFastCheckoutOrder->create($params); $orderEntityId = $order->getId(); } catch (\Exception $e) { - $this->payHelper->logCritical($e->getMessage(), $params); + $this->payHelper->logCritical('Fast checkout: ' . $e->getMessage(), $params); + if ($e->getCode() == 404) { + return $this->result->setContents('TRUE| Error creating fast checkout order. ' . $e->getMessage()); + } return $this->result->setContents('FALSE| Error creating fast checkout order. ' . $e->getMessage()); } } elseif (strpos($params['extra3'] ?? '', "fastcheckout") !== false) { diff --git a/Controller/Checkout/FastCheckoutStart.php b/Controller/Checkout/FastCheckoutStart.php index 014ba40b..7a76e6ea 100644 --- a/Controller/Checkout/FastCheckoutStart.php +++ b/Controller/Checkout/FastCheckoutStart.php @@ -160,12 +160,12 @@ private function getProducts() $productArr = []; foreach ($products as $key => $product) { - if ($product->getPrice() > 0) { + if ($product->getPriceInclTax() > 0) { $productArr[] = [ 'id' => $product->getProductId(), 'quantity' => $product->getQty(), 'description' => $product->getName(), - 'price' => $product->getPrice() * 100, + 'price' => $product->getPriceInclTax() * 100, 'currecny' => $this->storeManager->getStore()->getCurrentCurrencyCode(), 'type' => \Paynl\Transaction::PRODUCT_TYPE_ARTICLE, 'vatPercentage' => ($product->getPriceInclTax() - $product->getBasePrice()) / $product->getBasePrice() * 100, diff --git a/Controller/Checkout/Redirect.php b/Controller/Checkout/Redirect.php index d3ffc6a8..527d4e29 100644 --- a/Controller/Checkout/Redirect.php +++ b/Controller/Checkout/Redirect.php @@ -88,13 +88,12 @@ public function execute() $payment = $order->getPayment(); if (empty($payment)) { - $this->_redirect('checkout/cart'); - return; + throw new \Exception('No payment found'); } $methodInstance = $this->paymentHelper->getMethodInstance($payment->getMethod()); if ($methodInstance instanceof \Paynl\Payment\Model\Paymentmethod\Paymentmethod) { - $this->payHelper->logNotice('Start new payment for order ' . $order->getId(), array(), $order->getStore()); + $this->payHelper->logNotice('Start new payment for order ' . $order->getId() . '. PayProfileId: ' . $methodInstance->getPaymentOptionId(), array(), $order->getStore()); $redirectUrl = $methodInstance->startTransaction($order); $this->getResponse()->setNoCacheHeaders(); $this->getResponse()->setRedirect($redirectUrl); @@ -105,8 +104,7 @@ public function execute() $this->_getCheckoutSession()->restoreQuote(); // phpcs:ignore $this->messageManager->addExceptionMessage($e, __('Something went wrong, please try again later')); $this->messageManager->addExceptionMessage($e, $e->getMessage()); - $this->payHelper->logCritical($e, array(), $order->getStore()); - + $this->payHelper->logCritical($e->getMessage(), array(), $order->getStore()); $this->_redirect('checkout/cart'); } } diff --git a/Model/CreateFastCheckoutOrder.php b/Model/CreateFastCheckoutOrder.php index 9fa63d74..1ad25da0 100644 --- a/Model/CreateFastCheckoutOrder.php +++ b/Model/CreateFastCheckoutOrder.php @@ -12,6 +12,7 @@ use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\OrderFactory; use Magento\Store\Model\StoreManagerInterface; +use Paynl\Payment\Helper\PayHelper; class CreateFastCheckoutOrder { @@ -65,6 +66,11 @@ class CreateFastCheckoutOrder */ private $searchCriteriaBuilder; + /** + * @var \Paynl\Payment\Helper\PayHelper; + */ + private $payHelper; + /** * @param StoreManagerInterface $storeManager * @param QuoteFactory $quote @@ -75,6 +81,7 @@ class CreateFastCheckoutOrder * @param ShippingMethodManagementInterface $shippingMethodManagementInterface * @param OrderRepositoryInterface $orderRepositoryInterface * @param SearchCriteriaBuilder $searchCriteriaBuilder + * @param PayHelper $payHelper */ public function __construct( StoreManagerInterface $storeManager, @@ -85,7 +92,8 @@ public function __construct( OrderFactory $orderFactory, ShippingMethodManagementInterface $shippingMethodManagementInterface, OrderRepositoryInterface $orderRepositoryInterface, - SearchCriteriaBuilder $searchCriteriaBuilder + SearchCriteriaBuilder $searchCriteriaBuilder, + PayHelper $payHelper ) { $this->storeManager = $storeManager; $this->quote = $quote; @@ -96,12 +104,14 @@ public function __construct( $this->shippingMethodManagementInterface = $shippingMethodManagementInterface; $this->orderRepositoryInterface = $orderRepositoryInterface; $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->payHelper = $payHelper; } /** * @param array $params * @return Order * @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing + * @throws \Exception */ public function create($params) { @@ -111,6 +121,7 @@ public function create($params) $shippingAddressData = $checkoutData['shippingAddress'] ?? null; if (empty($customerData) || empty($billingAddressData) || empty($shippingAddressData)) { + $this->payHelper->logCritical("Fast checkout: Missing data, cannot create order.", ['customerData' => $customerData, 'billingAddressData' => $billingAddressData, 'shippingAddressData' => $shippingAddressData]); // phpcs:ignore throw new \Exception("Missing data, cannot create order."); } @@ -119,8 +130,25 @@ public function create($params) $orderId = explode('fastcheckout', $params['orderId']); $quoteId = $orderId[1] ?? ''; + $this->payHelper->logDebug('Start fast checkout order create', ['quoteId' => $quoteId]); + try { $quote = $this->quote->create()->loadByIdWithoutStore($quoteId); + $this->payHelper->logDebug('Fast checkout: quote->getId()', ['quoteId' => $quoteId, 'magentoQuoteId' => $quote->getId() ?? 'null']); + + if (empty($quote['is_active'])) { + $this->payHelper->logDebug('Fast checkout: Quote inactive', ['quoteId' => $quoteId]); + + $existingOrder = $this->getExistingOrder($quoteId); + if (empty($existingOrder)) { + $this->payHelper->logDebug('Fast checkout: Reactivating quote', ['quoteId' => $quoteId]); + $quote->setIsActive(true); + $quote->save(); + } else { + return $existingOrder; + } + } + $storeId = $quote->getStoreId(); $shippingMethodQuote = $quote->getShippingAddress()->getShippingMethod(); @@ -148,7 +176,7 @@ public function create($params) $quote->assignCustomer($customer); $quote->setSendConfirmation(1); - $billingAddress = $quote->getBillingAddress()->addData(array( + $quote->getBillingAddress()->addData(array( 'customer_address_id' => '', 'prefix' => '', 'firstname' => $billingAddressData['firstName'] ?? $customerData['firstName'], @@ -170,7 +198,7 @@ public function create($params) 'save_in_address_book' => 1, )); - $shippingAddress = $quote->getShippingAddress()->addData(array( + $quote->getShippingAddress()->addData(array( 'customer_address_id' => '', 'prefix' => '', 'firstname' => $shippingAddressData['firstName'] ?? $customerData['firstName'], @@ -196,22 +224,26 @@ public function create($params) $shippingAddress->setCollectShippingRates(true)->collectShippingRates(); $shippingData = $this->shippingMethodManagementInterface->getList($quote->getId()); - $shippingMethodsAvaileble = []; + $shippingMethodsAvailable = []; foreach ($shippingData as $shipping) { $code = $shipping->getCarrierCode() . '_' . $shipping->getMethodCode(); - $shippingMethodsAvaileble[$code] = $code; + $shippingMethodsAvailable[$code] = $code; } - if (!empty($shippingMethodsAvaileble[$shippingMethodQuote])) { + $this->payHelper->logDebug('Fast checkout: Available shipping methods', $shippingMethodsAvailable); + + if (!empty($shippingMethodsAvailable[$shippingMethodQuote])) { $shippingMethod = $shippingMethodQuote; - } elseif (!empty($shippingMethodsAvaileble[$store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping')])) { + } elseif (!empty($shippingMethodsAvailable[$store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping')])) { $shippingMethod = $store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping'); - } elseif (!empty($shippingMethodsAvaileble[$store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping_backup')])) { + } elseif (!empty($shippingMethodsAvailable[$store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping_backup')])) { $shippingMethod = $store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping_backup'); } + $this->payHelper->logDebug('Fast checkout: Shipping options', ['quote' => $shippingMethodQuote, 'setting' => $store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping'), 'setting_backup' => $store->getConfig('payment/paynl_payment_ideal/fast_checkout_shipping_backup')]); // phpcs:ignore + if (empty($shippingMethod)) { - throw new \Exception("No shipping method availeble"); + throw new \Exception("No shipping method available"); } $shippingAddress->setShippingMethod($shippingMethod); @@ -226,23 +258,33 @@ public function create($params) $service = $this->quoteManagement->submit($quote); $increment_id = $service->getRealOrderId(); + $this->payHelper->logDebug('Fast checkout: Reserved increment_id', [$increment_id]); $order = $this->orderFactory->create()->loadByIncrementId($increment_id); $additionalData = $order->getPayment()->getAdditionalInformation(); $additionalData['transactionId'] = $payOrderId; $order->getPayment()->setAdditionalInformation($additionalData); $order->save(); + $this->payHelper->logDebug('Fast checkout: Created order_id', [$order->getId()]); $order->addStatusHistoryComment(__('PAY. - Created iDEAL Fast Checkout order'))->save(); } catch (NoSuchEntityException $e) { + $this->payHelper->logDebug('Fast checkout: Quote not found', ['quoteId' => $quoteId, 'error' => $e->getMessage()]); $order = $this->getExistingOrder($quoteId); + } catch (\Exception $e) { + $this->payHelper->logDebug('Fast checkout: Exception on create', ['quoteId' => $quoteId, 'error' => $e->getMessage()]); + throw new \Exception("Exception on create. " . $e->getMessage()); + } + if (empty($order)) { + $this->payHelper->logCritical('Fast checkout: Both order & quote not found', ['quoteId' => $quoteId, 'searchCriteria' => $searchCriteria, 'searchResult' => $searchResult]); + throw new \Exception("Order & Quote can't be found. " . $quoteId, 404); } return $order; } /** * @param string $quoteId - * @return Order + * @return Order|boolean * @throws \Exception * @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing */ @@ -254,7 +296,7 @@ public function getExistingOrder($quoteId) $order = array_shift($searchResult); } if (empty($order)) { - throw new \Exception("Order can't be found."); + return false; } return $order; } diff --git a/composer.json b/composer.json index a212131c..c134f5bc 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "paynl/magento2-plugin", "description": "PAY. Payment methods for Magento2", "type": "magento2-module", - "version": "3.14.3", + "version": "3.14.4", "require": { "magento/module-sales": "^102.0.0 || ^103.0.0", "magento/module-payment": "^100.3.0", diff --git a/view/frontend/web/css/payFastCheckout.css b/view/frontend/web/css/payFastCheckout.css index d9671629..91be031d 100644 --- a/view/frontend/web/css/payFastCheckout.css +++ b/view/frontend/web/css/payFastCheckout.css @@ -19,6 +19,7 @@ background-repeat: no-repeat; background-size: 51px; background-position: 8px center; + color: white; } #top-cart-btn-fastcheckout { @@ -36,6 +37,7 @@ background-repeat: no-repeat; background-size: 51px; background-position: 8px center; + color: white; } #paynl_fast_checkout_fallback button { @@ -60,4 +62,4 @@ #paynl_fast_checkout_fallback button { max-width: 250px; } -} +} \ No newline at end of file