Server IP : 103.191.208.50 / Your IP : 216.73.216.53 Web Server : LiteSpeed System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64 User : celkcksm ( 1031) PHP Version : 7.4.33 Disable Function : show_source, system, shell_exec, passthru, popen, exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/celkcksm/cms.ncriptech.com/app/Http/Controllers/Payment/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php namespace App\Http\Controllers\Payment; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Models\PrintSetting; use App\Traits\FeesStudent; use App\Models\Setting; use App\Models\Fee; use Paystack; use Toastr; use Auth; use DB; class PaystackController extends Controller { use FeesStudent; /** * success response method. * * @return \Illuminate\Http\Response */ public function index() { // return view('paystack'); } /** * Redirect the User to Paystack Payment Page * @return Url */ public function redirectToGateway(Request $request) { // Payment Process try { // Get Amount $amount = 0; if(isset($request->fee_id)){ $fee_id = $request->fee_id; $amount = $this->netAmount($fee_id); } // $currency = Setting::where('status', '1')->first()->currency ?? 'NGN'; $print = PrintSetting::where('slug', 'fees-receipt')->first(); $fee = Fee::where('id', $fee_id)->first(); $data = array( "amount" => $amount * 100, "reference" => Paystack::genTranxRef(), "email" => Auth::guard('student')->user()->email, "currency" => $currency ?? 'NGN', "orderID" => str_pad($fee_id, 6, '0', STR_PAD_LEFT), "callback_url" => route('payment.paystack.callback'), "metadata" => [ "fee_id" => $fee_id, "description" => __('field_receipt') .': '. ($print->prefix ?? '') . str_pad($fee_id, 6, '0', STR_PAD_LEFT), ], ); // Charge Fee If Status Is Unpaid if(isset($fee->status) && $fee->status == 0){ return Paystack::getAuthorizationUrl($data)->redirectNow(); } else { Toastr::error(__('msg_something_went_wrong'), __('msg_error')); return redirect()->back(); } } catch(\Exception $e) { \Log::error('PayStack Payment Error: ' . $e->getMessage()); Toastr::error(__('msg_something_went_wrong'), __('msg_error')); return redirect()->back(); } } /** * Obtain Paystack payment information * @return void */ public function handleGatewayCallback() { try { $paymentDetails = Paystack::getPaymentData(); // Check if payment was successful if (isset($paymentDetails['data']['status']) && $paymentDetails['data']['status'] == 'success') { // Get fee ID $fee_id = $paymentDetails['data']['metadata']['fee_id']; // Update Fee if(isset($fee_id)){ $this->payStudentFee($fee_id, 9); } Toastr::success(__('msg_your_payment_successful'), __('msg_success')); } else { Toastr::error(__('msg_something_went_wrong'), __('msg_error')); } return redirect()->route('student.fees.index'); } catch (\Exception $e) { \Log::error('PayStack Payment Error: ' . $e->getMessage()); Toastr::error(__('msg_something_went_wrong'), __('msg_error')); return redirect()->route('student.fees.index'); } } }