From 0eaaca98d17c1e60a27d254e84139239a5617f24 Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Mon, 1 Jul 2024 01:31:59 +0600 Subject: [PATCH] assign vendor process testing --- routes/api.php | 19 ++- src/Contracts/OrderQuotation.php | 5 +- src/Contracts/ProceedOrder.php | 12 ++ src/Facades/Remit.php | 2 + .../Controllers/AssignVendorController.php | 146 ++++++++++++------ .../Resources/AssignableVendorCollection.php | 17 -- src/Remit.php | 9 ++ src/Services/AssignVendorService.php | 109 +++++++++++++ src/Vendors/AgraniBankApi.php | 15 +- src/Vendors/CityBankApi.php | 2 +- src/Vendors/EmqApi.php | 8 +- src/Vendors/IslamiBankApi.php | 44 ++++-- src/Vendors/TransFastApi.php | 13 +- src/Vendors/ValYouApi.php | 13 +- 14 files changed, 323 insertions(+), 91 deletions(-) create mode 100644 src/Contracts/ProceedOrder.php create mode 100644 src/Services/AssignVendorService.php diff --git a/routes/api.php b/routes/api.php index c567177..cb83a9d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -24,8 +24,23 @@ Route::prefix('remit')->name('remit.') ->middleware(config('fintech.auth.middleware'))->group(function () { if (Core::packageExists('Transaction')) { - Route::get('assignable-vendors/{order_id}', [AssignVendorController::class, 'available']) - ->name('assignable-vendors.available'); + Route::get('assign-vendors/available/{order_id}', [AssignVendorController::class, 'available']) + ->name('assign-vendors.available'); + + Route::post('assign-vendors/quote', [AssignVendorController::class, 'vendor']) + ->name('assign-vendors.quota'); + + Route::post('assign-vendors/process', [AssignVendorController::class, 'process']) + ->name('assign-vendors.process'); + + Route::post('assign-vendors/status', [AssignVendorController::class, 'status']) + ->name('assign-vendors.status'); + + Route::post('assign-vendors/release', [AssignVendorController::class, 'release']) + ->name('assign-vendors.release'); + + Route::post('assign-vendors/cancel', [AssignVendorController::class, 'cancel']) + ->name('assign-vendors.cancel'); } Route::apiResource('bank-transfers', BankTransferController::class)->except('update', 'destroy'); Route::group(['prefix' => 'bank-transfers'], function () { diff --git a/src/Contracts/OrderQuotation.php b/src/Contracts/OrderQuotation.php index fa7629d..303484f 100644 --- a/src/Contracts/OrderQuotation.php +++ b/src/Contracts/OrderQuotation.php @@ -2,12 +2,11 @@ namespace Fintech\Remit\Contracts; -use MongoDB\Laravel\Eloquent\Model; interface OrderQuotation { /** - * @param \Illuminate\Database\Eloquent\Model|Model $order + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order */ - public function requestQuotation($order): mixed; + public function requestQuote($order): mixed; } diff --git a/src/Contracts/ProceedOrder.php b/src/Contracts/ProceedOrder.php new file mode 100644 index 0000000..09e830c --- /dev/null +++ b/src/Contracts/ProceedOrder.php @@ -0,0 +1,12 @@ +find($id); + + if (!$order) { + throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $id); + } + + return $order; + } + /** * Store a newly created resource in storage. */ public function available(string $id): JsonResponse|AssignableVendorCollection { try { - $order = Transaction::order()->find($id); - if (! $order) { - throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $id); - } + $order = $this->getOrder($id); - $serviceVendors = Business::serviceVendor()->list([ - 'service_id_array' => [$order->service_id], - 'enabled' => true, - 'paginate' => false, - ]); + $serviceVendors = Remit::assignVendor()->availableVendors($order); return new AssignableVendorCollection($serviceVendors); @@ -57,29 +61,34 @@ public function vendor(AssignableVendorInfoRequest $request): JsonResponse $service_vendor_slug = $request->input('vendor_slug'); try { - $order = Transaction::order()->find($order_id); - if (! $order) { - throw (new ModelNotFoundException)->setModel(config('fintech.transaction.order_model'), $order_id); - } + $order = $this->getOrder($order_id); - $availableVendors = config('fintech.remit.providers'); + $jsonResponse = Remit::assignVendor()->requestQuote($order, $service_vendor_slug); - if (! isset($availableVendors[$service_vendor_slug])) { - throw new ErrorException('Service Vendor is not available on the configuration.'); - } + return response()->success($jsonResponse); - $vendor = $availableVendors[$service_vendor_slug]; + } catch (ModelNotFoundException $exception) { - $driverClass = $vendor['driver']; + return response()->notfound($exception->getMessage()); + + } catch (Exception $exception) { - $instance = App::make($driverClass); + return response()->failed($exception->getMessage()); + } + } + + public function process(AssignableVendorInfoRequest $request): JsonResponse + { + $order_id = $request->input('order_id'); + + $service_vendor_slug = $request->input('vendor_slug'); + + try { - if (! $instance instanceof OrderQuotation) { - throw new ErrorException('Service Vendor Class is not instance of `Fintech\Remit\Contracts\OrderQuotation` interface.'); - } + $order = $this->getOrder($order_id); - $jsonResponse = $instance->requestQuotation($order); + $jsonResponse = Remit::assignVendor()->requestQuote($order, $service_vendor_slug); return response()->success($jsonResponse); @@ -93,40 +102,75 @@ public function vendor(AssignableVendorInfoRequest $request): JsonResponse } } - /** - * Show the form for editing the specified resource. - */ - public function edit(string $id) + public function status(AssignableVendorInfoRequest $request): JsonResponse { - // - } + $order_id = $request->input('order_id'); - /** - * Update the specified resource in storage. - */ - public function update(Request $request, string $id) - { - // - } + $service_vendor_slug = $request->input('vendor_slug'); - /** - * Remove the specified resource from storage. - */ - public function destroy(string $id) - { - // + try { + + $order = $this->getOrder($order_id); + + $jsonResponse = Remit::assignVendor()->requestQuote($order, $service_vendor_slug); + + return response()->success($jsonResponse); + + } catch (ModelNotFoundException $exception) { + + return response()->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return response()->failed($exception->getMessage()); + } } - private function defaultVendorData(): array + public function release(AssignableVendorInfoRequest $request): JsonResponse { - return [ - 'balance' => 'test', - 'approved' => true, - ]; + $order_id = $request->input('order_id'); + + $service_vendor_slug = $request->input('vendor_slug'); + + try { + + $order = $this->getOrder($order_id); + + $jsonResponse = Remit::assignVendor()->requestQuote($order, $service_vendor_slug); + + return response()->success($jsonResponse); + + } catch (ModelNotFoundException $exception) { + + return response()->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return response()->failed($exception->getMessage()); + } } - private function cityBankVendorData(): array + public function cancel(AssignableVendorInfoRequest $request): JsonResponse { + $order_id = $request->input('order_id'); + + $service_vendor_slug = $request->input('vendor_slug'); + + try { + + $order = $this->getOrder($order_id); + + $jsonResponse = Remit::assignVendor()->requestQuote($order, $service_vendor_slug); + return response()->success($jsonResponse); + + } catch (ModelNotFoundException $exception) { + + return response()->notfound($exception->getMessage()); + + } catch (Exception $exception) { + + return response()->failed($exception->getMessage()); + } } } diff --git a/src/Http/Resources/AssignableVendorCollection.php b/src/Http/Resources/AssignableVendorCollection.php index bca8192..2ee283c 100644 --- a/src/Http/Resources/AssignableVendorCollection.php +++ b/src/Http/Resources/AssignableVendorCollection.php @@ -28,21 +28,4 @@ public function toArray($request) ]; })->toArray(); } - - /** - * Get additional data that should be returned with the resource array. - * - * @return array - */ - public function with(Request $request): array - { - return [ - 'options' => [ - 'dir' => Constant::SORT_DIRECTIONS, - 'per_page' => Constant::PAGINATE_LENGTHS, - 'sort' => ['id', 'name', 'created_at', 'updated_at'], - ], - 'query' => $request->all(), - ]; - } } diff --git a/src/Remit.php b/src/Remit.php index 541d8cc..e589d88 100644 --- a/src/Remit.php +++ b/src/Remit.php @@ -2,6 +2,7 @@ namespace Fintech\Remit; +use Fintech\Remit\Services\AssignVendorService; use Fintech\Remit\Services\BankTransferService; use Fintech\Remit\Services\CashPickupService; use Fintech\Remit\Services\WalletTransferService; @@ -32,6 +33,14 @@ public function walletTransfer() return app(WalletTransferService::class); } + /** + * @return AssignVendorService + */ + public function assignVendor() + { + return app(AssignVendorService::class); + } + //** Crud Service Method Point Do not Remove **// } diff --git a/src/Services/AssignVendorService.php b/src/Services/AssignVendorService.php new file mode 100644 index 0000000..6c76a0d --- /dev/null +++ b/src/Services/AssignVendorService.php @@ -0,0 +1,109 @@ +list([ + 'service_id_array' => [$order->service_id], + 'enabled' => true, + 'paginate' => false, + ]); + } + + /** + * @throws ErrorException + */ + public function requestQuote(BaseModel $order, string $vendor_slug): mixed + { + $availableVendors = config('fintech.remit.providers', []); + + if (!isset($availableVendors[$vendor_slug])) { + throw new ErrorException('Service Vendor is not available on the configuration.'); + } + + $vendor = $availableVendors[$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.'); + } + + return $instance->requestQuote($order); + } + + public function processOrder(BaseModel $order, string $vendor_slug): mixed + { + $availableVendors = config('fintech.remit.providers', []); + + if (!isset($availableVendors[$vendor_slug])) { + throw new ErrorException('Service Vendor is not available on the configuration.'); + } + + $vendor = $availableVendors[$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.'); + } + + return $instance->requestQuote($order); + } + + public function orderStatus(BaseModel $order, string $vendor_slug): mixed + { + $availableVendors = config('fintech.remit.providers', []); + + if (!isset($availableVendors[$vendor_slug])) { + throw new ErrorException('Service Vendor is not available on the configuration.'); + } + + $vendor = $availableVendors[$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.'); + } + + return $instance->requestQuote($order); + } + + public function cancelOrder(BaseModel $order, string $vendor_slug): mixed + { + $availableVendors = config('fintech.remit.providers', []); + + if (!isset($availableVendors[$vendor_slug])) { + throw new ErrorException('Service Vendor is not available on the configuration.'); + } + + $vendor = $availableVendors[$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.'); + } + + return $instance->requestQuote($order); + } +} diff --git a/src/Vendors/AgraniBankApi.php b/src/Vendors/AgraniBankApi.php index 95a757e..e3dee5e 100644 --- a/src/Vendors/AgraniBankApi.php +++ b/src/Vendors/AgraniBankApi.php @@ -2,16 +2,15 @@ namespace Fintech\Remit\Vendors; -use App\Services\Backend\Setting\CatalogListService; -use App\Services\Backend\Setting\CountryService; use Carbon\Carbon; use DOMDocument; use DOMException; use Exception; +use Fintech\Remit\Contracts\OrderQuotation; use Illuminate\Support\Facades\Log; use stdClass; -class AgraniBankApi +class AgraniBankApi implements OrderQuotation { const OCCUPATION = 'OCC'; @@ -622,4 +621,14 @@ public function getData($url, $params = []) ]; } + + /** + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order + */ + public function requestQuote($order): mixed + { + return [ + + ]; + } } diff --git a/src/Vendors/CityBankApi.php b/src/Vendors/CityBankApi.php index b34fb52..26545c4 100644 --- a/src/Vendors/CityBankApi.php +++ b/src/Vendors/CityBankApi.php @@ -623,7 +623,7 @@ public function verifyAccount(array $accountInfo = []): mixed * * @throws Exception */ - public function requestQuotation($order): mixed + public function requestQuote($order): mixed { return $this->vendorBalance(); } diff --git a/src/Vendors/EmqApi.php b/src/Vendors/EmqApi.php index 4d7085e..6a99ffc 100644 --- a/src/Vendors/EmqApi.php +++ b/src/Vendors/EmqApi.php @@ -1350,11 +1350,13 @@ public function vendorBalance(array $accountInfo = []): mixed } /** - * @param \Illuminate\Database\Eloquent\Model|Model $order + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order */ - public function requestQuotation($order): mixed + public function requestQuote($order): mixed { - // TODO: Implement requestQuotation() method. + return [ + + ]; } protected function getBalanceFromCurrency(string $currency, $response) diff --git a/src/Vendors/IslamiBankApi.php b/src/Vendors/IslamiBankApi.php index 100184b..817c8fc 100644 --- a/src/Vendors/IslamiBankApi.php +++ b/src/Vendors/IslamiBankApi.php @@ -6,9 +6,10 @@ use Fintech\Core\Supports\Utility; use Fintech\Remit\Contracts\BankTransfer; use Fintech\Remit\Contracts\OrderQuotation; +use Fintech\Remit\Contracts\ProceedOrder; use Illuminate\Support\Facades\Http; -class IslamiBankApi implements BankTransfer, OrderQuotation +class IslamiBankApi implements BankTransfer, OrderQuotation, ProceedOrder { /** * IslamiBank API configuration. @@ -94,7 +95,7 @@ public function fetchAccountDetail(array $data): array private function connectionCheck($xml_post_string, $method): array { $xml_string = $this->xmlGenerate($xml_post_string, $method); - dump($method.'
'.$xml_string); + $response = Http::soap($this->apiUrl, $method, $xml_string); // $headers = [ @@ -854,9 +855,23 @@ public function fetchBalance(string $currency): array return $return; } - public function requestQuotation($order): array + /** + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order + * @throws Exception + */ + public function requestQuote($order): mixed { - return []; + return $this->fetchBalance('BDT'); + } + + /** + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order + */ + public function processOrder($order): mixed + { + return [ + + ]; } /** @@ -899,12 +914,23 @@ private function __beneficiaryIdentityTypeCode(int|string $code, string $flag = if ($flag == 'value') { $return = [ - 1 => 'Passport', 2 => 'Cheque', 3 => 'Photo', 4 => 'Finger Print', - 5 => 'Introducer', 6 => 'Driving License', 7 => 'Other', 8 => 'Remittance Card', - 9 => 'National ID', 9 => 'National ID Card', 9 => 'National Identity Card', - 9 => 'Voter ID', 9 => 'Voter ID Card', 9 => 'Voter Identity Card', + 1 => 'Passport', + 2 => 'Cheque', + 3 => 'Photo', + 4 => 'Finger Print', + 5 => 'Introducer', + 6 => 'Driving License', + 7 => 'Other', + 8 => 'Remittance Card', + 9 => 'National ID', + 9 => 'National ID Card', + 9 => 'National Identity Card', + 9 => 'Voter ID', + 9 => 'Voter ID Card', + 9 => 'Voter Identity Card', 10 => 'Birth Certificate', - 11 => 'Student ID Card', 11 => 'Student Identity Card', + 11 => 'Student ID Card', + 11 => 'Student Identity Card', ]; $return = array_flip($return); } diff --git a/src/Vendors/TransFastApi.php b/src/Vendors/TransFastApi.php index 8177732..9bc9b4e 100644 --- a/src/Vendors/TransFastApi.php +++ b/src/Vendors/TransFastApi.php @@ -3,9 +3,10 @@ namespace Fintech\Remit\Vendors; use Exception; +use Fintech\Remit\Contracts\OrderQuotation; use Illuminate\Support\Facades\Log; -class TransFastApi +class TransFastApi implements OrderQuotation { protected $payment_mode; @@ -975,4 +976,14 @@ public function postCreateTransaction($data) //dd($params); return $this->putPostData($url, $params); } + + /** + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order + */ + public function requestQuote($order): mixed + { + return [ + + ]; + } } diff --git a/src/Vendors/ValYouApi.php b/src/Vendors/ValYouApi.php index 02224e1..0fa7c00 100644 --- a/src/Vendors/ValYouApi.php +++ b/src/Vendors/ValYouApi.php @@ -3,10 +3,11 @@ namespace Fintech\Remit\Vendors; use Exception; +use Fintech\Remit\Contracts\OrderQuotation; use Illuminate\Support\Facades\Log; use SimpleXMLElement; -class ValYouApi +class ValYouApi implements OrderQuotation { /** * @var string @@ -663,4 +664,14 @@ public function authorizedConfirmed($input_data) return json_decode(json_encode($response->Authorized_ConfirmedResponse->Authorized_ConfirmedResult), true); } + + /** + * @param \Illuminate\Database\Eloquent\Model|\Fintech\Core\Abstracts\BaseModel $order + */ + public function requestQuote($order): mixed + { + return [ + + ]; + } }