diff --git a/src/Order/QueryHandler/GetOrderForApprovalReversedQueryHandler.php b/src/Order/QueryHandler/GetOrderForApprovalReversedQueryHandler.php index 8b1b903d6..b188f5673 100644 --- a/src/Order/QueryHandler/GetOrderForApprovalReversedQueryHandler.php +++ b/src/Order/QueryHandler/GetOrderForApprovalReversedQueryHandler.php @@ -81,10 +81,13 @@ public function handle(GetOrderForApprovalReversedQuery $query) } $hasBeenCanceled = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_CANCELED))); + $hasBeenPaid = $order->hasBeenPaid(); + $hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED))); + $hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID))); return new GetOrderForApprovalReversedQueryResult( (int) $order->id, - (bool) $order->hasBeenPaid(), + $hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid, (bool) $hasBeenCanceled ); } diff --git a/src/Order/QueryHandler/GetOrderForPaymentCompletedQueryHandler.php b/src/Order/QueryHandler/GetOrderForPaymentCompletedQueryHandler.php index 7779655fb..b94423127 100644 --- a/src/Order/QueryHandler/GetOrderForPaymentCompletedQueryHandler.php +++ b/src/Order/QueryHandler/GetOrderForPaymentCompletedQueryHandler.php @@ -21,6 +21,7 @@ namespace PrestaShop\Module\PrestashopCheckout\Order\QueryHandler; +use Configuration; use Order; use OrderPayment; use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException; @@ -28,6 +29,7 @@ use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException; use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentCompletedQuery; use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentCompletedQueryResult; +use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys; use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository; use PrestaShopCollection; use PrestaShopDatabaseException; @@ -89,10 +91,14 @@ public function handle(GetOrderForPaymentCompletedQuery $query) } } + $hasBeenPaid = $order->hasBeenPaid(); + $hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED))); + $hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID))); + return new GetOrderForPaymentCompletedQueryResult( (int) $order->id, (int) $order->id_cart, - (bool) $order->hasBeenPaid(), + $hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid, (string) $order->total_paid, (int) $order->id_currency, $psCheckoutCart->getPaypalFundingSource(), diff --git a/src/Order/QueryHandler/GetOrderForPaymentRefundedQueryHandler.php b/src/Order/QueryHandler/GetOrderForPaymentRefundedQueryHandler.php index 415b44a37..bc94cb115 100644 --- a/src/Order/QueryHandler/GetOrderForPaymentRefundedQueryHandler.php +++ b/src/Order/QueryHandler/GetOrderForPaymentRefundedQueryHandler.php @@ -21,12 +21,14 @@ namespace PrestaShop\Module\PrestashopCheckout\Order\QueryHandler; +use Configuration; use Order; use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException; use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException; use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException; use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentRefundedQuery; use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentRefundedQueryResult; +use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys; use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository; use PrestaShopCollection; use PrestaShopDatabaseException; @@ -78,12 +80,16 @@ public function handle(GetOrderForPaymentRefundedQuery $query) throw new OrderNotFoundException('No PrestaShop Order associated to this PayPal Order at this time.'); } + $hasBeenPaid = $order->hasBeenPaid(); + $hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED))); + $hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID))); + return new GetOrderForPaymentRefundedQueryResult( (int) $order->id, (int) $order->getCurrentState(), - (bool) $order->hasBeenPaid(), - (bool) count($order->getHistory((int) $order->id_lang, \Configuration::get('PS_CHECKOUT_STATE_PARTIALLY_REFUNDED'))), - (bool) count($order->getHistory((int) $order->id_lang, \Configuration::get('PS_CHECKOUT_STATE_REFUNDED'))), + $hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid, + (bool) count($order->getHistory((int) $order->id_lang, Configuration::get('PS_CHECKOUT_STATE_PARTIALLY_REFUNDED'))), + (bool) count($order->getHistory((int) $order->id_lang, Configuration::get('PS_CHECKOUT_STATE_REFUNDED'))), (string) $order->getTotalPaid(), (int) $order->id_currency ); diff --git a/src/Order/QueryHandler/GetOrderForPaymentReversedQueryHandler.php b/src/Order/QueryHandler/GetOrderForPaymentReversedQueryHandler.php index d171c107d..4d630cbfa 100644 --- a/src/Order/QueryHandler/GetOrderForPaymentReversedQueryHandler.php +++ b/src/Order/QueryHandler/GetOrderForPaymentReversedQueryHandler.php @@ -21,13 +21,14 @@ namespace PrestaShop\Module\PrestashopCheckout\Order\QueryHandler; +use Configuration; use Order; -use OrderSlip; use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException; use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException; use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException; use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentReversedQuery; use PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentReversedQueryResult; +use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys; use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository; use PrestaShopCollection; use PrestaShopDatabaseException; @@ -79,25 +80,15 @@ public function handle(GetOrderForPaymentReversedQuery $query) throw new OrderNotFoundException('No PrestaShop Order associated to this PayPal Order at this time.'); } + $hasBeenPaid = $order->hasBeenPaid(); + $hasBeenCompleted = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED))); + $hasBeenPartiallyPaid = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID))); + $hasBeenTotallyRefunded = count($order->getHistory($order->id_lang, (int) Configuration::getGlobalValue(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_REFUNDED))); + return new GetOrderForPaymentReversedQueryResult( (int) $order->id, - (bool) $order->hasBeenPaid(), - $this->hasBeenTotallyRefunded($order) + $hasBeenPaid || $hasBeenCompleted || $hasBeenPartiallyPaid, + $hasBeenTotallyRefunded ); } - - private function hasBeenTotallyRefunded(Order $order) - { - /** @var OrderSlip[] $orderSlips */ - $orderSlips = $order->getOrderSlipsCollection()->getResults(); - $refundAmount = 0; - - if (!empty($orderSlips)) { - foreach ($orderSlips as $orderSlip) { - $refundAmount += $orderSlip->amount + $orderSlip->shipping_cost_amount; - } - } - - return $refundAmount >= $order->total_paid; - } }