Merge pull request #104 from witelgroup/feature/PaymentHarimCheckServise
Write webservice for harim and Cmms
This commit is contained in:
@@ -50,6 +50,13 @@ PAYMENT_USERNAME=
|
||||
PAYMENT_PASSWORD=
|
||||
PAYMENT_LINK=
|
||||
|
||||
HARIM_PAYMENT_USERNAME=
|
||||
HARIM_PAYMENT_PASSWORD=
|
||||
HARIM_PAYMENT_URL=
|
||||
HARIM_PAYMENT_SERIAL=
|
||||
HARIM_PAYMENT_INSTANCE_ID=
|
||||
|
||||
|
||||
RMS_VERSION=3.0
|
||||
RMS_CTO_PHONE_NUMBER=
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ class GetMachinesInfoListCommand extends Command
|
||||
'province_id' => $entry['UnitGroupCode'] ?? null,
|
||||
'city_id' => $entry['UnitCode'] ?? null,
|
||||
'station_id' => $entry['Layer3Code'] ?? null,
|
||||
'driver_name' => $entry['DriverName'] ?? null,
|
||||
]);
|
||||
|
||||
++$updatedRows;
|
||||
|
||||
@@ -21,6 +21,10 @@ enum HarimStates: int
|
||||
case BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL = 15;
|
||||
case MOKHALEFAT_BA_DASTGAH = 16;
|
||||
case ETMAM_FARAYAND = 17;
|
||||
case SODOR_FACTOR = 18;
|
||||
case PARDAKHT_FACTOR = 19;
|
||||
case SABT_FISH = 20;
|
||||
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
@@ -42,6 +46,9 @@ enum HarimStates: int
|
||||
self::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL => "تائید عرصه و اعیان ارسال شده توسط مدیر",
|
||||
self::MOKHALEFAT_BA_DASTGAH => "مخالفت با درخواست",
|
||||
self::ETMAM_FARAYAND => "اتمام فرایند",
|
||||
self::SODOR_FACTOR => "صدور فاکتور",
|
||||
self::PARDAKHT_FACTOR => "پرداخت فاکتور",
|
||||
self::SABT_FISH => "ثبت فیش",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,18 @@
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
||||
|
||||
use App\Facades\Sms\Sms;
|
||||
use App\Enums\HarimStates;
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\V3\Dashboard\Harim\Detail\HarimSubmitInvoiceRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Harim;
|
||||
use App\Models\HarimState;
|
||||
use App\Services\Cartables\Harim\HarimPaymentService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class DetailController extends Controller
|
||||
@@ -30,4 +36,58 @@ class DetailController extends Controller
|
||||
->orderBy('id', 'desc')
|
||||
->get(['id', 'expert_description', 'action_name', 'previous_state_name']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
* @throws ProhibitedAction
|
||||
*/
|
||||
public function submitInvoice(Harim $harim, HarimPaymentService $harimpaymentService, HarimSubmitInvoiceRequest $request): JsonResponse
|
||||
{
|
||||
$lock = Cache::lock("harimPayment-{$harim->id}", 10);
|
||||
throw_if(! $lock->get(), new ProhibitedAction('امکان درخواست مجدد تا 10 ثانیه دیگر وجود ندارد'));
|
||||
|
||||
$payment_amount = $harim->payment_amount;
|
||||
|
||||
$bill_code = $harimpaymentService->invoiceBillApi($harim->national_id, $payment_amount);
|
||||
|
||||
DB::transaction(function () use ($bill_code, $harim) {
|
||||
|
||||
$harim->histories()->update([
|
||||
// 'bill_code' => $bill_code,
|
||||
'status' => HarimStates::SODOR_FACTOR->value,
|
||||
'status_fa' => HarimStates::SODOR_FACTOR->label(),
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
$msg = "فاکتور با شناسه پرداخت \n" . explode("/", $harim->bill_code)[0]. "\n برای پرداخت از لینک زیر اقدام نمایید.\n\n"
|
||||
. config('harim_web_services.Harim_Payment.LINK')."/#/pay/".explode("/", $harim->bill_code)[0]."/$payment_amount";
|
||||
|
||||
Sms::sendSms($harim->phone_number, $msg);
|
||||
|
||||
$lock->release();
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function checkPaymentStatus(Harim $harim, HarimPaymentService $harimpaymentService): JsonResponse
|
||||
{
|
||||
DB::transaction(function () use ($harim, $harimpaymentService) {
|
||||
|
||||
$response = json_decode($harimpaymentService->callPaymentStatusBillApi(explode('/', $harim->bill_code)[0]));
|
||||
|
||||
throw_if(! $response->isPayed, new ProhibitedAction('پرداخت انجام نشده است'));
|
||||
|
||||
$harim->histories()->update([
|
||||
'status' => HarimStates::PARDAKHT_FACTOR->value,
|
||||
'status_fa' => HarimStates::PARDAKHT_FACTOR->label(),
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
return $this->successResponse($harim);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\V3\Dashboard\Harim\Detail;
|
||||
|
||||
use App\Enums\HarimStates;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class HarimSubmitInvoiceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->harim->state_id == HarimStates::SABT_FISH->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,13 @@ class AllocateRequest extends FormRequest
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$duplicateMission = Mission::query()->where('machine_id', '=', $this->machine_id)
|
||||
->whereBetween('start_date', [$this->mission->start_date, $this->mission->end_date])
|
||||
->orWhereBetween('end_date', [$this->mission->start_date, $this->mission->end_date])
|
||||
->where('start_date', '<=', $this->mission->end_date)
|
||||
->where('end_date', '>=', $this->mission->start_date)
|
||||
->exists();
|
||||
|
||||
if ($duplicateMission) {
|
||||
$validator->errors()->add(
|
||||
'machine',
|
||||
'machine_id',
|
||||
'خودروی مورد نظر در این زمان رزرو می باشد'
|
||||
);
|
||||
}
|
||||
|
||||
67
app/Services/Cartables/Harim/HarimPaymentService.php
Normal file
67
app/Services/Cartables/Harim/HarimPaymentService.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cartables\Harim;
|
||||
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class HarimPaymentService
|
||||
{
|
||||
/**
|
||||
* @throws ProhibitedAction
|
||||
*/
|
||||
public function invoiceBillApi($national_id, $payment_amount): int|string
|
||||
{
|
||||
if (App::isProduction())
|
||||
{
|
||||
try {
|
||||
$payload = array(
|
||||
'username' => config('harim_web_services.Harim_Payment.username'),
|
||||
'password' => config('harim_web_services.Harim_Payment.PASSWORD'),
|
||||
'amount' => $payment_amount,
|
||||
'serial' => config('harim_web_services.Harim_Payment.serial'),
|
||||
'type' => 1,
|
||||
'instanceid' => config('harim_web_services.Harim_Payment.instanceid'),
|
||||
'ownerid' => $national_id,
|
||||
'calculationBox' => "{\"rows\":[{\"amount\":" . $payment_amount . ",\"code\":\"7070011026200593\"}]}"
|
||||
);
|
||||
|
||||
$response = Http::withBody(http_build_query($payload))
|
||||
->throw()
|
||||
->withoutVerifying()
|
||||
->post(config('harim_web_services.Harim_Payment.url'));
|
||||
|
||||
return $response->body();
|
||||
|
||||
}
|
||||
catch (\Throwable $th) {
|
||||
throw new ProhibitedAction('خطا در ارتباط با سرویس پرداخت');
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function callPaymentStatusBillApi($bill_code)
|
||||
{
|
||||
if (App::isProduction())
|
||||
{
|
||||
try {
|
||||
$username = config('harim_web_services.Harim_Payment.username');
|
||||
$password = config('harim_web_services.Harim_Payment.PASSWORD');
|
||||
$url = config('harim_web_services.Harim_Payment.url');
|
||||
|
||||
$result = "{$url}/{$username}/{$password}/{$bill_code}";
|
||||
|
||||
return Http::get($result)
|
||||
->throw()
|
||||
->body();
|
||||
|
||||
}catch (\Throwable $th) {
|
||||
throw new ProhibitedAction('خطا در دریافت');
|
||||
}
|
||||
}
|
||||
return json_encode(['isPayed' => 1]);
|
||||
}
|
||||
}
|
||||
@@ -38,5 +38,10 @@ return [
|
||||
|
||||
'Harim_Payment' => [
|
||||
'fee' => env('HARIM_AMOUNT_FEE'),
|
||||
'username' => env('HARIM_ENCRYPTION_USERNAME'),
|
||||
'password' => env('HARIM_ENCRYPTION_PASSWORD'),
|
||||
'url' => env('HARIM_ENCRYPTION_URL'),
|
||||
'serial' => env('HARIM_ENCRYPTION_SERIAL'),
|
||||
'instanceid' => env('HARIM_ENCRYPTION_INSTANCE_ID'),
|
||||
]
|
||||
];
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('cmms_machines', function (Blueprint $table) {
|
||||
$table->string('driver_name')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('cmms_machines', function (Blueprint $table) {
|
||||
$table->dropColumn('driver_name');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -19,7 +19,7 @@
|
||||
<a href="{{ route('v2.road_observations.pending_view') }}" class="btn btn-default btn-block my-2">رسیدگی به شکایات واکنش سریع</a>
|
||||
@endcan
|
||||
@can('add-safety-and-privacy')
|
||||
<a href="{{ route('v2.safety_and_privacy.operator.create') }}" class="btn btn-default btn-block my-2">ثبت نگهداری حریم راه</a>
|
||||
<a href="/v3/dashboard/road-safety/operator" class="btn btn-default btn-block my-2">ثبت نگهداری حریم راه</a>
|
||||
@endcan
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user