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\Transaction; | use App\Transaction; | ||||
use App\Wallet; | use App\Wallet; | ||||
use App\Http\Controllers\Controller; | use App\Http\Controllers\Controller; | ||||
use App\Providers\PaymentProvider; | use App\Providers\PaymentProvider; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||
use Illuminate\Support\Facades\Auth; | |||||
/** | /** | ||||
* API\WalletsController | * API\WalletsController | ||||
*/ | */ | ||||
class WalletsController extends Controller | class WalletsController extends Controller | ||||
{ | { | ||||
/** | /** | ||||
* Display a listing of the resource. | * Display a listing of the resource. | ||||
Show All 33 Lines | class WalletsController extends Controller | ||||
* @param string $id A wallet identifier | * @param string $id A wallet identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse The response | * @return \Illuminate\Http\JsonResponse The response | ||||
*/ | */ | ||||
public function show($id) | public function show($id) | ||||
{ | { | ||||
$wallet = Wallet::find($id); | $wallet = Wallet::find($id); | ||||
if (empty($wallet)) { | if (empty($wallet) || !$this->checkTenant($wallet->owner)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!Auth::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 = \App\Providers\PaymentProvider::factory($wallet); | ||||
$result['provider'] = $provider->name(); | $result['provider'] = $provider->name(); | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | class WalletsController extends Controller | ||||
* @param string $receipt Receipt identifier (YYYY-MM) | * @param string $receipt Receipt identifier (YYYY-MM) | ||||
* | * | ||||
* @return \Illuminate\Http\Response | * @return \Illuminate\Http\Response | ||||
*/ | */ | ||||
public function receiptDownload($id, $receipt) | public function receiptDownload($id, $receipt) | ||||
{ | { | ||||
$wallet = Wallet::find($id); | $wallet = Wallet::find($id); | ||||
if (empty($wallet) || !$this->checkTenant($wallet->owner)) { | |||||
return $this->errorResponse(404); | |||||
} | |||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!Auth::guard()->user()->canRead($wallet)) { | if (!$this->guard()->user()->canRead($wallet)) { | ||||
abort(403); | abort(403); | ||||
} | } | ||||
list ($year, $month) = explode('-', $receipt); | list ($year, $month) = explode('-', $receipt); | ||||
if (empty($year) || empty($month) || $year < 2000 || $month < 1 || $month > 12) { | if (empty($year) || empty($month) || $year < 2000 || $month < 1 || $month > 12) { | ||||
abort(404); | abort(404); | ||||
} | } | ||||
Show All 27 Lines | class WalletsController extends Controller | ||||
* @param string $id Wallet identifier | * @param string $id Wallet identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function receipts($id) | public function receipts($id) | ||||
{ | { | ||||
$wallet = Wallet::find($id); | $wallet = Wallet::find($id); | ||||
if (empty($wallet) || !$this->checkTenant($wallet->owner)) { | |||||
return $this->errorResponse(404); | |||||
} | |||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!Auth::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', PaymentProvider::STATUS_PAID) | ||||
->where('amount', '<>', 0) | ->where('amount', '<>', 0) | ||||
->orderBy('ident', 'desc') | ->orderBy('ident', 'desc') | ||||
Show All 16 Lines | class WalletsController extends Controller | ||||
* @param string $id Wallet identifier | * @param string $id Wallet identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function transactions($id) | public function transactions($id) | ||||
{ | { | ||||
$wallet = Wallet::find($id); | $wallet = Wallet::find($id); | ||||
if (empty($wallet) || !$this->checkTenant($wallet->owner)) { | |||||
return $this->errorResponse(404); | |||||
} | |||||
// Only owner (or admin) has access to the wallet | // Only owner (or admin) has access to the wallet | ||||
if (!Auth::guard()->user()->canRead($wallet)) { | if (!$this->guard()->user()->canRead($wallet)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$pageSize = 10; | $pageSize = 10; | ||||
$page = intval(request()->input('page')) ?: 1; | $page = intval(request()->input('page')) ?: 1; | ||||
$hasMore = false; | $hasMore = false; | ||||
$isAdmin = $this instanceof Admin\WalletsController; | $isAdmin = $this instanceof Admin\WalletsController; | ||||
▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines |