From f9140e9a73cd0ee18c470a9e89319bb18b39d30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Tue, 20 Feb 2024 12:18:13 +0100 Subject: [PATCH] wip --- src/Gateway/Driver.php | 10 +++++++++- src/Models/Order.php | 22 +++++++++++++--------- src/Models/Transaction.php | 1 - 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Gateway/Driver.php b/src/Gateway/Driver.php index 373eb82a..5f5189e1 100644 --- a/src/Gateway/Driver.php +++ b/src/Gateway/Driver.php @@ -111,12 +111,20 @@ public function checkout(Request $request, Order $order): Order return $order; } + /** + * Resolve the order by the given UUID. + */ + public function resolveOrder(string $id): Order + { + return Order::proxy()->newQuery()->where('bazar_orders.uuid', $id)->firstOrFail(); + } + /** * Resolve the order model for payment capture. */ public function resolveOrderForCapture(Request $request): Order { - return Order::proxy()->newQuery()->where('uuid', $request->input('order'))->firstOrFail(); + return $this->resolveOrder($request->input('order')); } /** diff --git a/src/Models/Order.php b/src/Models/Order.php index c06b0ebd..5ad61710 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -38,7 +38,7 @@ class Order extends Model implements Contract public const CANCELLED = 'cancelled'; - public const COMPLETED = 'completed'; + public const FULFILLED = 'fulfilled'; public const FAILED = 'failed'; @@ -46,12 +46,8 @@ class Order extends Model implements Contract public const ON_HOLD = 'on_hold'; - public const PARTIALLY_REFUNDED = 'partially_refunded'; - public const PENDING = 'pending'; - public const REFUNDED = 'refunded'; - /** * The accessors to append to the model's array form. * @@ -131,11 +127,9 @@ public static function getStatuses(): array static::PENDING => __('Pending'), static::ON_HOLD => __('On Hold'), static::IN_PROGRESS => __('In Progress'), - static::COMPLETED => __('Completed'), + static::FULFILLED => __('Fulfilled'), static::CANCELLED => __('Cancelled'), static::FAILED => __('Failed'), - static::REFUNDED => __('Refunded'), - static::PARTIALLY_REFUNDED => __('Partially Refunded'), ]; } @@ -319,7 +313,17 @@ public function getTotalRefundable(): float */ public function paid(): bool { - return $this->payments->isNotEmpty() && $this->getTotal() <= $this->getTotalPaid(); + return $this->payments->filter()->completed()->isNotEmpty() + && $this->getTotal() <= $this->getTotalPaid(); + } + + /** + * Determine if the order is partially refunded. + */ + public function partiallyPaid(): bool + { + return $this->payments->filter->completed()->isNotEmpty() + && $this->getTotal() > $this->getTotalPaid(); } /** diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index f06a6702..11a341f9 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -7,7 +7,6 @@ use Cone\Bazar\Interfaces\Models\Transaction as Contract; use Cone\Bazar\Support\Facades\Gateway; use Cone\Root\Traits\InteractsWithProxy; -use DateTimeInterface; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\Factory;