public function checkout(Request $request) { $response = new stdClass(); if ($request->isMethod('post')) { $postData = $request->all(); $userId = $postData['id']; $token = $postData['token']; $amount = $postData['money']; $name = $postData['name']; $addrLine1 = $postData['addrLine1']; $city = $postData['city']; $state = $postData['state']; $country = $postData['country']; $email = $postData['email']; $zipCode = $postData['zipCode']; $phoneNumber = $postData['phoneNumber']; $authFlag = false; if (isset($postData['api_token'])) { $apiToken = $postData['api_token']; if ($apiToken == $this->API_TOKEN) { $authFlag = true; } else { $authFlag = false; } } if ($authFlag) { $rules = array('money' => 'required|regex:/^[0-9]+([.][0-9]{0,2}+)?$/', 'name' => 'required', 'addrLine1' => 'required', 'city' => 'required', 'state' => 'required', 'zipCode' => 'required', 'country' => 'required', 'email' => 'required', 'phoneNumber' => 'required'); $message = array('money.required' => 'Please Enter Amount that you want to add to your wallet', 'money.regex' => 'Please Enter a valid Amount i.e. number or decimal value ', 'name.required' => 'please enter your name', 'addrLine1.required' => 'please enter address', 'city.required' => 'please enter city', 'state.required' => 'please enter state', 'zipCode.required' => 'please provide zip code', 'country.required' => 'please specify country name', 'email.required' => 'please enter your email', 'phoneNumber.required' => 'please enter your phone number'); $validator = Validator::make($request->all(), $rules, $message); if (!$validator->fails()) { \Twocheckout::privateKey('1768AF13-92B6-4B9D-8493-66E884E98FEF'); \Twocheckout::sellerId('901311477'); \Twocheckout::sandbox(true); #Uncomment to use Sandbox \Twocheckout::verifySSL(false); try { $charge = \Twocheckout_Charge::auth(array("merchantOrderId" => "123", "token" => $token, "currency" => 'USD', "total" => $amount, "billingAddr" => array("name" => $name, "addrLine1" => $addrLine1, "city" => $city, "state" => $state, "zipCode" => $zipCode, "country" => $country, "email" => $email, "phoneNumber" => $phoneNumber))); // echo json_encode($charge,true);die; // echo '<pre>'; // print_r($charge);die; if ($charge['response']['responseCode'] == 'APPROVED') { // echo "Thanks for your Order!"; // echo "<h3>Return Parameters:</h3>"; // echo "<pre>"; // print_r($charge); // echo "</pre>"; // echo die; $transactionId = $charge['response']['transactionId']; $objModelTransaction = new Transaction(); $input = array('tx_id' => '', 'tx_type' => '1', 'tx_mode' => '1', 'tx_code' => ' ', 'transaction_id' => $transactionId, 'user_id' => $userId, 'amount' => $amount, 'payment_time' => time() + 19800); $result = $objModelTransaction->addNewTransaction($input); //code for increasing the amount (updating the account bal) // first checking that user has details in usersmeta table or not, if not then acc_bal will be 0 & add users with amount // or if yes then update accountbalance $objModelUsermeta = new Usersmeta(); $whereForUpdateUser = array('rawQuery' => 'user_id = ?', 'bindParams' => [$userId]); $isUserAvailable = $objModelUsermeta->getUsermetaWhere($whereForUpdateUser); if ($isUserAvailable) { $accountBal = $isUserAvailable->account_bal; $totalBalance = $accountBal + $amount; $dataForUpdateUser = array('account_bal' => $totalBalance); // return $dataForUpdateUser; $updated = $objModelUsermeta->updateUsermetaWhere($dataForUpdateUser, $whereForUpdateUser); } else { $accountBal = 0; $totalBalance = $accountBal + $amount; $addData = array('user_id' => $userId, 'account_bal' => $totalBalance); $addUsermeta = $objModelUsermeta->addUsermeta($addData); } // code for generating NOTIFICATION $objModelNotification = Notification::getInstance(); $input = array('notification_id' => '', 'user_id' => $userId, 'notifications_txt' => '$ ' . $amount . ' is successfully credited to your account through 2CO credit card payment'); $addNotification = $objModelNotification->addNewNotification($input); $response->code = 200; $response->message = "Payment Approved"; $response->data = $totalBalance; echo json_encode($response, true); } } catch (\Twocheckout_Error $e) { echo json_encode($e->getMessage(), true); // print_r($e->getMessage()); } } } } }
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 getTicketById($ticketId) { $result = Transaction::whereId($ticketId)->first(); //first() function in sql returns the first value of the selected column return $result; }
public function expressCallback(Request $request) { // return 23; $response = new stdClass(); $postData = $request->all(); $userId = $postData['id']; $amount = $postData['amount']; $payerid = $postData['PayerID']; $token = $postData['token']; // print_r($token);print_r($payerid);die; $authFlag = false; if (isset($postData['api_token'])) { $apiToken = $postData['api_token']; if ($apiToken == $this->API_TOKEN) { $authFlag = true; } } if ($authFlag) { $objpaypal = Paypal::getInstance(); $result = $objpaypal->ConfirmPayment($amount, $token, $payerid); // echo"<pre>";print_r($result);die; // echo json_encode($result, true); if ($result) { // $function_result=$this->myCurlFunction(); // return $function_result; if ($result['ACK'] == "Success") { // $response->code = 200; // $response->message = "Amount added to your Wallet Successfully."; $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID']; $data['acknowledgement'] = $result['ACK']; $data['amount'] = $amount; $data['paymentTime'] = date('Y-m-d H:i:s'); $transactionId = $data['transactionId']; $amount = $data['amount']; $paymentTime = $data['paymentTime']; $objModelTransaction = new Transaction(); $input = array('tx_id' => '', 'tx_type' => '1', 'tx_mode' => '0', 'tx_code' => ' ', 'transaction_id' => $transactionId, 'user_id' => $userId, 'amount' => $amount, 'payment_time' => strtotime($paymentTime)); $result = $objModelTransaction->addNewTransaction($input); //code for increasing the amount (updating the account bal) // first checking that user has details in usersmeta table or not, if not then acc_bal will be 0 & add users with amount // or if yes then update accountbalance $objModelUsermeta = new Usersmeta(); $whereForUpdateUser = array('rawQuery' => 'user_id = ?', 'bindParams' => [$userId]); $isUserAvailable = $objModelUsermeta->getUsermetaWhere($whereForUpdateUser); if ($isUserAvailable) { $accountBal = $isUserAvailable->account_bal; $totalBalance = $accountBal + $amount; $dataForUpdateUser = array('account_bal' => $totalBalance); // return $dataForUpdateUser; $updated = $objModelUsermeta->updateUsermetaWhere($whereForUpdateUser, $dataForUpdateUser); } else { $accountBal = 0; $totalBalance = $accountBal + $amount; $addData = array('user_id' => $userId, 'account_bal' => $totalBalance); $addUsermeta = $objModelUsermeta->addUsermeta($addData); } // code for generating NOTIFICATION $objModelNotification = Notification::getInstance(); $input = array('notification_id' => '', 'user_id' => $userId, 'notifications_txt' => '$ ' . $amount . ' is successfully credited to your account'); $addNotification = $objModelNotification->addNewNotification($input); $response->code = 200; $response->message = "Amount added to your Wallet Successfully."; // $response->notification="Your Account is Successfully Credited."; $response->data = $totalBalance; // echo '<pre>';print_r($response);die; // return $response; echo json_encode($response, true); } else { if ($result['ACK'] == "SuccessWithWarning") { // return 6; $response->code = 07; $response->message = "Amount added to your Wallet Successfully."; $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID']; $data['acknowledgement'] = $result['ACK']; $data['amount'] = $amount; $data['paymentTime'] = date('Y-m-d H:i:s'); $response->data = $data; echo json_encode($response, true); // echo'<pre>';print_r($data);die; // return $response->data = $data; // echo "<pre>"; // print_r($result); // die; // return 7; } else { $response->code = 400; $response->message = "Some ERROR OCCURRED."; echo "<pre>"; print_r($result); die; } } } // if ($result['ACK'] == "Success") { // $response->code = 200; // $response->message = "Payment model created successfully."; // $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID']; // $data['acknowledgement'] = $result['ACK']; // $data['amount'] = $amount; // $data['paymentTime'] = date('Y-m-d H:i:s'); // $response->data = $data; // } // if ($result) { // $response->code = 200; // $response->message = "Payment model created successfully."; // $response->data = 1; // echo json_encode($response, true); } else { $response->code = 400; $response->message = "Error in getting callback results. auth flag is not set"; $response->data = null; echo json_encode($response, true); } // // $payerid = $request->input('PayerID'); // $token = $request->input('token'); // // $objpaypal = paypal::getInstance(); // $result = $objpaypal->ConfirmPayment($amount, $token, $payerid); // //// echo "<pre>";print_r($result); //// die; // if ($result['ACK'] == "Success") { // $data['transactionId'] = $result['PAYMENTINFO_0_TRANSACTIONID']; // $data['acknowledgement'] = $result['ACK']; // $data['amount'] = $amount; // $data['paymentTime'] = date('Y-m-d H:i:s'); // } else { // echo "<pre>"; // print_r($result); // die; // } // echo "<pre>"; // print_r($data); // die; }
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'; } }