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;
|
2016-02-29 15:59:36 +00:00
|
|
|
use App\Models\Affiliate;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
2016-03-07 17:37:16 +00:00
|
|
|
use Omnipay;
|
2016-03-05 00:18:10 +00:00
|
|
|
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;
|
|
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
/**
|
|
|
|
|
* EventCheckoutController constructor.
|
|
|
|
|
* @param Request $request
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Request $request)
|
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';
|
2016-02-29 15:59:36 +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
|
|
|
|
|
*/
|
|
|
|
|
public function postValidateTickets(Request $request, $event_id)
|
2016-02-29 15:59:36 +00:00
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Order expires after X min
|
|
|
|
|
*/
|
2016-03-04 23:27:13 +00:00
|
|
|
$order_expires_time = Carbon::now()->addMinutes(config('attendize.checkout_timeout_after'));
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
$event = Event::findOrFail($event_id);
|
|
|
|
|
|
2016-08-29 11:25:49 +00:00
|
|
|
if (!$request->has('tickets')) {
|
|
|
|
|
return response()->json([
|
2016-09-06 20:39:27 +00:00
|
|
|
'status' => 'error',
|
2016-08-29 11:25:49 +00:00
|
|
|
'message' => 'No tickets selected',
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
$ticket_ids = $request->get('tickets');
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Remove any tickets the user has reserved
|
|
|
|
|
*/
|
2016-03-16 01:13:49 +00:00
|
|
|
ReservedTickets::where('session_id', '=', session()->getId())->delete();
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
/*
|
2016-03-05 00:18:10 +00:00
|
|
|
* Go though the selected tickets and check if they're available
|
2016-02-29 15:59:36 +00:00
|
|
|
* , tot up the price and reserve them to prevent over selling.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$validation_rules = [];
|
|
|
|
|
$validation_messages = [];
|
|
|
|
|
$tickets = [];
|
|
|
|
|
$order_total = 0;
|
|
|
|
|
$total_ticket_quantity = 0;
|
|
|
|
|
$booking_fee = 0;
|
|
|
|
|
$organiser_booking_fee = 0;
|
|
|
|
|
$quantity_available_validation_rules = [];
|
|
|
|
|
|
|
|
|
|
foreach ($ticket_ids as $ticket_id) {
|
2016-04-04 11:21:09 +00:00
|
|
|
$current_ticket_quantity = (int)$request->get('ticket_' . $ticket_id);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
if ($current_ticket_quantity < 1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$total_ticket_quantity = $total_ticket_quantity + $current_ticket_quantity;
|
|
|
|
|
|
|
|
|
|
$ticket = Ticket::find($ticket_id);
|
|
|
|
|
|
|
|
|
|
$ticket_quantity_remaining = $ticket->quantity_remaining;
|
|
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
$max_per_person = min($ticket_quantity_remaining, $ticket->max_per_person);
|
|
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
$quantity_available_validation_rules['ticket_' . $ticket_id] = [
|
|
|
|
|
'numeric',
|
|
|
|
|
'min:' . $ticket->min_per_person,
|
|
|
|
|
'max:' . $max_per_person
|
|
|
|
|
];
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
$quantity_available_validation_messages = [
|
2016-04-04 11:21:09 +00:00
|
|
|
'ticket_' . $ticket_id . '.max' => 'The maximum number of tickets you can register is ' . $ticket_quantity_remaining,
|
|
|
|
|
'ticket_' . $ticket_id . '.min' => 'You must select at least ' . $ticket->min_per_person . ' tickets.',
|
2016-02-29 15:59:36 +00:00
|
|
|
];
|
|
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
$validator = Validator::make(['ticket_' . $ticket_id => (int)$request->get('ticket_' . $ticket_id)],
|
|
|
|
|
$quantity_available_validation_rules, $quantity_available_validation_messages);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
2016-03-16 01:13:49 +00:00
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'error',
|
2016-03-05 00:18:10 +00:00
|
|
|
'messages' => $validator->messages()->toArray(),
|
2016-02-29 15:59:36 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$order_total = $order_total + ($current_ticket_quantity * $ticket->price);
|
|
|
|
|
$booking_fee = $booking_fee + ($current_ticket_quantity * $ticket->booking_fee);
|
|
|
|
|
$organiser_booking_fee = $organiser_booking_fee + ($current_ticket_quantity * $ticket->organiser_booking_fee);
|
|
|
|
|
|
|
|
|
|
$tickets[] = [
|
2016-05-08 15:36:26 +00:00
|
|
|
'ticket' => $ticket,
|
|
|
|
|
'qty' => $current_ticket_quantity,
|
|
|
|
|
'price' => ($current_ticket_quantity * $ticket->price),
|
|
|
|
|
'booking_fee' => ($current_ticket_quantity * $ticket->booking_fee),
|
2016-02-29 15:59:36 +00:00
|
|
|
'organiser_booking_fee' => ($current_ticket_quantity * $ticket->organiser_booking_fee),
|
2016-05-08 15:36:26 +00:00
|
|
|
'full_price' => $ticket->price + $ticket->total_booking_fee,
|
2016-02-29 15:59:36 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/*
|
2016-05-08 15:36:26 +00:00
|
|
|
* Reserve the tickets for X amount of minutes
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
$reservedTickets = new ReservedTickets();
|
2016-02-29 15:59:36 +00:00
|
|
|
$reservedTickets->ticket_id = $ticket_id;
|
|
|
|
|
$reservedTickets->event_id = $event_id;
|
|
|
|
|
$reservedTickets->quantity_reserved = $current_ticket_quantity;
|
|
|
|
|
$reservedTickets->expires = $order_expires_time;
|
2016-03-16 01:13:49 +00:00
|
|
|
$reservedTickets->session_id = session()->getId();
|
2016-02-29 15:59:36 +00:00
|
|
|
$reservedTickets->save();
|
|
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
for ($i = 0; $i < $current_ticket_quantity; $i++) {
|
|
|
|
|
/*
|
|
|
|
|
* Create our validation rules here
|
|
|
|
|
*/
|
|
|
|
|
$validation_rules['ticket_holder_first_name.' . $i . '.' . $ticket_id] = ['required'];
|
|
|
|
|
$validation_rules['ticket_holder_last_name.' . $i . '.' . $ticket_id] = ['required'];
|
|
|
|
|
$validation_rules['ticket_holder_email.' . $i . '.' . $ticket_id] = ['required', 'email'];
|
2016-04-04 11:21:09 +00:00
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
$validation_messages['ticket_holder_first_name.' . $i . '.' . $ticket_id . '.required'] = 'Ticket holder ' . ($i + 1) . '\'s first name is required';
|
|
|
|
|
$validation_messages['ticket_holder_last_name.' . $i . '.' . $ticket_id . '.required'] = 'Ticket holder ' . ($i + 1) . '\'s last name is required';
|
|
|
|
|
$validation_messages['ticket_holder_email.' . $i . '.' . $ticket_id . '.required'] = 'Ticket holder ' . ($i + 1) . '\'s email is required';
|
|
|
|
|
$validation_messages['ticket_holder_email.' . $i . '.' . $ticket_id . '.email'] = 'Ticket holder ' . ($i + 1) . '\'s email appears to be invalid';
|
2016-04-04 15:20:35 +00:00
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
/*
|
|
|
|
|
* Validation rules for custom questions
|
|
|
|
|
*/
|
|
|
|
|
foreach ($ticket->questions as $question) {
|
2016-04-04 15:20:35 +00:00
|
|
|
|
2016-05-28 08:20:15 +00:00
|
|
|
if ($question->is_required && $question->is_enabled) {
|
2016-05-08 15:36:26 +00:00
|
|
|
$validation_rules['ticket_holder_questions.' . $ticket_id . '.' . $i . '.' . $question->id] = ['required'];
|
|
|
|
|
$validation_messages['ticket_holder_questions.' . $ticket_id . '.' . $i . '.' . $question->id . '.required'] = "This question is required";
|
2016-04-04 15:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-04-04 15:20:35 +00:00
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($tickets)) {
|
2016-03-16 01:13:49 +00:00
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'error',
|
2016-03-05 00:18:10 +00:00
|
|
|
'message' => 'No tickets selected.',
|
|
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2016-07-07 23:00:18 +00:00
|
|
|
* The 'ticket_order_{event_id}' session stores everything we need to complete the transaction.
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-04-04 11:21:09 +00:00
|
|
|
session()->set('ticket_order_' . $event->id, [
|
2016-05-08 15:36:26 +00:00
|
|
|
'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,
|
|
|
|
|
'reserved_tickets_id' => $reservedTickets->id,
|
|
|
|
|
'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,
|
|
|
|
|
'affiliate_referral' => Cookie::get('affiliate_' . $event_id),
|
2016-04-04 11:21:09 +00:00
|
|
|
'account_payment_gateway' => count($event->account->active_payment_gateway) ? $event->account->active_payment_gateway : false,
|
2016-05-08 15:36:26 +00:00
|
|
|
'payment_gateway' => count($event->account->active_payment_gateway) ? $event->account->active_payment_gateway->payment_gateway : false,
|
2016-02-29 15:59:36 +00:00
|
|
|
]);
|
|
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
/*
|
|
|
|
|
* If we're this far assume everything is OK and redirect them
|
|
|
|
|
* to the the checkout page.
|
|
|
|
|
*/
|
2016-03-16 01:13:49 +00:00
|
|
|
if ($request->ajax()) {
|
|
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'success',
|
2016-02-29 15:59:36 +00:00
|
|
|
'redirectUrl' => route('showEventCheckout', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'event_id' => $event_id,
|
2016-03-05 00:18:10 +00:00
|
|
|
'is_embedded' => $this->is_embedded,
|
2016-04-04 11:21:09 +00:00
|
|
|
]) . '#order_form',
|
2016-03-05 00:18:10 +00:00
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-07 23:00:18 +00:00
|
|
|
/*
|
|
|
|
|
* Maybe display something prettier than this?
|
|
|
|
|
*/
|
2016-03-20 16:01:50 +00:00
|
|
|
exit('Please enable Javascript in your browser.');
|
2016-02-29 15:59:36 +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']);
|
|
|
|
|
|
|
|
|
|
$data = $order_session + [
|
2016-05-08 15:36:26 +00:00
|
|
|
'event' => Event::findorFail($order_session['event_id']),
|
2016-02-29 15:59:36 +00:00
|
|
|
'secondsToExpire' => $secondsToExpire,
|
2016-05-08 15:36:26 +00:00
|
|
|
'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.EventPageCheckout', $data);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-16 01:13:49 +00:00
|
|
|
return view('Public.ViewEvent.EventPageCheckout', $data);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-16 01:13:49 +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
|
|
|
{
|
2016-05-05 23:18:52 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If there's no session kill the request and redirect back to the event homepage.
|
|
|
|
|
*/
|
2016-05-08 15:36:26 +00:00
|
|
|
if (!session()->get('ticket_order_' . $event_id)) {
|
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-03-20 16:01:50 +00:00
|
|
|
$order = new Order;
|
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'];
|
|
|
|
|
|
2016-05-21 17:37:15 +00:00
|
|
|
$order->rules = $order->rules + $validation_rules;
|
|
|
|
|
$order->messages = $order->messages + $validation_messages;
|
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
|
|
|
}
|
|
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
/*
|
|
|
|
|
* Add the request data to a session in case payment is required off-site
|
|
|
|
|
*/
|
2016-04-04 11:21:09 +00:00
|
|
|
session()->push('ticket_order_' . $event_id . '.request_data', $request->except(['card-number', 'card-cvc']));
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
/*
|
2016-02-29 15:59:36 +00:00
|
|
|
* Begin payment attempt before creating the attendees etc.
|
|
|
|
|
* */
|
|
|
|
|
if ($ticket_order['order_requires_payment']) {
|
2016-07-09 11:06:44 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check if the user has chosen to pay offline
|
|
|
|
|
* and if they are allowed
|
|
|
|
|
*/
|
2016-09-06 20:39:27 +00:00
|
|
|
if ($request->get('pay_offline') && $event->enable_offline_payments) {
|
2016-07-09 11:06:44 +00:00
|
|
|
return $this->completeOrder($event_id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
try {
|
|
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
$gateway = Omnipay::create($ticket_order['payment_gateway']->name);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
$gateway->initialize($ticket_order['account_payment_gateway']->config + [
|
|
|
|
|
'testMode' => config('attendize.enable_test_payments'),
|
|
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-09-07 22:04:23 +00:00
|
|
|
$transaction_data = [
|
|
|
|
|
'amount' => ($ticket_order['order_total'] + $ticket_order['organiser_booking_fee']),
|
|
|
|
|
'currency' => $event->currency->code,
|
|
|
|
|
'description' => 'Order for customer: ' . $request->get('order_email'),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
2016-04-04 11:21:09 +00:00
|
|
|
switch ($ticket_order['payment_gateway']->id) {
|
2016-03-20 16:01:50 +00:00
|
|
|
case config('attendize.payment_gateway_paypal'):
|
2016-03-21 00:05:25 +00:00
|
|
|
case config('attendize.payment_gateway_coinbase'):
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-09-07 22:04:23 +00:00
|
|
|
$transaction_data += [
|
2016-04-04 11:21:09 +00:00
|
|
|
'cancelUrl' => route('showEventCheckoutPaymentReturn', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'event_id' => $event_id,
|
2016-03-20 16:01:50 +00:00
|
|
|
'is_payment_cancelled' => 1
|
|
|
|
|
]),
|
2016-04-04 11:21:09 +00:00
|
|
|
'returnUrl' => route('showEventCheckoutPaymentReturn', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'event_id' => $event_id,
|
2016-03-20 16:01:50 +00:00
|
|
|
'is_payment_successful' => 1
|
|
|
|
|
]),
|
|
|
|
|
'brandName' => isset($ticket_order['account_payment_gateway']->config['brandingName'])
|
|
|
|
|
? $ticket_order['account_payment_gateway']->config['brandingName']
|
|
|
|
|
: $event->organiser->name
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
case config('attendize.payment_gateway_stripe'):
|
|
|
|
|
$token = $request->get('stripeToken');
|
2016-09-07 22:04:23 +00:00
|
|
|
$transaction_data += [
|
2016-11-09 22:02:42 +00:00
|
|
|
'token' => $token,
|
|
|
|
|
'receipt_email' => $request->get('order_email'),
|
2016-03-20 16:01:50 +00:00
|
|
|
];
|
|
|
|
|
break;
|
2016-09-07 21:48:07 +00:00
|
|
|
case config('attendize.payment_gateway_migs'):
|
2016-09-07 22:04:23 +00:00
|
|
|
$transaction_data += [
|
2016-09-08 03:23:24 +00:00
|
|
|
'transactionId' => $event_id . date('YmdHis'), // TODO: Where to generate transaction id?
|
2016-09-07 21:48:07 +00:00
|
|
|
'returnUrl' => route('showEventCheckoutPaymentReturn', [
|
|
|
|
|
'event_id' => $event_id,
|
|
|
|
|
'is_payment_successful' => 1
|
|
|
|
|
]),
|
2016-09-08 03:23:24 +00:00
|
|
|
|
2016-09-07 21:48:07 +00:00
|
|
|
];
|
2016-09-07 22:04:23 +00:00
|
|
|
|
2016-09-08 03:23:24 +00:00
|
|
|
// Order description in MIGS is only 34 characters long; so we need a short description
|
2016-10-07 13:43:04 +00:00
|
|
|
$transaction_data['description'] = "Ticket sales " . $transaction_data['transactionId'];
|
2016-09-07 22:04:23 +00:00
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Log::error('No payment gateway configured.');
|
|
|
|
|
return repsonse()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'error',
|
2016-03-20 16:01:50 +00:00
|
|
|
'message' => 'No payment gateway configured.'
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$transaction = $gateway->purchase($transaction_data);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-06 17:59:19 +00:00
|
|
|
$response = $transaction->send();
|
|
|
|
|
|
|
|
|
|
if ($response->isSuccessful()) {
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-06-15 10:14:27 +00:00
|
|
|
session()->push('ticket_order_' . $event_id . '.transaction_id',
|
|
|
|
|
$response->getTransactionReference());
|
2016-05-28 08:28:53 +00:00
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
return $this->completeOrder($event_id);
|
|
|
|
|
|
2016-03-06 17:59:19 +00:00
|
|
|
} elseif ($response->isRedirect()) {
|
2016-03-20 16:01:50 +00:00
|
|
|
|
|
|
|
|
/*
|
2016-07-07 23:00:18 +00:00
|
|
|
* As we're going off-site for payment we need to store some data in a session so it's available
|
|
|
|
|
* when we return
|
2016-03-20 16:01:50 +00:00
|
|
|
*/
|
2016-04-04 11:21:09 +00:00
|
|
|
session()->push('ticket_order_' . $event_id . '.transaction_data', $transaction_data);
|
2016-09-07 20:57:21 +00:00
|
|
|
Log::info("Redirect url: " . $response->getRedirectUrl());
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-09-07 21:48:07 +00:00
|
|
|
$return = [
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'success',
|
|
|
|
|
'redirectUrl' => $response->getRedirectUrl(),
|
|
|
|
|
'message' => 'Redirecting to ' . $ticket_order['payment_gateway']->provider_name
|
2016-09-07 21:48:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// GET method requests should not have redirectData on the JSON return string
|
|
|
|
|
if($response->getRedirectMethod() == 'POST') {
|
|
|
|
|
$return['redirectData'] = $response->getRedirectData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json($return);
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
} else {
|
2016-03-06 17:59:19 +00:00
|
|
|
// 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',
|
2016-03-06 17:59:19 +00:00
|
|
|
'message' => $response->getMessage(),
|
2016-03-05 00:18:10 +00:00
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-06 17:59:19 +00:00
|
|
|
} catch (\Exeption $e) {
|
2016-02-29 15:59:36 +00:00
|
|
|
Log::error($e);
|
2016-03-06 17:59:19 +00:00
|
|
|
$error = 'Sorry, there was an error processing your payment. Please try again.';
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-06 17:59:19 +00:00
|
|
|
if ($error) {
|
2016-03-16 01:13:49 +00:00
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'error',
|
2016-03-06 17:59:19 +00:00
|
|
|
'message' => $error,
|
2016-03-05 00:18:10 +00:00
|
|
|
]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* No payment required so go ahead and complete the order
|
|
|
|
|
*/
|
|
|
|
|
return $this->completeOrder($event_id);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-05-20 22:54:45 +00:00
|
|
|
/**
|
|
|
|
|
* Attempt to complete a user's payment when they return from
|
|
|
|
|
* an off-site gateway
|
|
|
|
|
*
|
|
|
|
|
* @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)
|
|
|
|
|
{
|
|
|
|
|
|
2016-04-04 11:21:09 +00:00
|
|
|
if ($request->get('is_payment_cancelled') == '1') {
|
2016-03-20 16:01:50 +00:00
|
|
|
session()->flash('message', 'You cancelled your payment. You may try again.');
|
|
|
|
|
return response()->redirectToRoute('showEventCheckout', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'event_id' => $event_id,
|
2016-03-20 16:01:50 +00:00
|
|
|
'is_payment_cancelled' => 1,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ticket_order = session()->get('ticket_order_' . $event_id);
|
|
|
|
|
$gateway = Omnipay::create($ticket_order['payment_gateway']->name);
|
|
|
|
|
|
|
|
|
|
$gateway->initialize($ticket_order['account_payment_gateway']->config + [
|
|
|
|
|
'testMode' => config('attendize.enable_test_payments'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$transaction = $gateway->completePurchase($ticket_order['transaction_data'][0]);
|
|
|
|
|
|
|
|
|
|
$response = $transaction->send();
|
|
|
|
|
|
|
|
|
|
if ($response->isSuccessful()) {
|
2016-04-04 11:21:09 +00:00
|
|
|
session()->push('ticket_order_' . $event_id . '.transaction_id', $response->getTransactionReference());
|
2016-03-20 16:01:50 +00:00
|
|
|
return $this->completeOrder($event_id, false);
|
|
|
|
|
} else {
|
|
|
|
|
session()->flash('message', $response->getMessage());
|
|
|
|
|
return response()->redirectToRoute('showEventCheckout', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'event_id' => $event_id,
|
2016-03-20 16:01:50 +00:00
|
|
|
'is_payment_failed' => 1,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Complete an order
|
|
|
|
|
*
|
|
|
|
|
* @param $event_id
|
|
|
|
|
* @param bool|true $return_json
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
2016-04-04 11:21:09 +00:00
|
|
|
public function completeOrder($event_id, $return_json = true)
|
2016-03-20 16:01:50 +00:00
|
|
|
{
|
|
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
DB::beginTransaction();
|
2016-04-04 11:21:09 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
try {
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
$order = new Order();
|
|
|
|
|
$ticket_order = session()->get('ticket_order_' . $event_id);
|
|
|
|
|
$request_data = $ticket_order['request_data'][0];
|
|
|
|
|
$event = Event::findOrFail($ticket_order['event_id']);
|
|
|
|
|
$attendee_increment = 1;
|
|
|
|
|
$ticket_questions = isset($request_data['ticket_holder_questions']) ? $request_data['ticket_holder_questions'] : [];
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
/*
|
|
|
|
|
* Create the order
|
|
|
|
|
*/
|
|
|
|
|
if (isset($ticket_order['transaction_id'])) {
|
|
|
|
|
$order->transaction_id = $ticket_order['transaction_id'][0];
|
|
|
|
|
}
|
2016-09-06 20:39:27 +00:00
|
|
|
if ($ticket_order['order_requires_payment'] && !isset($request_data['pay_offline'])) {
|
2016-05-28 08:28:53 +00:00
|
|
|
$order->payment_gateway_id = $ticket_order['payment_gateway']->id;
|
|
|
|
|
}
|
|
|
|
|
$order->first_name = $request_data['order_first_name'];
|
|
|
|
|
$order->last_name = $request_data['order_last_name'];
|
|
|
|
|
$order->email = $request_data['order_email'];
|
2016-07-09 14:19:09 +00:00
|
|
|
$order->order_status_id = isset($request_data['pay_offline']) ? config('attendize.order_awaiting_payment') : config('attendize.order_complete');
|
2016-05-28 08:28:53 +00:00
|
|
|
$order->amount = $ticket_order['order_total'];
|
|
|
|
|
$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 = $ticket_order['event_id'];
|
2016-07-09 14:19:09 +00:00
|
|
|
$order->is_payment_received = isset($request_data['pay_offline']) ? 0 : 1;
|
2016-05-28 08:28:53 +00:00
|
|
|
$order->save();
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
/*
|
2016-05-28 08:28:53 +00:00
|
|
|
* Update the event sales volume
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-05-28 08:28:53 +00:00
|
|
|
$event->increment('sales_volume', $order->amount);
|
|
|
|
|
$event->increment('organiser_fees_volume', $order->organiser_booking_fee);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
/*
|
2016-05-28 08:28:53 +00:00
|
|
|
* Update affiliates stats stats
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-05-28 08:28:53 +00:00
|
|
|
if ($ticket_order['affiliate_referral']) {
|
|
|
|
|
$affiliate = Affiliate::where('name', '=', $ticket_order['affiliate_referral'])
|
|
|
|
|
->where('event_id', '=', $event_id)->first();
|
|
|
|
|
$affiliate->increment('sales_volume', $order->amount + $order->organiser_booking_fee);
|
|
|
|
|
$affiliate->increment('tickets_sold', $ticket_order['total_ticket_quantity']);
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
/*
|
2016-05-28 08:28:53 +00:00
|
|
|
* Update the event stats
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2018-04-24 18:25:07 +00:00
|
|
|
$event_stats = EventStats::updateOrCreate([
|
2016-05-28 08:28:53 +00:00
|
|
|
'event_id' => $event_id,
|
|
|
|
|
'date' => DB::raw('CURRENT_DATE'),
|
|
|
|
|
]);
|
|
|
|
|
$event_stats->increment('tickets_sold', $ticket_order['total_ticket_quantity']);
|
|
|
|
|
|
|
|
|
|
if ($ticket_order['order_requires_payment']) {
|
|
|
|
|
$event_stats->increment('sales_volume', $order->amount);
|
|
|
|
|
$event_stats->increment('organiser_fees_volume', $order->organiser_booking_fee);
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
/*
|
2016-05-28 08:28:53 +00:00
|
|
|
* Add the attendees
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-05-28 08:28:53 +00:00
|
|
|
foreach ($ticket_order['tickets'] as $attendee_details) {
|
2016-04-04 11:21:09 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
/*
|
|
|
|
|
* Update ticket's quantity sold
|
|
|
|
|
*/
|
|
|
|
|
$ticket = Ticket::findOrFail($attendee_details['ticket']['id']);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Update some ticket info
|
|
|
|
|
*/
|
|
|
|
|
$ticket->increment('quantity_sold', $attendee_details['qty']);
|
|
|
|
|
$ticket->increment('sales_volume', ($attendee_details['ticket']['price'] * $attendee_details['qty']));
|
|
|
|
|
$ticket->increment('organiser_fees_volume',
|
|
|
|
|
($attendee_details['ticket']['organiser_booking_fee'] * $attendee_details['qty']));
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-04-04 15:20:35 +00:00
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
/*
|
2016-05-28 08:28:53 +00:00
|
|
|
* Insert order items (for use in generating invoices)
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-05-28 08:28:53 +00:00
|
|
|
$orderItem = new OrderItem();
|
|
|
|
|
$orderItem->title = $attendee_details['ticket']['title'];
|
|
|
|
|
$orderItem->quantity = $attendee_details['qty'];
|
|
|
|
|
$orderItem->order_id = $order->id;
|
|
|
|
|
$orderItem->unit_price = $attendee_details['ticket']['price'];
|
|
|
|
|
$orderItem->unit_booking_fee = $attendee_details['ticket']['booking_fee'] + $attendee_details['ticket']['organiser_booking_fee'];
|
|
|
|
|
$orderItem->save();
|
2016-05-08 15:36:26 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
/*
|
|
|
|
|
* Create the attendees
|
|
|
|
|
*/
|
|
|
|
|
for ($i = 0; $i < $attendee_details['qty']; $i++) {
|
2016-05-20 22:54:45 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
$attendee = new Attendee();
|
|
|
|
|
$attendee->first_name = $request_data["ticket_holder_first_name"][$i][$attendee_details['ticket']['id']];
|
|
|
|
|
$attendee->last_name = $request_data["ticket_holder_last_name"][$i][$attendee_details['ticket']['id']];
|
|
|
|
|
$attendee->email = $request_data["ticket_holder_email"][$i][$attendee_details['ticket']['id']];
|
|
|
|
|
$attendee->event_id = $event_id;
|
|
|
|
|
$attendee->order_id = $order->id;
|
|
|
|
|
$attendee->ticket_id = $attendee_details['ticket']['id'];
|
|
|
|
|
$attendee->account_id = $event->account->id;
|
|
|
|
|
$attendee->reference_index = $attendee_increment;
|
|
|
|
|
$attendee->save();
|
2016-05-20 22:54:45 +00:00
|
|
|
|
|
|
|
|
|
2016-05-08 15:36:26 +00:00
|
|
|
/*
|
2016-05-28 08:28:53 +00:00
|
|
|
* Save the attendee's questions
|
2016-05-08 15:36:26 +00:00
|
|
|
*/
|
2016-05-28 08:28:53 +00:00
|
|
|
foreach ($attendee_details['ticket']->questions as $question) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ticket_answer = isset($ticket_questions[$attendee_details['ticket']->id][$i][$question->id]) ? $ticket_questions[$attendee_details['ticket']->id][$i][$question->id] : null;
|
|
|
|
|
|
|
|
|
|
if (is_null($ticket_answer)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If there are multiple answers to a question then join them with a comma
|
|
|
|
|
* and treat them as a single answer.
|
|
|
|
|
*/
|
|
|
|
|
$ticket_answer = is_array($ticket_answer) ? implode(', ', $ticket_answer) : $ticket_answer;
|
2016-05-08 15:36:26 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
if (!empty($ticket_answer)) {
|
|
|
|
|
QuestionAnswer::create([
|
|
|
|
|
'answer_text' => $ticket_answer,
|
|
|
|
|
'attendee_id' => $attendee->id,
|
|
|
|
|
'event_id' => $event->id,
|
|
|
|
|
'account_id' => $event->account->id,
|
|
|
|
|
'question_id' => $question->id
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
}
|
2016-04-04 11:21:09 +00:00
|
|
|
}
|
2016-04-04 15:20:35 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
/* Keep track of total number of attendees */
|
|
|
|
|
$attendee_increment++;
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
/*
|
|
|
|
|
* Kill the session
|
|
|
|
|
*/
|
|
|
|
|
session()->forget('ticket_order_' . $event->id);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-05-28 08:28:53 +00:00
|
|
|
/*
|
|
|
|
|
* Queue up some tasks - Emails to be sent, PDFs etc.
|
|
|
|
|
*/
|
2016-07-09 11:06:44 +00:00
|
|
|
Log::info('Firing the event');
|
2016-06-15 10:14:27 +00:00
|
|
|
event(new OrderCompletedEvent($order));
|
2016-05-28 08:28:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
|
|
|
|
|
Log::error($e);
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'status' => 'error',
|
|
|
|
|
'message' => 'Whoops! There was a problem processing your order. Please try again.'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
2016-03-21 16:39:36 +00:00
|
|
|
|
2016-04-04 11:21:09 +00:00
|
|
|
if ($return_json) {
|
2016-03-20 16:01:50 +00:00
|
|
|
return response()->json([
|
2016-05-08 15:36:26 +00:00
|
|
|
'status' => 'success',
|
2016-03-20 16:01:50 +00:00
|
|
|
'redirectUrl' => route('showOrderDetails', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'is_embedded' => $this->is_embedded,
|
2016-03-20 16:01:50 +00:00
|
|
|
'order_reference' => $order->order_reference,
|
|
|
|
|
]),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-20 16:01:50 +00:00
|
|
|
return response()->redirectToRoute('showOrderDetails', [
|
2016-05-08 15:36:26 +00:00
|
|
|
'is_embedded' => $this->is_embedded,
|
2016-04-04 11:21:09 +00:00
|
|
|
'order_reference' => $order->order_reference,
|
|
|
|
|
]);
|
2016-03-20 16:01:50 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-05-28 08:28:53 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
'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
|
|
|
|
2016-03-16 01:13:49 +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
|
|
|
}
|
2016-03-07 17:18:55 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-21 16:36:40 +00:00
|
|
|
|