feat: refactor purchase status handling and add finalize endpoint for purchases
This commit is contained in:
@@ -16,7 +16,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
'tenant_codigo',
|
||||
'user_id',
|
||||
'status',
|
||||
'payment_status',
|
||||
'payment_method',
|
||||
'total',
|
||||
'dni',
|
||||
@@ -28,6 +27,12 @@ class Purchase extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const STATUS_CREATED = 'created';
|
||||
public const STATUS_PENDING_PAYMENT = 'pending_payment';
|
||||
public const STATUS_PAID = 'paid';
|
||||
public const STATUS_CANCELLED = 'cancelled';
|
||||
public const STATUS_REJECTED = 'rejected';
|
||||
|
||||
protected $table = 'compras';
|
||||
|
||||
protected function casts(): array
|
||||
@@ -117,11 +122,17 @@ class Purchase extends Model
|
||||
return $cart->getTotalAmount();
|
||||
}
|
||||
|
||||
public function finalize(): void
|
||||
public function markAsPendingPayment(): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => 'paid',
|
||||
'payment_status' => 'approved',
|
||||
'status' => self::STATUS_PENDING_PAYMENT,
|
||||
]);
|
||||
}
|
||||
|
||||
public function markAsPaid(): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => self::STATUS_PAID,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user