first commit
This commit is contained in:
152
app/Http/Controllers/Admin/PaymentController.php
Normal file
152
app/Http/Controllers/Admin/PaymentController.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Mollie\Laravel\Facades\Mollie;
|
||||
use Mollie\Api\Exceptions\ApiException;
|
||||
use Mollie\Api\MollieApiClient;
|
||||
use App\Models\Frontend\payment_transaction_master;
|
||||
use App\Models\Admin\program;
|
||||
use App\Models\Admin\country;
|
||||
use App\Exports\UsersExport;
|
||||
use Carbon\Carbon;
|
||||
use PDF;
|
||||
use Excel;
|
||||
|
||||
class PaymentController extends Controller {
|
||||
|
||||
public function index() {
|
||||
$weekAgo = Carbon::now()->subWeek();
|
||||
$latest_payments = payment_transaction_master::with('user', 'Programs.programe_country')
|
||||
->where('created_at', '>=', $weekAgo) // Filter transactions from the last week
|
||||
->orderByDesc('created_at')
|
||||
->get()
|
||||
->toArray();
|
||||
$register_payments = payment_transaction_master::with('user', 'Programs.programe_country')
|
||||
->where('payment_status', 1)
|
||||
->get()
|
||||
->toArray();
|
||||
$volunteer_payments = payment_transaction_master::with('user', 'Programs.programe_country')
|
||||
->where('payment_status', 2)
|
||||
->get()
|
||||
->toArray();
|
||||
$country = country::all()->toArray();
|
||||
// dd($latest_payments,$register_payments,$volunteer_payments);
|
||||
return view('Admin.Pages.manage_payments.manage_payment')->with(['latest_pay' => $latest_payments, 'regi_pay' => $register_payments, 'vol_pay' => $volunteer_payments, 'country' => $country]);
|
||||
}
|
||||
|
||||
public function createPayment(Request $request) {
|
||||
// dd($request->all());
|
||||
$paymentAmount = $request->query('payment_amount');
|
||||
$convertName = $request->query('selected_currency');
|
||||
$redirect_url = $request->query('redirect_url');
|
||||
$programId = $request->query('pro_id');
|
||||
$programWeek = $request->query('selected_week');
|
||||
$p_start_date = $request->query('start_date');
|
||||
$url = url($redirect_url);
|
||||
|
||||
$metadata = [
|
||||
'prog_id' => $programId,
|
||||
'prog_week' => $programWeek,
|
||||
'prog_start_date' => $p_start_date,
|
||||
];
|
||||
// dd($metadata);
|
||||
// dd($paymentAmount,$convertName,$redirect_url,$url,$progs_id,$progs_week,$p_start_date,$p_end_date);
|
||||
$payment = Mollie::api()->payments()->create([
|
||||
'amount' => [
|
||||
'currency' => $convertName,
|
||||
'value' => $paymentAmount
|
||||
],
|
||||
'metadata' => $metadata,
|
||||
'description' => 'Test payment',
|
||||
'redirectUrl' => $url
|
||||
]);
|
||||
|
||||
session(['transaction_id' => $payment->id]);
|
||||
$redirectUrl = $payment->getCheckoutUrl();
|
||||
return response()->json(['redirect_url' => $redirectUrl]);
|
||||
|
||||
}
|
||||
|
||||
// public function paymentStatus(Request $request) {
|
||||
// if (session()->has('transaction_id')) {
|
||||
// $transaction_id = session('transaction_id');
|
||||
// }
|
||||
//
|
||||
// $payment = Mollie::api()->payments()->get($transaction_id);
|
||||
//
|
||||
// // Process the payment status
|
||||
// if ($payment->isPaid()) {
|
||||
// // Payment is successful
|
||||
// // Do something here
|
||||
// } elseif ($payment->isOpen()) {
|
||||
// // Payment is still open
|
||||
// // Do something here
|
||||
// } elseif ($payment->isCanceled()) {
|
||||
// // Payment is canceled
|
||||
// // Do something here
|
||||
// }
|
||||
//
|
||||
// return view('payment.status', compact('payment'));
|
||||
// }
|
||||
|
||||
public function download_pdf($id) {
|
||||
try {
|
||||
$latest_payments = payment_transaction_master::with('user', 'Programs.programe_country')
|
||||
->where('id', $id)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
// $start_date = date('d-m-y', strtotime($latest_payments[0]['programs']['start_date']));
|
||||
if (isset($latest_payments[0]) && isset($latest_payments[0]['programs']) && isset($latest_payments[0]['programs']['start_date'])) {
|
||||
$start_date = date('d-m-y', strtotime($latest_payments[0]['programs']['start_date']));
|
||||
} else {
|
||||
// Set a default value here.
|
||||
$start_date = 'No start date available';
|
||||
}
|
||||
|
||||
// $end_date = date('d-m-y', strtotime($latest_payments[0]['programs']['end_date']));
|
||||
if (isset($latest_payments[0]) && isset($latest_payments[0]['programs']) && isset($latest_payments[0]['programs']['end_date'])) {
|
||||
$end_date = date('d-m-y', strtotime($latest_payments[0]['programs']['end_date']));
|
||||
} else {
|
||||
// Set a default value here.
|
||||
$end_date = 'No end date available';
|
||||
}
|
||||
|
||||
$data = [
|
||||
'title' => 'Payment Invoice',
|
||||
'date' => date('j F Y', strtotime('25 March 2023')),
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date,
|
||||
'latest_payments' => $latest_payments
|
||||
];
|
||||
|
||||
$pdf = PDF::loadView('Admin.Pages.manage_payments.payment_invoice', $data);
|
||||
|
||||
return $pdf->download('invoice.pdf');
|
||||
} catch (Exception $e) {
|
||||
// Handle the exception here, e.g., log it or return an error response.
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------export start here----------------------------------------------------------
|
||||
public function exportUser(Request $request) {
|
||||
$start_date = $request->input('start_date');
|
||||
$end_date = $request->input('end_date');
|
||||
$country_id = $request->input('country_id');
|
||||
|
||||
// Build filters based on the provided parameters
|
||||
$filters = [
|
||||
'start_date' => $start_date,
|
||||
'end_date' => $end_date,
|
||||
'country_id' => $country_id,
|
||||
];
|
||||
|
||||
// Pass the filters to the UsersExport class
|
||||
return Excel::download(new UsersExport($filters), 'users.xlsx');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user