관리-도구
편집 파일: PaymentController.php
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use App\Models\Admin; use App\Models\Deposit; use App\Models\Gateway; use App\Models\GeneralSetting; use App\Models\Payment; use App\Models\Property; use App\Models\Transaction; use App\Notifications\DepositNotification; use Auth; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Str; class PaymentController extends Controller { public function gateways(Request $request, $id) { $property = Property::findOrFail($id); $property_exist = Payment::where('property_id', $id)->where('user_id', Auth::id())->where('next_payment_date', '!=', null)->where('payment_status', 1)->first(); if (!$property_exist) { $gateways = Gateway::where('status', 1)->latest()->get(); $pageTitle = "Payment Methods"; session()->put('invest_amount',10); return view("frontend.user.gateway.gateways", compact('gateways', 'pageTitle', 'property')); } return redirect()->back()->with('error', 'Already invest to this plan'); } public function paynow(Request $request) { $request->validate([ 'amount' => 'required|gte:0', ]); $gateway = Gateway::where('status', 1)->findOrFail($request->id); $trx = strtoupper(Str::random()); $final_amount = ($request->amount * $gateway->rate) + $gateway->charge; if (isset($request->type) && $request->type == 'deposit') { $deposit = Deposit::create([ 'gateway_id' => $gateway->id, 'user_id' => auth()->id(), 'transaction_id' => $trx, 'amount' => $request->amount, 'rate' => $gateway->rate, 'charge' => $gateway->charge, 'final_amount' => $final_amount, 'payment_status' => 0, 'payment_type' => 1, ]); session()->put('trx', $trx); session()->put('type', 'deposit'); return redirect()->route('user.gateway.details', $gateway->id); } $property_id = Property::with('time')->findOrFail($request->property_id); if ($property_id->amount_type == 0) { if ($property_id->maximum_amount) { if ($request->amount > $property_id->maximum_amount) { return redirect()->back()->with('error', 'Maximum Invest Limit ' . number_format($property_id->maximum_amount, 2)); } } if ($property_id->minimum_amount) { if ($request->amount < $property_id->minimum_amount) { return redirect()->back()->with('error', 'Minimum Invest Limit ' . number_format($property_id->minimum_amount, 2)); } } } if ($property_id->amount_type == 1) { if ($property_id->amount) { if ($request->amount != $property_id->amount) { return redirect()->back()->with('error', 'Fixed Invest Limit ' . number_format($property_id->amount, 2)); } } } $next_payment_date = Carbon::now()->addHours($property_id->time->time); Payment::create([ 'property_id' => $property_id->id, 'gateway_id' => $gateway->id, 'user_id' => auth()->id(), 'transaction_id' => $trx, 'amount' => $request->amount, 'rate' => $gateway->rate, 'charge' => $gateway->charge, 'final_amount' => $final_amount, 'payment_status' => 0, 'next_payment_date' => $next_payment_date, ]); session()->put('trx', $trx); session()->forget('type'); return redirect()->route('user.gateway.details', $gateway->id); } public function gatewaysDetails($id) { $gateway = Gateway::where('status', 1)->findOrFail($id); if (session('type') == 'deposit') { $deposit = Deposit::where('transaction_id', session('trx'))->firstOrFail(); } else { $deposit = Payment::where('transaction_id', session('trx'))->firstOrFail(); } $pageTitle = $gateway->gateway_name . ' Payment Details'; if ($gateway->gateway_name == 'vouguepay') { $vouguePayParams["marchant_id"] = $gateway->gateway_parameters->vouguepay_merchant_id; $vouguePayParams["redirect_url"] = route("user.vouguepay.redirect"); $vouguePayParams["currency"] = $gateway->gateway_parameters->gateway_currency; $vouguePayParams["merchant_ref"] = $deposit->transaction_id; $vouguePayParams["memo"] = "Payment"; $vouguePayParams["store_id"] = $deposit->user_id; $vouguePayParams["loadText"] = $deposit->transaction_id; $vouguePayParams["amount"] = $deposit->final_amount; $vouguePayParams = json_decode(json_encode($vouguePayParams)); return view("frontend.user.gateway.{$gateway->gateway_name}", compact('gateway', 'pageTitle', 'deposit', 'vouguePayParams')); } if ($gateway->is_created) { return view("frontend.user.gateway.gateway_manual", compact('gateway', 'pageTitle', 'deposit')); } return view("frontend.user.gateway.{$gateway->gateway_name}", compact('gateway', 'pageTitle', 'deposit')); } public function gatewayRedirect(Request $request, $id) { $gateway = Gateway::where('status', 1)->findOrFail($id); if (session('type') == 'deposit') { $deposit = Deposit::where('transaction_id', session('trx'))->firstOrFail(); } else { $deposit = Payment::where('transaction_id', session('trx'))->firstOrFail(); } $name = $gateway->gateway_name; if($gateway->is_created){ $name = "manual"; } $new = __NAMESPACE__ . '\\Gateway\\' . $name . '\ProcessController'; $data = $new::process($request, $gateway, $deposit->final_amount, $deposit); if ($gateway->gateway_name == 'nowpayments') { return redirect()->to($data->invoice_url); } if ($gateway->gateway_name == 'mollie') { return redirect()->to($data['redirect_url']); } if ($gateway->gateway_name == 'paghiper') { if (isset($data['status']) && $data['status'] == false) { return redirect()->route('user.investmentproperty')->with('error', 'Something Went Wrong'); } return redirect()->to($data); } if ($gateway->gateway_name == 'coinpayments') { if (isset($data['result']['checkout_url'])) { return redirect()->to($data['result']['checkout_url']); } } if ($gateway->gateway_name == 'paypal') { $data = json_decode($data); return redirect()->to($data->links[1]->href); } $notify[] = ['success', 'Your Payment is Successfully Recieved']; return redirect()->route('home')->withNotify($notify); } public static function updateUserData($deposit, $fee_amount, $transaction) { $general = GeneralSetting::first(); $user = auth()->user(); if (session('type') == 'deposit') { $user->balance = $user->balance + $deposit->amount; $user->save(); } $deposit->payment_status = 1; $deposit->save(); if (!(session('type') == 'deposit')) { refferMoney($deposit->user->id, 'invest', $deposit->amount); } session()->forget('type'); Transaction::create([ 'trx' => $deposit->transaction_id, 'gateway_id' => $deposit->gateway_id, 'amount' => $deposit->final_amount, 'currency' => $general->site_currency, 'details' => 'Payment Successfull', 'charge' => $fee_amount, 'type' => '-', 'gateway_transaction' => $transaction, 'user_id' => auth()->id(), 'payment_status' => 1, ]); sendMail('PAYMENT_SUCCESSFULL', [ 'property' => $deposit->property->property_name ?? 'Deposit', 'trx' => $transaction, 'amount' => $deposit->amount, 'currency' => $general->site_currency, ], $deposit->user); } }