Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 20, 2024
1 parent 194ad12 commit f9140e9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/Gateway/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
22 changes: 13 additions & 9 deletions src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,16 @@ class Order extends Model implements Contract

public const CANCELLED = 'cancelled';

public const COMPLETED = 'completed';
public const FULFILLED = 'fulfilled';

public const FAILED = 'failed';

public const IN_PROGRESS = 'in_progress';

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.
*
Expand Down Expand Up @@ -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'),
];
}

Expand Down Expand Up @@ -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();
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f9140e9

Please sign in to comment.