Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/WalletsController.php
<?php | <?php | ||||
namespace App\Http\Controllers\API\V4; | namespace App\Http\Controllers\API\V4; | ||||
use App\Payment; | |||||
use App\Transaction; | use App\Transaction; | ||||
use App\Wallet; | use App\Wallet; | ||||
use App\Http\Controllers\ResourceController; | use App\Http\Controllers\ResourceController; | ||||
use App\Providers\PaymentProvider; | use App\Providers\PaymentProvider; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
/** | /** | ||||
Show All 18 Lines | public function show($id) | ||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!$this->guard()->user()->canRead($wallet)) { | if (!$this->guard()->user()->canRead($wallet)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$result = $wallet->toArray(); | $result = $wallet->toArray(); | ||||
$provider = \App\Providers\PaymentProvider::factory($wallet); | $provider = PaymentProvider::factory($wallet); | ||||
$result['provider'] = $provider->name(); | $result['provider'] = $provider->name(); | ||||
$result['notice'] = $this->getWalletNotice($wallet); | $result['notice'] = $this->getWalletNotice($wallet); | ||||
return response()->json($result); | return response()->json($result); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | public function receipts($id) | ||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!$this->guard()->user()->canRead($wallet)) { | if (!$this->guard()->user()->canRead($wallet)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$result = $wallet->payments() | $result = $wallet->payments() | ||||
->selectRaw('distinct date_format(updated_at, "%Y-%m") as ident') | ->selectRaw('distinct date_format(updated_at, "%Y-%m") as ident') | ||||
->where('status', PaymentProvider::STATUS_PAID) | ->where('status', Payment::STATUS_PAID) | ||||
->where('amount', '<>', 0) | ->where('amount', '<>', 0) | ||||
->orderBy('ident', 'desc') | ->orderBy('ident', 'desc') | ||||
->get() | ->get() | ||||
->whereNotIn('ident', [date('Y-m')]) // exclude current month | ->whereNotIn('ident', [date('Y-m')]) // exclude current month | ||||
->pluck('ident'); | ->pluck('ident'); | ||||
return response()->json([ | return response()->json([ | ||||
'status' => 'success', | 'status' => 'success', | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |