Skip to content

Commit 92505c9

Browse files
committed
code formatted and optimized
1 parent 9743483 commit 92505c9

22 files changed

+219
-203
lines changed

config/tab.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

33
// config for Fintech/Tab
4+
use Fintech\Tab\Models\PayBill;
5+
use Fintech\Tab\Repositories\Eloquent\PayBillRepository;
6+
47
return [
58

69
/*
@@ -31,7 +34,7 @@
3134
|
3235
| This value will be used to across system where model is needed
3336
*/
34-
'pay_bill_model' => \Fintech\Tab\Models\PayBill::class,
37+
'pay_bill_model' => PayBill::class,
3538

3639
//** Model Config Point Do not Remove **//
3740

@@ -44,9 +47,9 @@
4447
*/
4548

4649
'repositories' => [
47-
\Fintech\Tab\Interfaces\PayBillRepository::class => \Fintech\Tab\Repositories\Eloquent\PayBillRepository::class,
50+
\Fintech\Tab\Interfaces\PayBillRepository::class => PayBillRepository::class,
4851

49-
\Fintech\Tab\Interfaces\PayBillRepository::class => \Fintech\Tab\Repositories\Eloquent\PayBillRepository::class,
52+
\Fintech\Tab\Interfaces\PayBillRepository::class => PayBillRepository::class,
5053

5154
//** Repository Binding Config Point Do not Remove **//
5255
],

routes/api.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Fintech\Tab\Http\Controllers\PayBillController;
34
use Illuminate\Support\Facades\Config;
45
use Illuminate\Support\Facades\Route;
56

@@ -16,8 +17,8 @@
1617
if (Config::get('fintech.tab.enabled')) {
1718
Route::prefix('tab')->name('tab.')->group(function () {
1819

19-
Route::apiResource('pay-bills', \Fintech\Tab\Http\Controllers\PayBillController::class);
20-
Route::post('pay-bills/{pay_bill}/restore', [\Fintech\Tab\Http\Controllers\PayBillController::class, 'restore'])->name('pay-bills.restore');
20+
Route::apiResource('pay-bills', PayBillController::class);
21+
Route::post('pay-bills/{pay_bill}/restore', [PayBillController::class, 'restore'])->name('pay-bills.restore');
2122

2223
//DO NOT REMOVE THIS LINE//
2324
});

src/Exceptions/TabException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class TabException extends Exception
1313
/**
1414
* CoreException constructor.
1515
*
16-
* @param string $message
17-
* @param int $code
16+
* @param string $message
17+
* @param int $code
1818
*/
1919
public function __construct($message = '', $code = 0, ?Throwable $previous = null)
2020
{

src/Facades/Tab.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace Fintech\Tab\Facades;
44

5+
use Fintech\Tab\Services\PayBillService;
56
use Illuminate\Support\Facades\Facade;
67

78
/**
8-
* @method static \Fintech\Tab\Services\PayBillService payBill()
9+
* @method static PayBillService payBill()
910
* // Crud Service Method Point Do not Remove //
1011
*
1112
* @see \Fintech\Tab\Tab

src/Http/Controllers/PayBillController.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function store(StorePayBillRequest $request): JsonResponse
8585
'country_id' => $request->input('source_country_id', $depositor->profile?->country_id),
8686
])->first();
8787

88-
if (! $depositAccount) {
88+
if (!$depositAccount) {
8989
throw new Exception("User don't have account deposit balance");
9090
}
9191

@@ -94,8 +94,8 @@ public function store(StorePayBillRequest $request): JsonResponse
9494
'country_id' => $request->input('source_country_id', $depositor->profile?->country_id),
9595
])->first();
9696

97-
if (! $masterUser) {
98-
throw new Exception('Master User Account not found for '.$request->input('source_country_id', $depositor->profile?->country_id).' country');
97+
if (!$masterUser) {
98+
throw new Exception('Master User Account not found for ' . $request->input('source_country_id', $depositor->profile?->country_id) . ' country');
9999
}
100100

101101
//set pre defined conditions of deposit
@@ -125,7 +125,7 @@ public function store(StorePayBillRequest $request): JsonResponse
125125

126126
$payBill = Tab::payBill()->create($inputs);
127127

128-
if (! $payBill) {
128+
if (!$payBill) {
129129
throw (new StoreOperationException)->setModel(config('fintech.tab.pay_bill_model'));
130130
}
131131
$order_data = $payBill->order_data;
@@ -141,20 +141,20 @@ public function store(StorePayBillRequest $request): JsonResponse
141141
])->first();
142142
//update User Account
143143
$depositedUpdatedAccount = $depositedAccount->toArray();
144-
$depositedUpdatedAccount['user_account_data']['spent_amount'] = (float) $depositedUpdatedAccount['user_account_data']['spent_amount'] + (float) $userUpdatedBalance['spent_amount'];
145-
$depositedUpdatedAccount['user_account_data']['available_amount'] = (float) $userUpdatedBalance['current_amount'];
146-
if (((float) $depositedUpdatedAccount['user_account_data']['available_amount']) < ((float) config('fintech.transaction.minimum_balance'))) {
144+
$depositedUpdatedAccount['user_account_data']['spent_amount'] = (float)$depositedUpdatedAccount['user_account_data']['spent_amount'] + (float)$userUpdatedBalance['spent_amount'];
145+
$depositedUpdatedAccount['user_account_data']['available_amount'] = (float)$userUpdatedBalance['current_amount'];
146+
if (((float)$depositedUpdatedAccount['user_account_data']['available_amount']) < ((float)config('fintech.transaction.minimum_balance'))) {
147147
throw new Exception(__('Insufficient balance!', [
148-
'previous_amount' => ((float) $depositedUpdatedAccount['user_account_data']['available_amount']),
149-
'current_amount' => ((float) $userUpdatedBalance['spent_amount']),
148+
'previous_amount' => ((float)$depositedUpdatedAccount['user_account_data']['available_amount']),
149+
'current_amount' => ((float)$userUpdatedBalance['spent_amount']),
150150
]));
151151
}
152-
$order_data['order_data']['previous_amount'] = (float) $depositedAccount->user_account_data['available_amount'];
153-
$order_data['order_data']['current_amount'] = (float) $userUpdatedBalance['current_amount'];
154-
if (! Transaction::userAccount()->update($depositedAccount->getKey(), $depositedUpdatedAccount)) {
152+
$order_data['order_data']['previous_amount'] = (float)$depositedAccount->user_account_data['available_amount'];
153+
$order_data['order_data']['current_amount'] = (float)$userUpdatedBalance['current_amount'];
154+
if (!Transaction::userAccount()->update($depositedAccount->getKey(), $depositedUpdatedAccount)) {
155155
throw new Exception(__('User Account Balance does not update', [
156-
'previous_amount' => ((float) $depositedUpdatedAccount['user_account_data']['available_amount']),
157-
'current_amount' => ((float) $userUpdatedBalance['spent_amount']),
156+
'previous_amount' => ((float)$depositedUpdatedAccount['user_account_data']['available_amount']),
157+
'current_amount' => ((float)$userUpdatedBalance['spent_amount']),
158158
]));
159159
}
160160
Tab::payBill()->update($payBill->getKey(), ['order_data' => $order_data, 'order_number' => $order_data['purchase_number']]);
@@ -179,23 +179,28 @@ public function store(StorePayBillRequest $request): JsonResponse
179179

180180
/**
181181
* @lrd:start
182-
* Return a specified *PayBill* resource found by id.
182+
* Update a specified *PayBill* resource using id.
183183
*
184184
* @lrd:end
185-
*
186-
* @throws ModelNotFoundException
187185
*/
188-
public function show(string|int $id): PayBillResource|JsonResponse
186+
public function update(UpdatePayBillRequest $request, string|int $id): JsonResponse
189187
{
190188
try {
191189

192190
$payBill = Tab::payBill()->find($id);
193191

194-
if (! $payBill) {
192+
if (!$payBill) {
195193
throw (new ModelNotFoundException)->setModel(config('fintech.tab.pay_bill_model'), $id);
196194
}
197195

198-
return new PayBillResource($payBill);
196+
$inputs = $request->validated();
197+
198+
if (!Tab::payBill()->update($id, $inputs)) {
199+
200+
throw (new UpdateOperationException)->setModel(config('fintech.tab.pay_bill_model'), $id);
201+
}
202+
203+
return $this->updated(__('core::messages.resource.updated', ['model' => 'Pay Bill']));
199204

200205
} catch (ModelNotFoundException $exception) {
201206

@@ -209,28 +214,23 @@ public function show(string|int $id): PayBillResource|JsonResponse
209214

210215
/**
211216
* @lrd:start
212-
* Update a specified *PayBill* resource using id.
217+
* Return a specified *PayBill* resource found by id.
213218
*
214219
* @lrd:end
220+
*
221+
* @throws ModelNotFoundException
215222
*/
216-
public function update(UpdatePayBillRequest $request, string|int $id): JsonResponse
223+
public function show(string|int $id): PayBillResource|JsonResponse
217224
{
218225
try {
219226

220227
$payBill = Tab::payBill()->find($id);
221228

222-
if (! $payBill) {
229+
if (!$payBill) {
223230
throw (new ModelNotFoundException)->setModel(config('fintech.tab.pay_bill_model'), $id);
224231
}
225232

226-
$inputs = $request->validated();
227-
228-
if (! Tab::payBill()->update($id, $inputs)) {
229-
230-
throw (new UpdateOperationException)->setModel(config('fintech.tab.pay_bill_model'), $id);
231-
}
232-
233-
return $this->updated(__('core::messages.resource.updated', ['model' => 'Pay Bill']));
233+
return new PayBillResource($payBill);
234234

235235
} catch (ModelNotFoundException $exception) {
236236

@@ -254,11 +254,11 @@ public function destroy(string|int $id): JsonResponse
254254

255255
$payBill = Tab::payBill()->find($id);
256256

257-
if (! $payBill) {
257+
if (!$payBill) {
258258
throw (new ModelNotFoundException)->setModel(config('fintech.tab.pay_bill_model'), $id);
259259
}
260260

261-
if (! Tab::payBill()->destroy($id)) {
261+
if (!Tab::payBill()->destroy($id)) {
262262

263263
throw (new DeleteOperationException())->setModel(config('fintech.tab.pay_bill_model'), $id);
264264
}
@@ -288,11 +288,11 @@ public function restore(string|int $id): JsonResponse
288288

289289
$payBill = Tab::payBill()->find($id, true);
290290

291-
if (! $payBill) {
291+
if (!$payBill) {
292292
throw (new ModelNotFoundException)->setModel(config('fintech.tab.pay_bill_model'), $id);
293293
}
294294

295-
if (! Tab::payBill()->restore($id)) {
295+
if (!Tab::payBill()->restore($id)) {
296296

297297
throw (new RestoreOperationException())->setModel(config('fintech.tab.pay_bill_model'), $id);
298298
}

src/Http/Requests/ImportPayBillRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Fintech\Tab\Http\Requests;
44

5+
use Illuminate\Contracts\Validation\ValidationRule;
56
use Illuminate\Foundation\Http\FormRequest;
67

78
class ImportPayBillRequest extends FormRequest
@@ -17,7 +18,7 @@ public function authorize(): bool
1718
/**
1819
* Get the validation rules that apply to the request.
1920
*
20-
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
21+
* @return array<string, ValidationRule|array|string>
2122
*/
2223
public function rules(): array
2324
{

src/Http/Requests/StorePayBillRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function rules(): array
2828
'source_country_id' => ['required', 'integer', 'min:1'],
2929
'destination_country_id' => ['required', 'integer', 'min:1'],
3030
'service_id' => ['required', 'integer', 'min:1'],
31-
'ordered_at' => ['required', 'date', 'date_format:Y-m-d H:i:s', 'before_or_equal:'.date('Y-m-d H:i:s')],
31+
'ordered_at' => ['required', 'date', 'date_format:Y-m-d H:i:s', 'before_or_equal:' . date('Y-m-d H:i:s')],
3232
'amount' => ['required', 'numeric'],
3333
'currency' => ['required', 'string', 'size:3'],
3434
'converted_currency' => ['required', 'string', 'size:3'],

src/Http/Requests/UpdatePayBillRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Fintech\Tab\Http\Requests;
44

5+
use Illuminate\Contracts\Validation\ValidationRule;
56
use Illuminate\Foundation\Http\FormRequest;
67

78
class UpdatePayBillRequest extends FormRequest
@@ -17,7 +18,7 @@ public function authorize(): bool
1718
/**
1819
* Get the validation rules that apply to the request.
1920
*
20-
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
21+
* @return array<string, ValidationRule|array|string>
2122
*/
2223
public function rules(): array
2324
{

src/Http/Resources/PayBillCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PayBillCollection extends ResourceCollection
1212
/**
1313
* Transform the resource collection into an array.
1414
*
15-
* @param Request $request
15+
* @param Request $request
1616
* @return array
1717
*/
1818
public function toArray($request)

src/Http/Resources/PayBillResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
namespace Fintech\Tab\Http\Resources;
44

55
use Fintech\Core\Facades\Core;
6+
use Illuminate\Http\Request;
67
use Illuminate\Http\Resources\Json\JsonResource;
78

89
class PayBillResource extends JsonResource
910
{
1011
/**
1112
* Transform the resource into an array.
1213
*
13-
* @param \Illuminate\Http\Request
14+
* @param Request
1415
* @return array
1516
*/
1617
public function toArray($request)

0 commit comments

Comments
 (0)