⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Repositories
/
View File Name :
PatientPaypalRepository.php
<?php namespace App\Repositories; use App\Models\IpdPatientDepartment; use App\Models\IpdPayment; use App\Models\Transaction; use DB; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\App; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class PatientPaypalRepository */ class PatientPaypalRepository { /** * @throws \Throwable */ public function patientPaymentSuccess($response) { try { DB::beginTransaction(); $userId = getLoggedInUserId(); $transactionID = $response['purchase_units'][0]['payments']['captures'][0]['id']; $amount = $response['purchase_units'][0]['payments']['captures'][0]['amount']['value']; $ipdPatientId = $response['purchase_units'][0]['reference_id']; $transactionData = [ 'transaction_id' => $transactionID, 'amount' => $amount, 'user_id' => $userId, 'status' => 'paid', 'meta' => $response, 'payment_type' => Transaction::TYPE_PAYPAL, // 'payment_type' => IpdPayment::PAYMENT_MODES_PAYPAL, ]; $transaction = Transaction::create($transactionData); $ipdPaymentData = [ 'transaction_id' => $transaction->id, 'ipd_patient_department_id' => $ipdPatientId, 'payment_mode' => IpdPayment::PAYMENT_MODES_PAYPAL, 'date' => Carbon::now(), 'amount' => $amount, ]; $ipdPayment = App::make(IpdPaymentRepository::class); $ipdPayment->store($ipdPaymentData); // update ipd bill $ipdPatientDepartment = IpdPatientDepartment::findOrFail($ipdPatientId); $ipdBill = $ipdPatientDepartment->bill; if ($ipdBill) { $ipdBill->total_payments = $ipdBill->total_payments + $amount; $ipdBill->net_payable_amount = $ipdBill->net_payable_amount - $amount; $ipdBill->save(); $ipdPatientDepartment->bill_status = 1; $ipdPatientDepartment->save(); } DB::commit(); } catch (Exception $e) { DB::rollBack(); throw new UnprocessableEntityHttpException($e->getMessage()); } } }