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 Srmklive\PayPal\Services\PayPal; use Illuminate\Http\Request; use App\Models\PrintSetting; use App\Traits\FeesStudent; use App\Models\Setting; use App\Models\Fee; use Toastr; use DB; class PaypalController extends Controller { use FeesStudent; /** * success response method. * * @return \Illuminate\Http\Response */ public function index() { // return view('paypal'); } /** * success response method. * * @return \Illuminate\Http\Response */ public function process(Request $request) { // Payment Process $provider = new PayPal; $provider->setApiCredentials(config('paypal')); $paypalToken = $provider->getAccessToken(); // 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 ?? 'USD'; $print = PrintSetting::where('slug', 'fees-receipt')->first(); $fee = Fee::where('id', $fee_id)->first(); // Set Session session()->put('fee_id', $fee_id); // Charge Fee If Status Is Unpaid if(isset($fee->status) && $fee->status == 0){ $response = $provider->createOrder([ "intent" => "CAPTURE", "application_context" => [ "return_url" => route('payment.paypal.success'), "cancel_url" => route('payment.paypal.cancel'), ], "purchase_units" => [ 0 => [ "amount" => [ "currency_code" => $currency ?? 'USD', "value" => $amount, ], "description" => __('field_receipt') .': '. ($print->prefix ?? '') . str_pad($fee_id, 6, '0', STR_PAD_LEFT), ] ] ]); } if (isset($response['id']) && $response['id'] != null) { foreach ($response['links'] as $links) { if ($links['rel'] == 'approve') { return redirect()->away($links['href']); } } Toastr::error(__('msg_something_went_wrong'), __('msg_error')); return redirect()->route('payment.paypal.cancel'); } else { Toastr::error(__('msg_something_went_wrong'), __('msg_error')); return redirect()->route('student.fees.index'); } } /** * success response method. * * @return \Illuminate\Http\Response */ public function paymentSuccess(Request $request) { // Payment Process $provider = new PayPal; $provider->setApiCredentials(config('paypal')); $provider->getAccessToken(); $response = $provider->capturePaymentOrder($request['token']); if (isset($response['status']) && $response['status'] == 'COMPLETED') { // Update Fee $fee_id = session()->get('fee_id'); if(isset($fee_id)){ $this->payStudentFee($fee_id, 6); } // Clear Session session()->forget('fee_id'); Toastr::success(__('msg_your_payment_successful'), __('msg_success')); return redirect()->route('student.fees.index'); } else { Toastr::error(__('msg_something_went_wrong'), __('msg_error')); return redirect()->route('student.fees.index'); } } /** * success response method. * * @return \Illuminate\Http\Response */ public function paymentCancel() { // Toastr::error(__('msg_your_payment_cancelled'), __('msg_error')); return redirect()->route('student.fees.index'); } }