app/Http/Controllers/Frontsite/PaymentController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $data = $request->all();
        $appointment = Appointment::where('id', $data['appointment_id'])->first();
        $config_payment = ConfigPayment::first();
        $specialist_fee = $appointment->doctor->specialist->price;
        $doctor_fee = $appointment->doctor->fee;
        $hospital_fee = $config_payment->fee;
        $hospital_vat = $config_payment->vat;
        $total = $specialist_fee + $doctor_fee + $hospital_fee;
         with vat and grand total
        $total_with_vat = ($total * $hospital_vat) / 100;
        $grand_total = $total + $total_with_vat;
        $transaction = new Transaction;
        $transaction->appointment_id = $appointment['id'];
        $transaction->fee_doctor = $doctor_fee;
        $transaction->fee_specialist = $specialist_fee;
        $transaction->fee_hospital = $hospital_fee;
        $transaction->sub_total = $total;
        $transaction->vat = $total_with_vat;
        $transaction->total = $grand_total;
        $transaction->save();
        $appointment = Appointment::find($appointment->id);
        $appointment->status = 1; 
        $appointment->save();
        return redirect()->route('payment.success');
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; $ appointment = Appointment :: where ( 'id' , $ data [ 'appointment_id' ] ) -> first ( ) ; $ config_payment = ConfigPayment :: first ( ) ; $ specialist_fee = $ appointment -> doctor -> specialist -> price ; $ doctor_fee = $ appointment -> doctor -> fee ; $ hospital_fee = $ config_payment -> fee ; $ hospital_vat = $ config_payment -> vat ; $ total = $ specialist_fee + $ doctor_fee + $ hospital_fee ; $ total_with_vat = ( $ total * $ hospital_vat ) / 100 ; $ grand_total = $ total + $ total_with_vat ; $ transaction = new Transaction ; $ transaction -> appointment_id = $ appointment [ 'id' ] ; $ transaction -> fee_doctor = $ doctor_fee ; $ transaction -> fee_specialist = $ specialist_fee ; $ transaction -> fee_hospital = $ hospital_fee ; $ transaction -> sub_total = $ total ; $ transaction -> vat = $ total_with_vat ; $ transaction -> total = $ grand_total ; $ transaction -> save ( ) ; $ appointment = Appointment :: find ( $ appointment -> id ) ; $ appointment -> status = 1 ; $ appointment -> save ( ) ; return redirect ( ) -> route ( 'payment.success' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// set transaction // total // total with vat and grand total // save to database // update status appointment // set to completed payment