Файловый менеджер - Редактировать - /home/clickysoft/public_html/calvary-p2.clickysoft.net/app/Http/Controllers/Front/AnnualDueController.php
Назад
<?php namespace App\Http\Controllers\Front; use App\Http\Controllers\Controller; use App\Http\Requests\Front\AnnualDueRequest; use App\Http\Requests\Front\CardVerificationRequest; use App\Mail\OrderPlacedForAdmin; use App\Mail\OrderPlacedForUser; use App\Models\Grade; use App\Models\HotLunch; use App\Models\LunchOrder; use App\Models\LunchOrderChild; use App\Models\LunchPaymentLog; use App\Models\School; use App\Models\ShirtSize; use App\Models\SiteSetting; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Session; use net\authorize\api\constants\ANetEnvironment; use net\authorize\api\contract\v1 as AnetAPI; use net\authorize\api\controller as AnetController; class AnnualDueController extends Controller { public function index($username = null) { $now = Carbon::now()->format('Y-m-d'); $year = Carbon::now()->format('Y'); $hotLunch = HotLunch::where('reg_starts', '<=', $now) ->where('reg_ends', '>=', $now) ->where('status', 1) ->first(); $schools = School::with(['grades'])->get(); $orderExit = LunchOrder::where('user_id', Auth::id()) ->where('status', 'Completed') ->whereYear('created_at', $year)->first(); $siteSettings = SiteSetting::first(); $shirtSizes = ShirtSize::all(); return view('front.annual-due.index', compact('hotLunch', 'schools', 'orderExit', 'siteSettings', 'shirtSizes')); } public function addAnnualDueData(AnnualDueRequest $request) { $siteSettings = SiteSetting::first(); if ($request->grade === "8th" && request()->party_contribution < $siteSettings->party_contribution) { return redirect()->back()->withInput()->with('error_msg', 'You have to contribute at least $' . $siteSettings->party_contribution); } $now = Carbon::now()->format('Y-m-d'); $year = Carbon::now()->format('Y'); $hotLunch = HotLunch::where('reg_starts', '<=', $now) ->where('reg_ends', '>=', $now) ->where('status', 1) ->first(); $orderExit = LunchOrder::where('user_id', Auth::id()) ->where('status', 'Completed') ->whereYear('created_at', $year)->first(); $grade = Grade::where('title', $request->grade)->first(); $annualDue = 0; $schoolDirectoryQuantity = $request->school_directory_quantity; $schoolDirectoryPrice = ($siteSettings->school_directory * $request->school_directory_quantity); $annualGraduationContribution = 0; $communityService = $siteSettings->class_fund; $totalPrice = 0; if (empty($orderExit)) { $annualDue = $siteSettings->annual_dues; } if ($request->grade === "8th") { $annualGraduationContribution = $request->party_contribution; } $finalPrice = ($schoolDirectoryPrice + $annualGraduationContribution + $annualDue + $communityService); Session::put('user_annual_due_cart', [ 'user_id' => Auth::id(), 'hot_lunch_id' => $hotLunch->id, 'hot_lunch_title' => $hotLunch->title, 'hot_lunch_reg_starts' => $hotLunch->reg_starts, 'hot_lunch_reg_ends' => $hotLunch->reg_ends, 'total_price' => $totalPrice, 'is_paid_annual_due' => 1, 'annual_due' => $annualDue, 'school_directory_quantity' => $schoolDirectoryQuantity, 'school_directory_price' => $schoolDirectoryPrice, 'annual_graduation_contribution' => $annualGraduationContribution, 'community_service' => $communityService, 'final_price' => $finalPrice, 'child' => [ 'user_id' => Auth::id(), 'school_id' => $grade->school_id, 'hot_lunch_id' => $hotLunch->id, 'grade_id' => $grade->id, 'grade_title' => $grade->title, 'full_name' => $request->child_full_name, 'annual_graduation_contribution' => $annualGraduationContribution, 't_type' => $request->shirt_size, 'community_service' => $communityService, 'total_amount' => $finalPrice ] ]); return redirect()->route('annual.due.checkout'); } public function annualDueCheckout() { $userCart = Session::get('user_annual_due_cart'); if (empty($userCart)) { return redirect()->route('annual.due'); } return view('front.annual-due.checkout', compact('userCart')); } public function addAnnualDueCheckoutData(CardVerificationRequest $request) { $userCart = Session::get('user_annual_due_cart'); $merchant_login_id = config('app.merchant_login_id'); $merchant_transaction_id = config('app.merchant_transaction_key'); $input = $request->input(); $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName($merchant_login_id); $merchantAuthentication->setTransactionKey($merchant_transaction_id); $refId = 'ref' . time(); $cardNumber = preg_replace('/\s+/', '', $input['card_number']); $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber($cardNumber); $creditCard->setExpirationDate($input['expiration_year'] . "-" . $input['expiration_month']); $creditCard->setCardCode($input['cvv']); $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); // Set billing information $billTo = new AnetAPI\CustomerAddressType(); $billTo->setFirstName(\auth()->user()->first_name); $billTo->setLastName(\auth()->user()->last_name); $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount(number_format($userCart['final_price'], 2, '.', '')); $transactionRequestType->setPayment($paymentOne); $transactionRequestType->setBillTo($billTo); $requests = new AnetAPI\CreateTransactionRequest(); $requests->setMerchantAuthentication($merchantAuthentication); $requests->setRefId($refId); $requests->setTransactionRequest($transactionRequestType); $controller = new AnetController\CreateTransactionController($requests); $response = $controller->executeWithApiResponse(ANetEnvironment::PRODUCTION); $message_text = "Card is invalid."; $msg_type = "error_msg"; if ($response != null) { // Check to see if the API request was successfully received and acted upon if ($response->getMessages()->getResultCode() == "Ok") { $t_response = $response->getTransactionResponse(); if ($t_response != null && $t_response->getMessages() != null) { $order = LunchOrder::create([ 'user_id' => $userCart['user_id'], 'hot_lunch_id' => $userCart['hot_lunch_id'], 'coupon_id' => 0, 'hot_lunch_title' => $userCart['hot_lunch_title'], 'hot_lunch_reg_starts' => $userCart['hot_lunch_reg_starts'], 'hot_lunch_reg_ends' => $userCart['hot_lunch_reg_ends'], 'discount' => 0, 'total_price' => $userCart['total_price'], 'is_paid_annual_due' => 1, 'annual_due' => $userCart['annual_due'], 'school_directory_quantity' => $userCart['school_directory_quantity'], 'school_directory_price' => $userCart['school_directory_price'], 'annual_graduation_contribution' => $userCart['annual_graduation_contribution'], 'community_service' => $userCart['community_service'], 'final_price' => $userCart['final_price'], 'type' => LunchOrder::ANNUAL_DUE ]); LunchOrderChild::create([ 'user_id' => $userCart['user_id'], 'order_id' => $order->id, 'school_id' => $userCart['child']['school_id'], 'hot_lunch_id' => $userCart['hot_lunch_id'], 'grade_id' => $userCart['child']['grade_id'], 'full_name' => $userCart['child']['full_name'], 'annual_graduation_contribution' => $userCart['annual_graduation_contribution'], 't_type' => $userCart['child']['t_type'], 'community_service' => $userCart['community_service'], 'total_amount' => $userCart['final_price'], 'type' => LunchOrder::ANNUAL_DUE ]); LunchPaymentLog::create([ 'user_id' => Auth::id(), 'order_id' => $order->id, 'name_on_card' => Auth::user()->full_name, 'response_code' => $t_response->getResponseCode(), 'transaction_id' => $t_response->getTransId(), 'auth_id' => $t_response->getAuthCode(), 'message_code' => $t_response->getMessages()[0]->getCode() ]); $site_setting = SiteSetting::first(); Mail::to(Auth::user()->email)->later(now()->addSeconds(5), (new OrderPlacedForUser($order))); Mail::to($site_setting->admin_email)->later(now()->addSeconds(5), (new OrderPlacedForAdmin($order))); Session::put('user_annual_due_cart', []); return redirect()->route('orders.hot-lunch')->with('success_msg', 'Your order has been placed successfully. Kindly check your Junk/Spam folder for order information/receipt.'); } else { $message_text = 'There were some issue with the payment. Please try again later.'; $msg_type = "error_msg"; if ($t_response->getErrors() != null) { $message_text = $t_response->getErrors()[0]->getErrorText(); } } } } return redirect()->back()->withInput()->with($msg_type, $message_text); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка