Skip to content

Commit

Permalink
service provider updated
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Feb 14, 2024
1 parent 77f9c20 commit a87b7e3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
51 changes: 46 additions & 5 deletions src/Http/Controllers/AssignVendorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
use App\Http\Controllers\Controller;
use Exception;
use Fintech\Core\Traits\ApiResponseTrait;
use Fintech\Remit\Facades\Remit;
use Fintech\Remit\Http\Requests\AssignableVendorInfoRequest;
use Fintech\Remit\Http\Resources\AssignableVendorCollection;
use Fintech\Transaction\Facades\Transaction;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class AssignVendorController extends Controller
{
Expand All @@ -16,10 +21,9 @@ class AssignVendorController extends Controller
/**
* Store a newly created resource in storage.
*/
public function available(string $id): \Illuminate\Http\JsonResponse|\Fintech\Remit\Http\Resources\AssignableVendorCollection
public function available(string $id): JsonResponse|AssignableVendorCollection
{
try {

$order = Transaction::order()->find($id);

if (! $order) {
Expand All @@ -32,7 +36,7 @@ public function available(string $id): \Illuminate\Http\JsonResponse|\Fintech\Re
'paginate' => false,
]);

return new \Fintech\Remit\Http\Resources\AssignableVendorCollection($serviceVendors);
return new AssignableVendorCollection($serviceVendors);

} catch (ModelNotFoundException $exception) {

Expand All @@ -47,9 +51,46 @@ public function available(string $id): \Illuminate\Http\JsonResponse|\Fintech\Re
/**
* Display the specified resource.
*/
public function show(string $id)
public function vendor(AssignableVendorInfoRequest $request):JsonResponse
{
//
try {
$order = Transaction::order()->find($request->input('order_id'));

if (! $order) {
throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $request->input('order_id'));
}

$availableVendors = config('fintech.remit.providers');

if (!array_key_exists($request->input('vendor_slug'), $availableVendors)) {
throw new \ErrorException('Service Vendor is not available on the configuration.');
}

$jsonResponse = [];

return $this->success($jsonResponse);

} catch (ModelNotFoundException $exception) {

return $this->notfound($exception->getMessage());

} catch (Exception $exception) {

return $this->failed($exception->getMessage());
}
}

private function defaultVendorData(): array
{
return [
'balance' => 'test',
'approved' => true
];
}

private function cityBankVendorData(): array
{
return ;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Http/Requests/AssignableVendorInfoRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Fintech\Remit\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AssignableVendorInfoRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'order_id' => ['required', 'min:1', 'integer'],
'vendor_slug' => ['required', 'string', 'min:1'],
];
}
}
2 changes: 2 additions & 0 deletions src/Remit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Fintech\Remit;

use Fintech\Remit\Vendors\CityBankApi;

class Remit
{
/**
Expand Down

0 comments on commit a87b7e3

Please sign in to comment.