Skip to content

Commit

Permalink
order quotation check added
Browse files Browse the repository at this point in the history
  • Loading branch information
hafijul233 committed Feb 15, 2024
1 parent 036c6b6 commit 18614c4
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 273 deletions.
10 changes: 5 additions & 5 deletions src/Contracts/BankTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ interface BankTransfer
/**
* Execute the transfer operation
*/
public function makeTransfer(array $orderInfo): mixed;
public function makeTransfer(array $orderInfo = []): mixed;

public function transferStatus(array $orderInfo): mixed;
public function transferStatus(array $orderInfo = []): mixed;

public function cancelTransfer(array $orderInfo): mixed;
public function cancelTransfer(array $orderInfo = []): mixed;

public function verifyAccount(array $accountInfo): mixed;
public function verifyAccount(array $accountInfo = []): mixed;

public function vendorBalance(array $accountInfo): mixed;
public function vendorBalance(array $accountInfo = []): mixed;
}
12 changes: 12 additions & 0 deletions src/Contracts/OrderQuotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Fintech\Remit\Contracts;

interface OrderQuotation
{
/**
* @param \Illuminate\Database\Eloquent\Model|\MongoDB\Laravel\Eloquent\Model $order
* @return mixed
*/
public function requestQuotation($order): mixed;
}
28 changes: 22 additions & 6 deletions src/Http/Controllers/AssignVendorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use App\Http\Controllers\Controller;
use Exception;
use Fintech\Core\Traits\ApiResponseTrait;
use Fintech\Remit\Contracts\OrderQuotation;
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\Facades\App;

class AssignVendorController extends Controller
{
Expand All @@ -24,7 +26,7 @@ public function available(string $id): JsonResponse|AssignableVendorCollection
try {
$order = Transaction::order()->find($id);

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

Expand All @@ -51,20 +53,34 @@ public function available(string $id): JsonResponse|AssignableVendorCollection
*/
public function vendor(AssignableVendorInfoRequest $request): JsonResponse
{
$order_id = $request->input('order_id');

$service_vendor_slug = $request->input('vendor_slug');

try {
$order = Transaction::order()->find($request->input('order_id'));
$order = Transaction::order()->find($order_id);

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

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

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

$jsonResponse = [];
$vendor = $availableVendors[$service_vendor_slug];

$driverClass = $vendor['driver'];

$instance = App::make($driverClass);

if (!$instance instanceof OrderQuotation) {
throw new \ErrorException('Service Vendor Class is not instance of `Fintech\Remit\Contracts\OrderQuotation` interface.');
}

$jsonResponse = $instance->requestQuotation($order);

return $this->success($jsonResponse);

Expand Down
Loading

0 comments on commit 18614c4

Please sign in to comment.