nikarayan and payment service
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\PaymentService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Province;
|
||||
use App\Models\City;
|
||||
@@ -353,10 +354,10 @@ class ReceiptController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
public function invoiceBill(Request $request, Accident $accident)
|
||||
public function invoiceBill(Request $request, Accident $accident, PaymentService $paymentService)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($request, $accident) {
|
||||
DB::transaction(function () use ($request, $accident, $paymentService) {
|
||||
|
||||
$final_amount = $accident->sum - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount);
|
||||
|
||||
@@ -366,7 +367,7 @@ class ReceiptController extends Controller
|
||||
|
||||
$accident->final_amount = $final_amount;
|
||||
|
||||
$accident->bill_code = $this->invoiceBillApi($accident->driver_national_code, $final_amount);
|
||||
$accident->bill_code = $paymentService->invoiceBillApi($accident->driver_national_code, $final_amount);
|
||||
|
||||
$accident->invoiceBill();
|
||||
|
||||
@@ -396,13 +397,13 @@ class ReceiptController extends Controller
|
||||
return $msg;
|
||||
}
|
||||
|
||||
public function callPaymentStatus(Request $request, Accident $accident)
|
||||
public function callPaymentStatus(Request $request, Accident $accident, PaymentService $paymentService)
|
||||
{
|
||||
try {
|
||||
DB::transaction(function () use ($request, $accident) {
|
||||
DB::transaction(function () use ($request, $accident, $paymentService) {
|
||||
if ($accident->final_amount > 0) {
|
||||
|
||||
$response = json_decode($this->callPaymentStatusBillApi(explode("/", $accident->bill_code)[0]));
|
||||
$response = json_decode($paymentService->callPaymentStatusBillApi(explode("/", $accident->bill_code)[0]));
|
||||
|
||||
if ($response->isPayed) {
|
||||
$accident->payBill();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\V2\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\NikarayanService;
|
||||
use Illuminate\Http\Request;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -425,7 +426,7 @@ class RoadObservationController extends Controller
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function handle(Request $request, RoadObserved $roadObserved)
|
||||
public function handle(Request $request, RoadObserved $roadObserved, NikarayanService $nikarayanService)
|
||||
{
|
||||
if (! auth()->user()->hasAnyPermission(['show-fast-react-edarate-shahri', 'show-fast-react-province', 'show-fast-react'])) {
|
||||
return response()->json([
|
||||
@@ -498,19 +499,9 @@ class RoadObservationController extends Controller
|
||||
// if ($file_index > 0) {
|
||||
// $roadObserved->files()->createMany($files_path);
|
||||
// }
|
||||
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
|
||||
// $url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
|
||||
try {
|
||||
$array = array('strUserName' => 'vaytelrop',
|
||||
'strPassword' => 'VaYtelROP*2024',
|
||||
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
|
||||
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
|
||||
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
|
||||
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
|
||||
'strNextImageLink' => "https://rms.rmto.ir/".$files,
|
||||
'strRMSDateAndTime' => $roadObserved->updated_at
|
||||
);
|
||||
$soap_client = new SoapClient($url);
|
||||
$result = $soap_client->UpdateInfo_RoadObservedProblems($array);
|
||||
$result = $nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, $files);
|
||||
} catch (SoapFault $e) {
|
||||
|
||||
$msg = "error in send to nikarayan at".date("Y-m-d H:i:s")."\n".'rms: error in get road observation webservice babe!!!!'."\n";
|
||||
|
||||
30
app/Providers/NikarayanServiceProvider.php
Normal file
30
app/Providers/NikarayanServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Services\NikarayanService;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use SoapClient;
|
||||
|
||||
class NikarayanServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->app->bind(NikarayanServiceProvider::class, function () {
|
||||
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
|
||||
$soapClient = new SoapClient($url);
|
||||
return new NikarayanService($soapClient);
|
||||
});
|
||||
}
|
||||
}
|
||||
37
app/Services/NikarayanService.php
Normal file
37
app/Services/NikarayanService.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\RoadObserved;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use SoapClient;
|
||||
|
||||
class NikarayanService
|
||||
{
|
||||
protected SoapClient $soapClient;
|
||||
|
||||
public function __construct(SoapClient $soapClient)
|
||||
{
|
||||
$this->soapClient = $soapClient;
|
||||
}
|
||||
|
||||
public function updateRoadObservedInfoByNikarayan(Request $request, RoadObserved $roadObserved, $files)
|
||||
{
|
||||
if (App::isProduction())
|
||||
{
|
||||
$array = array('strUserName' => 'vaytelrop',
|
||||
'strPassword' => 'VaYtelROP*2024',
|
||||
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
|
||||
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
|
||||
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
|
||||
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
|
||||
'strNextImageLink' => "https://rms.rmto.ir/".$files,
|
||||
'strRMSDateAndTime' => $roadObserved->updated_at
|
||||
);
|
||||
return $this->soapClient->UpdateInfo_RoadObservedProblems($array);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
72
app/Services/PaymentService.php
Normal file
72
app/Services/PaymentService.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class PaymentService
|
||||
{
|
||||
public function invoiceBillApi($driver_national_code, $final_amount)
|
||||
{
|
||||
if (App::isProduction())
|
||||
{
|
||||
try {
|
||||
$post = array(
|
||||
'username' => env("PAYMENT_USERNAME"),
|
||||
'password' => env("PAYMENT_PASSWORD"),
|
||||
'amount' => $final_amount,
|
||||
'serial' => "12345",
|
||||
'type' => 1,
|
||||
'instanceid' => 123,
|
||||
'ownerid' => $driver_national_code,
|
||||
'calculationBox' => "{\"rows\":[{\"amount\":" . $final_amount . ",\"code\":\"7070021060000015\"}]}"
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://payment.rmto.ir/acc/rest/payid/gen");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
abort(500);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function callPaymentStatusBillApi($bill_code)
|
||||
{
|
||||
if (App::isProduction())
|
||||
{
|
||||
try {
|
||||
$post = array(
|
||||
// 'username' => env("PAYMENT_USERNAME"),
|
||||
// 'password' => env("PAYMENT_PASSWORD"),
|
||||
// 'amount' => $final_amount,
|
||||
// 'serial' => "12345",
|
||||
// 'type' => 1,
|
||||
// 'instanceid' => 123,
|
||||
// 'ownerid' => $driver_national_code,
|
||||
// 'calculationBox' => "{\"rows\":[{\"amount\":". $final_amount .",\"code\":\"7070021060000015\"}]}"
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://payment.rmto.ir/acc/rest/payid/track2/" . env("PAYMENT_USERNAME") . "/" . env("PAYMENT_PASSWORD") . "/" . $bill_code);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($ch, CURLOPT_POST, true);
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $response;
|
||||
} catch (\Throwable $th) {
|
||||
abort(500);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
2
bootstrap/cache/services.php
vendored
2
bootstrap/cache/services.php
vendored
@@ -44,6 +44,7 @@
|
||||
40 => 'App\\Providers\\RouteServiceProvider',
|
||||
41 => 'App\\Providers\\TelescopeServiceProvider',
|
||||
42 => 'Barryvdh\\Debugbar\\ServiceProvider',
|
||||
43 => 'App\\Providers\\NikarayanServiceProvider',
|
||||
),
|
||||
'eager' =>
|
||||
array (
|
||||
@@ -76,6 +77,7 @@
|
||||
26 => 'App\\Providers\\RouteServiceProvider',
|
||||
27 => 'App\\Providers\\TelescopeServiceProvider',
|
||||
28 => 'Barryvdh\\Debugbar\\ServiceProvider',
|
||||
29 => 'App\\Providers\\NikarayanServiceProvider',
|
||||
),
|
||||
'deferred' =>
|
||||
array (
|
||||
|
||||
@@ -181,6 +181,7 @@ return [
|
||||
App\Providers\TelescopeServiceProvider::class,
|
||||
|
||||
Barryvdh\Debugbar\ServiceProvider::class,
|
||||
App\Providers\NikarayanServiceProvider::class,
|
||||
|
||||
],
|
||||
|
||||
|
||||
192
tests/Feature/V2/Dashboard/RoadObservation/HandleTest.php
Normal file
192
tests/Feature/V2/Dashboard/RoadObservation/HandleTest.php
Normal file
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\V2\Dashboard\RoadObservation;
|
||||
|
||||
use App\Facades\Sms\Sms;
|
||||
use App\Models\LogList;
|
||||
use App\Models\Permission;
|
||||
use App\Models\RoadObserved;
|
||||
use App\Models\User;
|
||||
use App\Services\NikarayanService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Mockery\MockInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HandleTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase, WithFaker;
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*/
|
||||
public function test_user_should_have_right_permissions(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$roadObserved = RoadObserved::factory()->create();
|
||||
|
||||
$mock = $this->mock(NikarayanService::class, function (MockInterface $mock) {
|
||||
$mock->shouldReceive('updateRoadObservedInfoByNikarayan')->andReturn(0);
|
||||
});
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/v2/road_observations/handle/{$roadObserved->id}");
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_user_can_handle_road_observed_update_info(): void
|
||||
{
|
||||
$user = User::factory()
|
||||
->has(Permission::factory([
|
||||
'name' => 'show-fast-react-edarate-shahri'
|
||||
]))
|
||||
->create();
|
||||
|
||||
$roadObserved = RoadObserved::factory()->create();
|
||||
|
||||
$logList = LogList::factory()->create([
|
||||
'log_unique_code' => 1142
|
||||
]);
|
||||
|
||||
$mock = $this->mock(NikarayanService::class, function (MockInterface $mock) {
|
||||
$mock->shouldReceive('updateRoadObservedInfoByNikarayan')->andReturn(0);
|
||||
});
|
||||
|
||||
Sms::shouldReceive('sendSms');
|
||||
Storage::fake('public');
|
||||
|
||||
$attributes = [
|
||||
'image-before-1' => UploadedFile::fake()->image('file.jpg')->size('30'),
|
||||
'image-after-1' => UploadedFile::fake()->image('file.jpg')->size('30'),
|
||||
'rms-start-latlng' => '12,12',
|
||||
'rms-end-latlng' => '13,13',
|
||||
];
|
||||
|
||||
$response = $this->actingAs($user)->postJson("/v2/road_observations/handle/{$roadObserved->id}", $attributes);
|
||||
|
||||
$response->assertStatus(201)
|
||||
->assertJsonStructure([
|
||||
'status',
|
||||
'message',
|
||||
'data' => [
|
||||
"AutoID",
|
||||
"Description",
|
||||
"EndDate",
|
||||
"EndTime",
|
||||
"EndTime_DateTime",
|
||||
"EventTypeTitle",
|
||||
"FeatureTypeTitle",
|
||||
"MobileForSendEventSms",
|
||||
"ProvinceName",
|
||||
"StartDate",
|
||||
"StartTime",
|
||||
"StartTime_DateTime",
|
||||
"StartTime_DateTime_fa",
|
||||
"Title",
|
||||
"TownName",
|
||||
"WeatherName",
|
||||
"XLAM",
|
||||
"YLAM",
|
||||
"city_fa",
|
||||
"city_id",
|
||||
"created_at",
|
||||
"edarate_shahri_id",
|
||||
"fk_Country",
|
||||
"fk_EventType",
|
||||
"fk_FeatureType",
|
||||
"fk_Province",
|
||||
"fk_RegisteredEventMessage",
|
||||
"fk_Town",
|
||||
"fk_Weather",
|
||||
"handling_way_id",
|
||||
"id",
|
||||
"image_after",
|
||||
"image_before",
|
||||
"lat",
|
||||
"lng",
|
||||
"observed_way_id",
|
||||
"province_fa",
|
||||
"province_id",
|
||||
"refer_description",
|
||||
"restore_description",
|
||||
"rms_city_id",
|
||||
"rms_description",
|
||||
"rms_end_latlng",
|
||||
"rms_last_activity",
|
||||
"rms_last_activity_fa",
|
||||
"rms_province_id",
|
||||
"rms_start_latlng",
|
||||
"rms_status",
|
||||
"status",
|
||||
"status_fa",
|
||||
"supervising_time",
|
||||
"supervisor_description",
|
||||
"supervisor_id",
|
||||
"supervisor_name",
|
||||
"updated_at",
|
||||
"updated_at_fa"
|
||||
],
|
||||
'nikarayan_res'
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('road_observed_histories', [
|
||||
'user_id' => $user->id,
|
||||
'previous_rms_status' => 0,
|
||||
'previous_rms_start_latlng' => $roadObserved->rms_start_latlng,
|
||||
'previous_rms_end_latlng' => $roadObserved->rms_end_latlng,
|
||||
'previous_rms_description' => $roadObserved->rms_description,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('road_observeds', [
|
||||
"AutoID" => $roadObserved->AutoID,
|
||||
"Description" => $roadObserved->Description,
|
||||
"EndDate" => $roadObserved->EndDate,
|
||||
"EndTime" => $roadObserved->EndTime,
|
||||
"EndTime_DateTime" => $roadObserved->EndTime_DateTime,
|
||||
"EventTypeTitle" => $roadObserved->EventTypeTitle,
|
||||
"FeatureTypeTitle" => $roadObserved->FeatureTypeTitle,
|
||||
"MobileForSendEventSms" => $roadObserved->MobileForSendEventSms,
|
||||
"ProvinceName" => $roadObserved->ProvinceName,
|
||||
"StartDate" => $roadObserved->StartDate,
|
||||
"StartTime" => $roadObserved->StartTime,
|
||||
"StartTime_DateTime" => $roadObserved->StartTime_DateTime,
|
||||
"StartTime_DateTime_fa" => $roadObserved->StartTime_DateTime_fa,
|
||||
"Title" => $roadObserved->Title,
|
||||
"TownName" => $roadObserved->TownName,
|
||||
"WeatherName" => $roadObserved->WeatherName,
|
||||
"XLAM" => $roadObserved->XLAM,
|
||||
"YLAM" => $roadObserved->YLAM,
|
||||
"city_fa" => $roadObserved->city_fa,
|
||||
"city_id" => $roadObserved->city_id,
|
||||
"edarate_shahri_id" => null,
|
||||
"fk_Country" => $roadObserved->fk_Country,
|
||||
"fk_EventType" => $roadObserved->fk_EventType,
|
||||
"fk_FeatureType" => $roadObserved->fk_FeatureType,
|
||||
"fk_Province" => $roadObserved->fk_Province,
|
||||
"fk_RegisteredEventMessage" => $roadObserved->fk_RegisteredEventMessage,
|
||||
"fk_Town" => $roadObserved->fk_Town,
|
||||
"fk_Weather" => $roadObserved->fk_Weather,
|
||||
"handling_way_id" => $roadObserved->handling_way_id,
|
||||
"id" => $roadObserved->id,
|
||||
"lat" => $roadObserved->lat,
|
||||
"lng" => $roadObserved->lng,
|
||||
"observed_way_id" => $roadObserved->observed_way_id,
|
||||
"province_fa" => $roadObserved->province_fa,
|
||||
"province_id" => $roadObserved->province_id,
|
||||
"refer_description" => $roadObserved->refer_description,
|
||||
"restore_description" => $roadObserved->restore_description,
|
||||
"rms_city_id" => $roadObserved->rms_city_id,
|
||||
'rms_description' => null,
|
||||
"rms_province_id" => $roadObserved->rms_province_id,
|
||||
"rms_status" => 0,
|
||||
'status' => 0,
|
||||
'status_fa' => 'در حال بررسی',
|
||||
"supervising_time" => $roadObserved->supervising_time,
|
||||
"supervisor_description" => $roadObserved->supervisor_description,
|
||||
"supervisor_id" => $roadObserved->supervisor_id,
|
||||
"supervisor_name" => $roadObserved->supervisor_name,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user