public function getSuccessPayment(Request $request) { $admin = User::where(['type' => 'admin'])->first(); $gateway = Omnipay::create('PayPal_Express'); $gateway->setUsername('fai1999.fa_api1.gmail.com'); $gateway->setPassword('N8MALTPJ39RD3MG7'); $gateway->setSignature('AVieiSDlpAV8gE.TnT6kpOEjJbTKAJJakY.PKQSfbkf.rc2Gy1N7vumm'); $gateway->setTestMode(true); $params = Session::get('params'); $response = $gateway->completePurchase($params)->send(); $paypalResponse = $response->getData(); // this is the raw response object if (isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') { // Response // print_r($paypalResponse); } else { //Failed transaction } $count = Transaction::where(['transactionid' => $paypalResponse['PAYMENTINFO_0_TRANSACTIONID']])->count(); if ($count < 1) { Transaction::create(['senderid' => Auth::user()->id, 'transactionid' => $paypalResponse['PAYMENTINFO_0_TRANSACTIONID'], 'amount' => $paypalResponse['PAYMENTINFO_0_AMT'], 'recipientid' => $admin->id]); $balance = Balance::where(['userid' => Auth::user()->id])->first(); $balance = $balance->balance + $paypalResponse['PAYMENTINFO_0_AMT']; Balance::where(['userid' => Auth::user()->id])->update(['balance' => $balance]); } if (Auth::user()->type != 'admin') { return redirect()->route('transactions'); } }
public function getAcceptLesson($lessonid) { if (Auth::user()->type == 'tutor') { $lessoncount = Lesson::where(['id' => $lessonid, 'tutorid' => Auth::user()->id])->count(); if ($lessoncount > 0) { $updated = Lesson::where(['id' => $lessonid, 'tutorid' => Auth::user()->id])->update(['action' => 1]); } return redirect()->route('mylessons'); } elseif (Auth::user()->type == 'student') { $lesson = Lesson::where(['id' => $lessonid, 'studentid' => Auth::user()->id])->first(); if (count($lesson) > 0) { if ($lesson->amount <= Auth::user()->balance->balance) { $balance = Auth::user()->balance->balance - $lesson->amount; $updatebalance = Balance::where(['userid' => Auth::user()->id])->update(['balance' => $balance]); if ($updatebalance) { $tutorbalance = $lesson->tutor->balance->balance + $lesson->amount; $updatebalance = Balance::where(['userid' => $lesson->tutor->id])->update(['balance' => $tutorbalance]); Transaction::create(['recipientid' => Auth::user()->id, 'transactionid' => 'Web Payment', 'amount' => $lesson->amount, 'senderid' => $lesson->tutor->id]); $updated = Lesson::where(['id' => $lessonid, 'studentid' => Auth::user()->id])->update(['action' => 2]); return redirect()->route('mylessons'); } } else { return redirect()->route('student.buytime'); } } return redirect()->route('mylessons'); } else { return '404 page not found'; } }
public function postTutorPaid(Request $request) { if (Auth::user()->type == 'admin') { $tutorpayment = TutorPaymentRequest::where(['id' => $request->input('tutorid')])->first(); $balance = $tutorpayment->tutor->balance->balance - $tutorpayment->payment; Balance::where(['userid' => $tutorpayment->tutor->id])->update(['balance' => $balance]); Transaction::create(['senderid' => Auth::user()->id, 'transactionid' => $request->input('transactionid'), 'amount' => $tutorpayment->payment, 'recipientid' => $tutorpayment->tutorid]); TutorPaymentRequest::where(['id' => $request->input('tutorid')])->delete(); return redirect()->route('admin.turorpayment')->with('msg', 'Successfully Paid'); } else { return '404 page not found'; } }