digipay
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\DigipayInstallmentService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DigipayInstallmentController extends Controller
|
||||
{
|
||||
public function __construct(private DigipayInstallmentService $service)
|
||||
{
|
||||
}
|
||||
|
||||
public function setCredit(Request $request)
|
||||
{
|
||||
$this->ensureEnabled();
|
||||
$data = $request->validate([
|
||||
'mobile' => 'required|string|max:20',
|
||||
'plan4_toman' => 'required|integer|min:0',
|
||||
'plan12_toman' => 'required|integer|min:0',
|
||||
]);
|
||||
|
||||
return response()->json($this->service->setCredit(
|
||||
$data['mobile'],
|
||||
(int) $data['plan4_toman'],
|
||||
(int) $data['plan12_toman']
|
||||
));
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
$this->ensureEnabled();
|
||||
|
||||
return response()->json(['data' => $this->service->recentOrders()]);
|
||||
}
|
||||
|
||||
private function ensureEnabled(): void
|
||||
{
|
||||
if (! $this->service->enabled()) {
|
||||
abort(403, 'خرید اقساطی فعال نیست');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Customer;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\DigipayInstallmentService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DigipayInstallmentController extends Controller
|
||||
{
|
||||
public function __construct(private DigipayInstallmentService $service)
|
||||
{
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$this->ensureEnabled();
|
||||
|
||||
return response()->json($this->service->statusFor((int) auth('customer')->id()));
|
||||
}
|
||||
|
||||
public function start()
|
||||
{
|
||||
$this->ensureEnabled();
|
||||
$this->service->markStarted((int) auth('customer')->id());
|
||||
|
||||
return response()->json($this->service->statusFor((int) auth('customer')->id()));
|
||||
}
|
||||
|
||||
public function buy(Request $request)
|
||||
{
|
||||
$this->ensureEnabled();
|
||||
$data = $request->validate([
|
||||
'plan' => 'required|integer|in:4,12',
|
||||
'amount_toman' => 'required|integer|min:1000',
|
||||
]);
|
||||
|
||||
$result = $this->service->buy(
|
||||
(int) auth('customer')->id(),
|
||||
(int) $data['plan'],
|
||||
(int) $data['amount_toman']
|
||||
);
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
private function ensureEnabled(): void
|
||||
{
|
||||
if (! $this->service->enabled()) {
|
||||
abort(403, 'خرید اقساطی فعال نیست');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user