2016-03-05 00:18:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2016-06-15 10:14:27 +00:00
|
|
|
use App\Events\OrderCompletedEvent;
|
2020-03-17 07:14:09 +00:00
|
|
|
use App\Jobs\ProcessPayment;
|
2016-02-29 15:59:36 +00:00
|
|
|
use App\Models\Attendee;
|
2016-03-05 00:18:10 +00:00
|
|
|
use App\Models\Event;
|
2016-02-29 15:59:36 +00:00
|
|
|
use App\Models\EventStats;
|
2016-03-05 00:18:10 +00:00
|
|
|
use App\Models\Order;
|
2016-02-29 15:59:36 +00:00
|
|
|
use App\Models\OrderItem;
|
2016-04-04 11:21:09 +00:00
|
|
|
use App\Models\QuestionAnswer;
|
2016-09-06 20:39:27 +00:00
|
|
|
use App\Models\ReservedTickets;
|
2016-03-05 00:18:10 +00:00
|
|
|
use App\Models\Ticket;
|
2019-08-16 13:04:50 +00:00
|
|
|
use App\Payment\CardPayment;
|
2020-03-17 07:14:09 +00:00
|
|
|
use App\Services\EventOrderService as OrderService;
|
2016-03-05 00:18:10 +00:00
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use Cookie;
|
|
|
|
|
use DB;
|
2016-05-08 15:36:26 +00:00
|
|
|
use Illuminate\Http\Request;
|
2016-03-05 00:18:10 +00:00
|
|
|
use Log;
|
|
|
|
|
use PDF;
|
2016-05-20 22:54:45 +00:00
|
|
|
use PhpSpec\Exception\Exception;
|
2016-03-05 00:18:10 +00:00
|
|
|
use Validator;
|
2016-03-07 17:18:55 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
class EventCheckoutController extends Controller
|
|
|
|
|
{
|
2016-03-16 01:13:49 +00:00
|
|
|
/**
|
|
|
|
|
* Is the checkout in an embedded Iframe?
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
2016-02-29 15:59:36 +00:00
|
|
|
protected $is_embedded;
|
2019-08-16 13:04:50 +00:00
|
|
|
/**
|
|
|
|
|
* Payment gateway
|
|
|
|
|
* @var CardPayment
|
|
|
|
|
*/
|
|
|
|
|
protected $gateway;
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
/**
|
|
|
|
|
* EventCheckoutController constructor.
|
|
|
|
|
* @param Request $request
|
|
|
|
|
*/
|
2019-08-16 13:04:50 +00:00
|
|
|
public function __construct(Request $request, CardPayment $gateway)
|
2016-02-29 15:59:36 +00:00
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* See if the checkout is being called from an embedded iframe.
|
|
|
|
|
*/
|
2016-03-16 01:13:49 +00:00
|
|
|
$this->is_embedded = $request->get('is_embedded') == '1';
|
2019-08-16 13:04:50 +00:00
|
|
|
$this->gateway = $gateway;
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-02 10:32:23 +00:00
|
|
|
public function postValidateDate(Request $request, $event_id){
|
|
|
|
|
|
|
|
|
|
$this->validate($request,['ticket_date'=>'required|date']);
|
|
|
|
|
$event = Event::with('venue')->findOrFail($event_id);
|
2019-11-06 10:05:24 +00:00
|
|
|
$tickets = Ticket::with(['section','reserved:seat_no,ticket_id','booked:seat_no,ticket_id'])
|
2019-11-02 10:32:23 +00:00
|
|
|
->where('event_id',$event_id)
|
|
|
|
|
->where('ticket_date',$request->get('ticket_date'))
|
|
|
|
|
->where('is_hidden', false)
|
|
|
|
|
->orderBy('sort_order','asc')
|
|
|
|
|
->get();
|
2020-03-17 07:14:09 +00:00
|
|
|
|
2019-11-05 12:28:51 +00:00
|
|
|
if($tickets->count()==0){
|
2019-11-02 10:32:23 +00:00
|
|
|
//todo flash message
|
|
|
|
|
session()->flash('error','There is no tickets available');
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
2019-11-05 12:28:51 +00:00
|
|
|
|
2020-02-21 13:44:46 +00:00
|
|
|
return $this->render('Pages.SeatsPage',compact('event','tickets'));
|
2019-11-02 10:32:23 +00:00
|
|
|
}
|
2016-03-16 01:13:49 +00:00
|
|
|
/**
|
|
|
|
|
* Validate a ticket request. If successful reserve the tickets and redirect to checkout
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @param $event_id
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
2019-11-05 12:28:51 +00:00
|
|
|
public function postValidateSeats(Request $request, $event_id){
|
|
|
|
|
if (!$request->has('seats')) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
2020-03-03 18:40:09 +00:00
|
|
|
'message' => trans('ClientSide.no_seats'),
|
2019-11-05 12:28:51 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Order expires after X min
|
|
|
|
|
*/
|
|
|
|
|
$order_expires_time = Carbon::now()->addMinutes(config('attendize.checkout_timeout_after'));
|
|
|
|
|
|
|
|
|
|
$event = Event::findOrFail($event_id);
|
|
|
|
|
$seats = $request->get('seats');
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove any tickets the user has reserved
|
|
|
|
|
*/
|
2020-04-02 07:35:45 +00:00
|
|
|
ReservedTickets::where('session_id', '=', session()->getId())
|
|
|
|
|
->whereNull('expects_payment_at')
|
|
|
|
|
->orWhere('expects_payment_at','<',Carbon::now()->addMinutes(-5))
|
|
|
|
|
->delete();
|
2019-11-05 12:28:51 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Go though the selected tickets and check if they're available
|
|
|
|
|
* , tot up the price and reserve them to prevent over selling.
|
|
|
|
|
*/
|
|
|
|
|
$order_total = 0;
|
|
|
|
|
$booking_fee = 0;
|
|
|
|
|
$organiser_booking_fee = 0;
|
|
|
|
|
$total_ticket_quantity = 0;
|
|
|
|
|
$reserved = [];
|
|
|
|
|
$tickets = [];
|
|
|
|
|
$validation_rules = [];
|
|
|
|
|
$validation_messages = [];
|
|
|
|
|
foreach ($seats as $ticket_id=>$ticket_seats){
|
|
|
|
|
$seats_count = count($ticket_seats);
|
2020-03-17 10:38:11 +00:00
|
|
|
if(!$seats_count)
|
2019-11-05 12:28:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
$seat_nos = array_values($ticket_seats);
|
|
|
|
|
$reserved_tickets = ReservedTickets::where('ticket_id',$ticket_id)
|
|
|
|
|
->where('expires','>',Carbon::now())
|
|
|
|
|
->whereIn('seat_no',$seat_nos)
|
|
|
|
|
->pluck('seat_no');
|
|
|
|
|
|
|
|
|
|
$booked_tickets = Attendee::where('ticket_id',$ticket_id)
|
|
|
|
|
->where('event_id',$event_id)
|
|
|
|
|
->whereIn('seat_no',$seat_nos)
|
|
|
|
|
->pluck('seat_no');
|
|
|
|
|
|
|
|
|
|
if(count($reserved_tickets)>0 || count($booked_tickets)>0)
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
2020-03-05 13:35:58 +00:00
|
|
|
'message' => trans('ClientSide.message_reserved'),//todo show which are reserved
|
2019-11-05 12:28:51 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$ticket = Ticket::findOrFail($ticket_id);
|
|
|
|
|
$max_per_person = min($ticket->quantity_remaining, $ticket->max_per_person);
|
|
|
|
|
/*
|
|
|
|
|
* Validation max min ticket count
|
|
|
|
|
*/
|
|
|
|
|
if($seats_count < $ticket->min_per_person){
|
2020-03-03 18:40:09 +00:00
|
|
|
$message = trans('ClientSide.min_ticket_message',['min' => $ticket->min_per_person]);
|
2019-11-05 12:28:51 +00:00
|
|
|
}elseif ($seats_count > $max_per_person){
|
2020-03-03 18:40:09 +00:00
|
|
|
$message = trans('ClientSide.max_ticket_message',['max' => $ticket->quantity_remaining]);
|
2019-11-05 12:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($message)) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'messages' => $message,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$total_ticket_quantity += $seats_count;
|
|
|
|
|
$order_total += ($seats_count * $ticket->price);
|
|
|
|
|
$booking_fee += ($seats_count * $ticket->booking_fee);
|
|
|
|
|
$organiser_booking_fee += ($seats_count * $ticket->organiser_booking_fee);
|
|
|
|
|
$tickets[] = [
|
|
|
|
|
'ticket' => $ticket,
|
|
|
|
|
'qty' => $seats_count,
|
|
|
|
|
'seats' => $ticket_seats,
|
|
|
|
|
'price' => ($seats_count * $ticket->price),
|
2020-03-24 12:05:40 +00:00
|
|
|
'booking_fee' => ($seats_count * $ticket->booking_fee),//total_service_booking_fee per ticket
|
|
|
|
|
'organiser_booking_fee' => ($seats_count * $ticket->organiser_booking_fee),//total_organiser_booking_fee per ticket
|
|
|
|
|
'total_booking_fee' => $ticket->total_booking_fee,//service + organiser original booking fee sum
|
2020-02-03 07:39:45 +00:00
|
|
|
'original_price' => $ticket->price,
|
2019-11-05 12:28:51 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($ticket_seats as $seat_no){
|
|
|
|
|
$reservedTickets = new ReservedTickets();
|
|
|
|
|
$reservedTickets->ticket_id = $ticket_id;
|
|
|
|
|
$reservedTickets->event_id = $event_id;
|
|
|
|
|
$reservedTickets->quantity_reserved = 1;
|
|
|
|
|
$reservedTickets->expires = $order_expires_time;
|
|
|
|
|
$reservedTickets->session_id = session()->getId();
|
|
|
|
|
$reservedTickets->seat_no = $seat_no;
|
|
|
|
|
$reserved[] = $reservedTickets->attributesToArray();
|
|
|
|
|
/*
|
|
|
|
|
* Create our validation rules here
|
|
|
|
|
*/
|
|
|
|
|
$validation_rules['ticket_holder_first_name.' . $seat_no . '.' . $ticket_id] = ['required'];
|
|
|
|
|
$validation_rules['ticket_holder_last_name.' . $seat_no . '.' . $ticket_id] = ['required'];
|
|
|
|
|
$validation_rules['ticket_holder_email.' . $seat_no . '.' . $ticket_id] = ['required', 'email'];
|
|
|
|
|
|
2020-03-03 18:40:09 +00:00
|
|
|
$validation_messages['ticket_holder_first_name.' . $seat_no . '.' . $ticket_id . '.required'] = trans('ClientSide.holder_first_name_required',['seat' => $seat_no]);
|
|
|
|
|
$validation_messages['ticket_holder_last_name.' . $seat_no . '.' . $ticket_id . '.required'] = trans('ClientSide.holder_last_name_required',['seat' => $seat_no]);
|
|
|
|
|
$validation_messages['ticket_holder_email.' . $seat_no . '.' . $ticket_id . '.required'] = trans('ClientSide.holder_email_required',['seat' => $seat_no]);;
|
|
|
|
|
$validation_messages['ticket_holder_email.' . $seat_no . '.' . $ticket_id . '.email'] = trans('ClientSide.holder_email_invalid',['seat' => $seat_no]);;
|
2019-11-05 12:28:51 +00:00
|
|
|
/*
|
|
|
|
|
* Validation rules for custom questions
|
|
|
|
|
*/
|
|
|
|
|
foreach ($ticket->questions as $question) {
|
|
|
|
|
if ($question->is_required && $question->is_enabled) {
|
|
|
|
|
$validation_rules['ticket_holder_questions.' . $ticket_id . '.' . $seat_no . '.' . $question->id] = ['required'];
|
2020-03-03 18:40:09 +00:00
|
|
|
$validation_messages['ticket_holder_questions.' . $ticket_id . '.' . $seat_no . '.' . $question->id . '.required'] = trans('ClientSide.question_required');
|
2019-11-05 12:28:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ReservedTickets::insert($reserved);
|
|
|
|
|
|
|
|
|
|
if (empty($tickets)) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'No tickets selected.',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* The 'ticket_order_{event_id}' session stores everything we need to complete the transaction.
|
|
|
|
|
*/
|
|
|
|
|
session()->put('ticket_order_' . $event->id, [
|
|
|
|
|
'validation_rules' => $validation_rules,
|
|
|
|
|
'validation_messages' => $validation_messages,
|
|
|
|
|
'event_id' => $event->id,
|
|
|
|
|
'tickets' => $tickets,
|
|
|
|
|
'total_ticket_quantity' => $total_ticket_quantity,
|
|
|
|
|
'order_started' => time(),
|
|
|
|
|
'expires' => $order_expires_time,
|
|
|
|
|
'order_total' => $order_total,
|
|
|
|
|
'booking_fee' => $booking_fee,
|
|
|
|
|
'organiser_booking_fee' => $organiser_booking_fee,
|
|
|
|
|
'total_booking_fee' => $booking_fee + $organiser_booking_fee,
|
|
|
|
|
'order_requires_payment' => (ceil($order_total) == 0) ? false : true,
|
|
|
|
|
'account_id' => $event->account->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we're this far assume everything is OK and redirect them
|
|
|
|
|
* to the the checkout page.
|
|
|
|
|
*/
|
|
|
|
|
if ($request->ajax()) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'redirectUrl' => route('showEventCheckout', [
|
|
|
|
|
'event_id' => $event_id,
|
|
|
|
|
'is_embedded' => $this->is_embedded,
|
|
|
|
|
]) . '#order_form',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* todo Maybe display something prettier than this?
|
|
|
|
|
*/
|
2020-03-03 18:40:09 +00:00
|
|
|
exit(trans('ClientSide.enable_javascript'));
|
2019-11-05 12:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
/**
|
|
|
|
|
* Show the checkout page
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @param $event_id
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
|
|
|
|
*/
|
|
|
|
|
public function showEventCheckout(Request $request, $event_id)
|
2016-02-29 15:59:36 +00:00
|
|
|
{
|
2016-04-04 11:21:09 +00:00
|
|
|
$order_session = session()->get('ticket_order_' . $event_id);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
if (!$order_session || $order_session['expires'] < Carbon::now()) {
|
2016-11-06 21:56:35 +00:00
|
|
|
$route_name = $this->is_embedded ? 'showEmbeddedEventPage' : 'showEventPage';
|
|
|
|
|
return redirect()->route($route_name, ['event_id' => $event_id]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$secondsToExpire = Carbon::now()->diffInSeconds($order_session['expires']);
|
|
|
|
|
|
2019-11-05 12:28:51 +00:00
|
|
|
$event = Event::with('venue')->findorFail($order_session['event_id']);
|
2018-07-10 08:36:42 +00:00
|
|
|
|
2018-07-10 10:19:20 +00:00
|
|
|
$orderService = new OrderService($order_session['order_total'], $order_session['total_booking_fee'], $event);
|
|
|
|
|
$orderService->calculateFinalCosts();
|
2018-07-10 08:36:42 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
$data = $order_session + [
|
2018-07-10 08:36:42 +00:00
|
|
|
'event' => $event,
|
2016-02-29 15:59:36 +00:00
|
|
|
'secondsToExpire' => $secondsToExpire,
|
2016-05-08 15:36:26 +00:00
|
|
|
'is_embedded' => $this->is_embedded,
|
2018-07-10 14:50:46 +00:00
|
|
|
'orderService' => $orderService
|
2018-07-10 08:36:42 +00:00
|
|
|
];
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
if ($this->is_embedded) {
|
2019-09-14 12:27:41 +00:00
|
|
|
return view('Public.ViewEvent.Embedded.EventPageCheckout', $data); // <--- todo check this out
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2020-02-21 13:44:46 +00:00
|
|
|
return $this->render('Pages.CheckoutPage', $data);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-16 13:04:50 +00:00
|
|
|
/**
|
|
|
|
|
* Create the order, handle payment, update stats, fire off email jobs then redirect user
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @param $event_id
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
|
*/
|
|
|
|
|
public function postCreateOrder(Request $request, $event_id)
|
2016-02-29 15:59:36 +00:00
|
|
|
{
|
2018-10-16 19:03:55 +00:00
|
|
|
//If there's no session kill the request and redirect back to the event homepage.
|
2019-09-17 14:19:57 +00:00
|
|
|
$order_session = session()->get('ticket_order_' . $event_id);
|
|
|
|
|
if (!$order_session) {
|
2016-05-05 23:18:52 +00:00
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Your session has expired.',
|
|
|
|
|
'redirectUrl' => route('showEventPage', [
|
|
|
|
|
'event_id' => $event_id,
|
|
|
|
|
])
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
$event = Event::findOrFail($event_id);
|
2016-04-04 11:21:09 +00:00
|
|
|
$ticket_order = session()->get('ticket_order_' . $event_id);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
$validation_rules = $ticket_order['validation_rules'];
|
|
|
|
|
$validation_messages = $ticket_order['validation_messages'];
|
|
|
|
|
|
2020-04-29 11:48:01 +00:00
|
|
|
$order = new Order();
|
2016-05-21 17:37:15 +00:00
|
|
|
$order->rules = $order->rules + $validation_rules;
|
|
|
|
|
$order->messages = $order->messages + $validation_messages;
|
2020-04-29 11:48:01 +00:00
|
|
|
$order->order_reference = strtoupper(str_random(5)) . date('jn');
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
if (!$order->validate($request->all())) {
|
|
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'error',
|
2016-03-05 00:18:10 +00:00
|
|
|
'messages' => $order->errors(),
|
|
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-29 19:23:05 +00:00
|
|
|
//Add the request data to a session in case payment is required off-site
|
2019-08-16 13:04:50 +00:00
|
|
|
session()->push('ticket_order_' . $event_id . '.request_data', $request->except(['card-number', 'card-cvc']));
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2018-10-16 19:03:55 +00:00
|
|
|
try {
|
2019-08-29 19:23:05 +00:00
|
|
|
$orderService = new OrderService($ticket_order['order_total'], $ticket_order['total_booking_fee'], $event);
|
|
|
|
|
$orderService->calculateFinalCosts();
|
2019-09-17 14:19:57 +00:00
|
|
|
$secondsToExpire = Carbon::now()->diffInSeconds($order_session['expires']);
|
2020-04-29 11:48:01 +00:00
|
|
|
|
2020-03-17 07:14:09 +00:00
|
|
|
$transaction_data =[
|
2019-09-23 14:07:27 +00:00
|
|
|
'amount' => $orderService->getGrandTotal()*100,//multiply by 100 to obtain tenge
|
2019-08-16 13:04:50 +00:00
|
|
|
'currency' => 934,
|
2019-09-17 14:19:57 +00:00
|
|
|
'sessionTimeoutSecs' => $secondsToExpire,
|
2020-03-17 07:14:09 +00:00
|
|
|
'description' => 'bilettm sargyt: ' . $request->get('order_email'),
|
2020-04-29 11:48:01 +00:00
|
|
|
'orderNumber' => $order->order_reference,
|
2020-01-29 17:16:15 +00:00
|
|
|
|
2019-08-16 13:04:50 +00:00
|
|
|
'failUrl' => route('showEventCheckoutPaymentReturn', [
|
|
|
|
|
'event_id' => $event_id,
|
|
|
|
|
'is_payment_cancelled' => 1
|
|
|
|
|
]),
|
|
|
|
|
'returnUrl' => route('showEventCheckoutPaymentReturn', [
|
|
|
|
|
'event_id' => $event_id,
|
|
|
|
|
'is_payment_successful' => 1
|
|
|
|
|
]),
|
|
|
|
|
|
2019-08-29 19:23:05 +00:00
|
|
|
];
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2019-08-16 13:04:50 +00:00
|
|
|
$response = $this->gateway->registerPayment($transaction_data);
|
|
|
|
|
|
|
|
|
|
if($response->isSuccessfull()){
|
2020-03-17 07:14:09 +00:00
|
|
|
|
|
|
|
|
$order->first_name = $request->get('order_first_name');
|
|
|
|
|
$order->last_name = $request->get('order_last_name');
|
|
|
|
|
$order->email = $request->get('order_email');
|
|
|
|
|
$order->order_status_id = 5;//order awaiting payment
|
|
|
|
|
$order->amount = $orderService->getGrandTotal();
|
|
|
|
|
$order->booking_fee = $ticket_order['booking_fee'];
|
|
|
|
|
$order->organiser_booking_fee = $ticket_order['organiser_booking_fee'];
|
|
|
|
|
$order->discount = 0.00;
|
|
|
|
|
$order->account_id = $event->account_id;
|
|
|
|
|
$order->event_id = $event_id;
|
|
|
|
|
$order->is_payment_received = 0;//false
|
|
|
|
|
$order->taxamt = $orderService->getTaxAmount();
|
|
|
|
|
$order->session_id = session()->getId();
|
|
|
|
|
$order->transaction_id = $response->getPaymentReferenceId();
|
|
|
|
|
$order->order_date = Carbon::now();
|
|
|
|
|
$order->save();
|
|
|
|
|
|
2020-03-17 13:40:28 +00:00
|
|
|
session()->push('ticket_order_' . $event_id . '.order_id', $order->id);
|
2018-10-16 19:03:55 +00:00
|
|
|
Log::info("Redirect url: " . $response->getRedirectUrl());
|
2016-09-07 21:48:07 +00:00
|
|
|
|
2018-10-16 19:03:55 +00:00
|
|
|
$return = [
|
|
|
|
|
'status' => 'success',
|
|
|
|
|
'redirectUrl' => $response->getRedirectUrl(),
|
2020-04-11 11:55:52 +00:00
|
|
|
'message' => trans('ClientSide.redirect_payment_message')
|
2018-10-16 19:03:55 +00:00
|
|
|
];
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2018-10-16 19:03:55 +00:00
|
|
|
return response()->json($return);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// display error to customer
|
2016-03-16 01:13:49 +00:00
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'error',
|
2019-08-16 13:04:50 +00:00
|
|
|
'message' => $response->errorMessage(),
|
2016-03-05 00:18:10 +00:00
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2018-10-16 19:03:55 +00:00
|
|
|
} catch (\Exeption $e) {
|
|
|
|
|
Log::error($e);
|
2020-03-03 18:40:09 +00:00
|
|
|
$error = trans('ClientSide.payment_error');
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 19:03:55 +00:00
|
|
|
if ($error) {
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => $error,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2016-03-20 16:01:50 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-20 22:54:45 +00:00
|
|
|
/**
|
2019-08-29 19:23:05 +00:00
|
|
|
* Attempt to complete a user's payment when they return from
|
|
|
|
|
* an off-site gateway
|
2016-05-20 22:54:45 +00:00
|
|
|
*
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @param $event_id
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
2016-03-20 16:01:50 +00:00
|
|
|
public function showEventCheckoutPaymentReturn(Request $request, $event_id)
|
|
|
|
|
{
|
2019-08-29 19:23:05 +00:00
|
|
|
if ($request->get('is_payment_cancelled') == '1') {
|
|
|
|
|
session()->flash('message', trans('Event.payment_cancelled'));
|
|
|
|
|
return response()->redirectToRoute('showEventCheckout', [
|
|
|
|
|
'event_id' => $event_id,
|
|
|
|
|
'is_payment_cancelled' => 1,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 09:49:45 +00:00
|
|
|
//todo check the refresh page condition
|
2020-03-17 07:14:09 +00:00
|
|
|
$order_id = session()->get('ticket_order_' . $event_id . '.order_id');
|
|
|
|
|
$ticket_order = session()->get('ticket_order_' . $event_id);
|
2020-03-17 15:38:32 +00:00
|
|
|
$order = Order::findOrFail(sanitise($order_id[0]));
|
2020-03-17 07:14:09 +00:00
|
|
|
foreach ($ticket_order['tickets'] as $attendee_details) {
|
|
|
|
|
/*
|
|
|
|
|
* Insert order items (for use in generating invoices)
|
|
|
|
|
*/
|
2020-03-17 14:49:24 +00:00
|
|
|
$unit_booking_fee = $attendee_details['ticket']['booking_fee'] + $attendee_details['ticket']['organiser_booking_fee'];
|
2020-03-18 07:46:13 +00:00
|
|
|
|
2020-03-17 14:43:19 +00:00
|
|
|
OrderItem::create([
|
2020-03-17 15:36:25 +00:00
|
|
|
'title' => $attendee_details['ticket']['title'],
|
2020-03-17 15:38:32 +00:00
|
|
|
'order_id' => $order->id,
|
2020-03-17 15:36:25 +00:00
|
|
|
'quantity' => $attendee_details['qty'],
|
|
|
|
|
'unit_price' => $attendee_details['ticket']['price'],
|
|
|
|
|
'unit_booking_fee' => $unit_booking_fee
|
2020-03-17 14:43:19 +00:00
|
|
|
]);
|
2020-03-17 07:14:09 +00:00
|
|
|
}
|
2020-01-09 12:10:46 +00:00
|
|
|
|
2020-03-17 15:36:25 +00:00
|
|
|
|
2020-03-17 07:14:09 +00:00
|
|
|
$response = $this->gateway->getPaymentStatus($order->transaction_id);
|
2020-01-09 12:10:46 +00:00
|
|
|
|
2020-04-29 11:48:01 +00:00
|
|
|
$resp_data = $response->getResponseData();
|
|
|
|
|
|
|
|
|
|
$order->payment_card_pan = $resp_data['Pan'];
|
|
|
|
|
$order->payment_card_expiration = $resp_data['expiration'];
|
|
|
|
|
$order->payment_card_holder_name = $resp_data['cardholderName'];
|
|
|
|
|
$order->payment_order_status = $resp_data['OrderStatus'];
|
|
|
|
|
$order->payment_error_code = $resp_data['ErrorCode'];
|
|
|
|
|
$order->payment_error_message = $resp_data['ErrorMessage'];
|
|
|
|
|
|
|
|
|
|
|
2020-01-09 12:32:12 +00:00
|
|
|
//todo try catch for connection errors
|
2019-08-16 13:04:50 +00:00
|
|
|
if ($response->isSuccessfull()) {
|
2020-03-17 07:14:09 +00:00
|
|
|
|
|
|
|
|
OrderService::completeOrder($ticket_order, $order);
|
|
|
|
|
return response()->redirectToRoute('showOrderDetails', [
|
|
|
|
|
'is_embedded' => $this->is_embedded,
|
|
|
|
|
'order_reference' => $order->order_reference,
|
2016-03-20 16:01:50 +00:00
|
|
|
]);
|
2020-03-17 07:14:09 +00:00
|
|
|
} else {
|
2020-03-24 12:05:40 +00:00
|
|
|
//some times bank responds as payment not processed and we check 5 minutes later paymant status
|
2020-04-11 15:02:23 +00:00
|
|
|
ProcessPayment::dispatch($order,$ticket_order)->delay(now()->addMinutes(5));
|
2020-03-17 07:14:09 +00:00
|
|
|
return $this->render('Pages.OrderExpectingPayment');
|
2016-03-20 16:01:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 15:31:15 +00:00
|
|
|
public function mobileCheckoutPaymentReturn(Request $request, $event_id){
|
2020-01-31 12:57:40 +00:00
|
|
|
if ($request->get('is_payment_cancelled') == '1') {
|
2020-03-30 17:31:59 +00:00
|
|
|
return view('mobile.Pages.CheckoutFailed',['message'=>trans('ClientSide.payment_cancelled')]);
|
2020-01-30 15:31:15 +00:00
|
|
|
}
|
2020-03-18 07:46:13 +00:00
|
|
|
else if(!$request->has('orderId')){
|
2020-03-30 17:31:59 +00:00
|
|
|
return view('mobile.Pages.CheckoutFailed',['message'=> trans('ClientSide.no_order_id')]);
|
2020-01-31 12:57:40 +00:00
|
|
|
}
|
2020-03-18 07:46:13 +00:00
|
|
|
|
|
|
|
|
$order = Order::select('orders.id','order_status_id','is_payment_received','amount','booking_fee','created_at',
|
|
|
|
|
'organiser_booking_fee','event_id','session_id','account_id','first_name','last_name','email','order_reference')
|
|
|
|
|
->with(['event:id,sales_volume,organiser_fees_volume,organiser_id,title,post_order_display_message'])
|
|
|
|
|
->where('event_id',$event_id)
|
2020-03-17 07:14:09 +00:00
|
|
|
->where('transaction_id',$request->get('orderId'))
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if(!$order){
|
2020-03-30 17:31:59 +00:00
|
|
|
return view('mobile.Pages.CheckoutFailed',['message'=> trans('ClientSide.order_error')]);
|
2020-03-17 07:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$reserved_tickets = ReservedTickets::select('ticket_id',DB::raw('count(*) as quantity'))
|
|
|
|
|
->groupBy('ticket_id')
|
|
|
|
|
->with(['ticket:id,price,title'])
|
|
|
|
|
->where('session_id', $order->session_id)
|
|
|
|
|
->where('event_id', $event_id)
|
|
|
|
|
->get();
|
|
|
|
|
/*
|
|
|
|
|
* Insert order items (for use in generating invoices)
|
|
|
|
|
*/
|
|
|
|
|
foreach ($reserved_tickets as $resTicket){
|
|
|
|
|
$orderItem = new OrderItem();
|
|
|
|
|
$orderItem->title = $resTicket->ticket->title;
|
|
|
|
|
$orderItem->quantity = $resTicket->quantity;
|
|
|
|
|
$orderItem->order_id = $order->id;
|
|
|
|
|
$orderItem->unit_price = $resTicket->ticket->price;
|
|
|
|
|
$orderItem->unit_booking_fee = $resTicket->ticket->booking_fee + $order->organiser_booking_fee;
|
|
|
|
|
$orderItem->save();
|
|
|
|
|
}
|
2020-01-31 12:57:40 +00:00
|
|
|
|
2020-01-30 15:31:15 +00:00
|
|
|
$response = $this->gateway->getPaymentStatus($request->get('orderId'));
|
|
|
|
|
|
2020-04-29 11:48:01 +00:00
|
|
|
$resp_data = $response->getResponseData();
|
|
|
|
|
|
|
|
|
|
$order->payment_card_pan = $resp_data['Pan'];
|
|
|
|
|
$order->payment_card_expiration = $resp_data['expiration'];
|
|
|
|
|
$order->payment_card_holder_name = $resp_data['cardholderName'];
|
|
|
|
|
$order->payment_order_status = $resp_data['OrderStatus'];
|
|
|
|
|
$order->payment_error_code = $resp_data['ErrorCode'];
|
|
|
|
|
$order->payment_error_message = $resp_data['ErrorMessage'];
|
|
|
|
|
|
|
|
|
|
|
2020-01-30 15:31:15 +00:00
|
|
|
if ($response->isSuccessfull()) {
|
2020-03-18 07:46:13 +00:00
|
|
|
$data = OrderService::mobileCompleteOrder($order);
|
2020-03-30 17:31:59 +00:00
|
|
|
return view('mobile.Pages.ViewOrderPageApp', $data);
|
2020-01-30 15:31:15 +00:00
|
|
|
} else {
|
2020-04-02 07:35:45 +00:00
|
|
|
ReservedTickets::where('session_id', $order->session_id)
|
|
|
|
|
->where('event_id', $event_id)
|
|
|
|
|
->update(['expects_payment_at' => Carbon::now()]);
|
2020-04-11 15:02:23 +00:00
|
|
|
ProcessPayment::dispatch($order)->delay(now()->addMinutes(5));
|
2020-03-24 12:55:57 +00:00
|
|
|
return $this->render('Pages.OrderExpectingPayment',$order);
|
2020-01-30 15:31:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
/**
|
2016-03-16 01:13:49 +00:00
|
|
|
* Show the order details page
|
2016-02-29 15:59:36 +00:00
|
|
|
*
|
2016-03-16 01:13:49 +00:00
|
|
|
* @param Request $request
|
|
|
|
|
* @param $order_reference
|
|
|
|
|
* @return \Illuminate\View\View
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-03-16 01:13:49 +00:00
|
|
|
public function showOrderDetails(Request $request, $order_reference)
|
2016-02-29 15:59:36 +00:00
|
|
|
{
|
|
|
|
|
$order = Order::where('order_reference', '=', $order_reference)->first();
|
|
|
|
|
|
|
|
|
|
if (!$order) {
|
2016-03-16 01:13:49 +00:00
|
|
|
abort(404);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-08 11:28:44 +00:00
|
|
|
$orderService = new OrderService($order->amount, $order->booking_fee+$order->organiser_booking_fee, $order->event);
|
2018-07-10 10:19:20 +00:00
|
|
|
$orderService->calculateFinalCosts();
|
|
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
$data = [
|
2018-07-10 10:19:20 +00:00
|
|
|
'order' => $order,
|
|
|
|
|
'orderService' => $orderService,
|
|
|
|
|
'event' => $order->event,
|
|
|
|
|
'tickets' => $order->event->tickets,
|
|
|
|
|
'is_embedded' => $this->is_embedded,
|
2016-02-29 15:59:36 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ($this->is_embedded) {
|
2016-03-16 01:13:49 +00:00
|
|
|
return view('Public.ViewEvent.Embedded.EventPageViewOrder', $data);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2020-03-30 16:38:19 +00:00
|
|
|
return $this->render('Pages.ViewOrderPage', $data);
|
2019-10-11 16:26:24 +00:00
|
|
|
// return view('Public.ViewEvent.EventPageViewOrder', $data);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-03-16 01:13:49 +00:00
|
|
|
* Shows the tickets for an order - either HTML or PDF
|
2016-02-29 15:59:36 +00:00
|
|
|
*
|
2016-03-16 01:13:49 +00:00
|
|
|
* @param Request $request
|
|
|
|
|
* @param $order_reference
|
|
|
|
|
* @return \Illuminate\View\View
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-03-16 01:13:49 +00:00
|
|
|
public function showOrderTickets(Request $request, $order_reference)
|
2016-02-29 15:59:36 +00:00
|
|
|
{
|
|
|
|
|
$order = Order::where('order_reference', '=', $order_reference)->first();
|
|
|
|
|
|
|
|
|
|
if (!$order) {
|
2016-03-16 01:13:49 +00:00
|
|
|
abort(404);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
(localization) Several big changes:
1) Added localization components to the package. They allow usage of localized routes, like http://attendize.site/en/login
2) Added English and Polish localization files. They are ugly, repetitive, but mostly true to the original and relevant. It required rewriting several phrases, and certainly required editing most of the views and controllers.
3) Edited routes to accomodate point 1
4) Rewritten several rules regarding dates. In most cases using English notation (with English names for months) is bad in all other languages. I used environment wide date format that is used.
5) Updated installer. Haven't tested it yet, but should work. Rewrites .env.example file instead of creating it from scratch (by concatenating strings).
There are some minor changes that were simple fixes or other funky requirements from my employer that kinda make sense:
1) QR code reader wasn't working in firefox, fixed it. Works in chrome/firefox on mobile on https sites.
2) Added subscript text in some instances: below ticket registration, below ticket. It is kinda dumb, but in most cases is necessary to receive less complaints from clients.
3) Fixed geocoding api by adding api key in env file. At some point in 2016-2017 it was required by google to use API key from developer console and this requirement wasn't challenged in the code.
4) Ticket has been displaying either flyer or site logo on the side. Now displays both (which may affect 1d barcode - it might need some fixin). Regarding the same issue - description of an event contained the flyer image on the side, it was removed, cause it didn't fit in here.
5) Ticket style was updated, because of the above and because it didn't fit longer character strings. Now it's slightly uglier, but works in all cases.
and other.
There are also some inconveniences, like:
1) Unfinished translations. It was impossible for me to create translations based on strings located inside of a database, which I ignored (I think it's only at one place - surveys).
2) Ugly translation files. At some point I thought it is going to be easier to locate when I try translating vased by file name. Later I divided it by topics, and then I segmented it even more. It might require some serious clean-up.
3) Redundancy. In some cases there are several definitions for the same phrase in my localization files. I used it mostly to protect myself from different contexts for the phrase usage in different languages.
4) File division. There are several files that are placed in dedicated language directory (in /view/, like /view/pl/ or /view/en/). These files don't use language phrases, but they are translated as a whole. Mostly because using language phrases would make those view files unreadable.
5) Localzation helper marks some phrases as obsolete (in file "basic"), because they are used in app/Helpers folder (where this plugin doesn't reach)
2018-05-03 21:41:22 +00:00
|
|
|
$images = [];
|
|
|
|
|
$imgs = $order->event->images;
|
|
|
|
|
foreach ($imgs as $img) {
|
|
|
|
|
$images[] = base64_encode(file_get_contents(public_path($img->image_path)));
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
$data = [
|
2016-05-08 15:36:26 +00:00
|
|
|
'order' => $order,
|
|
|
|
|
'event' => $order->event,
|
|
|
|
|
'tickets' => $order->event->tickets,
|
2016-03-05 00:18:10 +00:00
|
|
|
'attendees' => $order->attendees,
|
2016-05-20 23:09:34 +00:00
|
|
|
'css' => file_get_contents(public_path('assets/stylesheet/ticket.css')),
|
|
|
|
|
'image' => base64_encode(file_get_contents(public_path($order->event->organiser->full_logo_path))),
|
(localization) Several big changes:
1) Added localization components to the package. They allow usage of localized routes, like http://attendize.site/en/login
2) Added English and Polish localization files. They are ugly, repetitive, but mostly true to the original and relevant. It required rewriting several phrases, and certainly required editing most of the views and controllers.
3) Edited routes to accomodate point 1
4) Rewritten several rules regarding dates. In most cases using English notation (with English names for months) is bad in all other languages. I used environment wide date format that is used.
5) Updated installer. Haven't tested it yet, but should work. Rewrites .env.example file instead of creating it from scratch (by concatenating strings).
There are some minor changes that were simple fixes or other funky requirements from my employer that kinda make sense:
1) QR code reader wasn't working in firefox, fixed it. Works in chrome/firefox on mobile on https sites.
2) Added subscript text in some instances: below ticket registration, below ticket. It is kinda dumb, but in most cases is necessary to receive less complaints from clients.
3) Fixed geocoding api by adding api key in env file. At some point in 2016-2017 it was required by google to use API key from developer console and this requirement wasn't challenged in the code.
4) Ticket has been displaying either flyer or site logo on the side. Now displays both (which may affect 1d barcode - it might need some fixin). Regarding the same issue - description of an event contained the flyer image on the side, it was removed, cause it didn't fit in here.
5) Ticket style was updated, because of the above and because it didn't fit longer character strings. Now it's slightly uglier, but works in all cases.
and other.
There are also some inconveniences, like:
1) Unfinished translations. It was impossible for me to create translations based on strings located inside of a database, which I ignored (I think it's only at one place - surveys).
2) Ugly translation files. At some point I thought it is going to be easier to locate when I try translating vased by file name. Later I divided it by topics, and then I segmented it even more. It might require some serious clean-up.
3) Redundancy. In some cases there are several definitions for the same phrase in my localization files. I used it mostly to protect myself from different contexts for the phrase usage in different languages.
4) File division. There are several files that are placed in dedicated language directory (in /view/, like /view/pl/ or /view/en/). These files don't use language phrases, but they are translated as a whole. Mostly because using language phrases would make those view files unreadable.
5) Localzation helper marks some phrases as obsolete (in file "basic"), because they are used in app/Helpers folder (where this plugin doesn't reach)
2018-05-03 21:41:22 +00:00
|
|
|
'images' => $images,
|
2016-02-29 15:59:36 +00:00
|
|
|
];
|
|
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
if ($request->get('download') == '1') {
|
2016-12-01 22:11:34 +00:00
|
|
|
return PDF::html('Public.ViewEvent.Partials.PDFTicket', $data, 'Tickets');
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-12-01 22:11:34 +00:00
|
|
|
return view('Public.ViewEvent.Partials.PDFTicket', $data);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-08-29 19:23:05 +00:00
|
|
|
|