Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function postRegister($domain, $slug, Request $request)
- {
- if ($request->has('force_error')) {
- //force error
- $a = 1 / 0;
- die();
- }
- $register_by_organiser = false;
- $event = Events::where('slug', $slug)->first();
- if (preg_replace('/[0-9]/', '', $slug) == '') {
- $event = Events::find($slug);
- $register_by_organiser = Auth::check();
- }
- if (! $event) {
- abort(404);
- }
- $payment_method_id = $request->input('payment_method_id', null);
- $payment_method_id = $payment_method_id == '' ? null : $payment_method_id;
- $files = Events::saveFiles($request);
- if (count($files) > 0) {
- foreach ($files as $key => $arr) {
- foreach ($arr as $k => $v) {
- if (preg_match('/^customizable_file_upload/', $k)) {
- $new_data = $request->all();
- $new_data['participant'][$key][$k] = $v;
- $request = new Request($new_data);
- unset($files[$key]);
- }
- }
- }
- }
- $user = null;
- $registrant_id = null;
- $forms_registrant_id = null;
- $registrant_email = null;
- $emails = [];
- $first_registrant = true;
- $totalPrice = 0;
- $totalFees = 0;
- if ($request->has('discount_code')) {
- $discount = Discounts::where('code', $request->input('discount_code'))
- ->where('disabled', false)
- ->whereHas('forms', function($forms) use ($event) {
- $forms->whereIn('id', $event->forms->lists('id')->toArray());
- })
- ->with('forms')
- ->first();
- if (! $discount || ! $discount->isValid()) {
- unset($discount);
- }
- }
- $discountSum = 0;
- // Gonna use to check if fee percent added for participants (because on subforms we add fee_percent only once)
- $parentFormAmountAdded = [];
- // Will be used for group reductions
- $participantCount = 0;
- $teamParticipantCount = [];
- // Count participants
- foreach ($request->participant as $participant_id => $participant) {
- if (isset($participant['first_name']) && isset($participant['form']) && $participant['form'] > 0) {
- $participantCount++;
- $form = Forms::find($participant['form']);
- if ($form && !$form->isOpenForRegistration($register_by_organiser)) {
- return redirect()->back();
- }
- if ($event->group_reduction_team_pins) {
- $team_name = $request->input('participant.' . explode('_', $participant_id)[0] . '.team_name', '');
- if (is_string($team_name)) {
- $team_name = trim($team_name);
- }
- $team_pin = $request->input('participant.' . explode('_', $participant_id)[0] . '.team_pin', '');
- if (is_string($team_pin)) {
- $team_pin = trim($team_pin);
- }
- if ($team_name && $team_pin && $this->checkIfPinIsValid($team_name, $team_pin, $form)) {
- if (! isset($teamParticipantCount[$team_name][$form->id])) {
- $teamParticipantCount[$team_name][$form->id] = $this->getTeamMembers($team_name, $form);
- }
- $teamParticipantCount[$team_name][$form->id]++;
- }
- }
- }
- }
- foreach ($request->participant as $participant_id => $participant) {
- if (isset($participant['first_name']) && isset($participant['form']) && $participant['form'] > 0) {
- $formDiscountAmount = 0;
- $participantPrice = 0;
- $form = Forms::find($participant['form']);
- if ($form && !$form->isOpenForRegistration($register_by_organiser)) {
- return redirect()->back();
- }
- // Form we use to calculate price (For example parent form of subform)
- $priceForm = ($form->form_id ? $form->parent_form : $form);
- $participant_id_exploded = explode('_', $participant_id);
- $mainParticipantKey = reset($participant_id_exploded); // Parent id for subforms
- $notAddedParentFormFee = (! isset($parentFormAmountAdded[$mainParticipantKey]) || $parentFormAmountAdded[$mainParticipantKey] != true);
- $participantFormPrice = 0;
- if (! $form->isFree() && $notAddedParentFormFee) {
- $team_name = $request->input('participant.' . explode('_', $participant_id)[0] . '.team_name', '');
- if (is_string($team_name)) {
- $team_name = trim($team_name);
- }
- foreach ($priceForm->prices as $formPrice) {
- $timeFrom = strtotime($formPrice->date_from . ' ' . $formPrice->time_from);
- $timeTo = strtotime($formPrice->date_to . ' ' . $formPrice->time_to);
- $now = time();
- if ($timeFrom <= $now && $timeTo > $now) {
- if (\Input::get('participant.' . $participant_id . '.form_price') != $formPrice->price) {
- \Bugsnag::notifyException(new \Exception('Bad participant form price'));
- }
- $participantFormPrice = $formPrice->price;
- $teamParticipants = 0;
- if ($team_name && isset($teamParticipantCount[$team_name][$form->id])) {
- $teamParticipants = $teamParticipantCount[$team_name][$form->id];
- }
- if ($event->group_reduction
- && ($participantCount >= $event->group_reduction_places || $teamParticipants >= $event->group_reduction_places)
- ) {
- $participantFormPrice -= $event->group_reduction_amount;
- }
- if (isset($discount) && $discount
- && (! $discount->forms->where('id', $priceForm->id)->isEmpty() || ! $discount->forms->where('form_id', $priceForm->id)->isEmpty())
- ) {
- if ($discount->discount_amount) {
- $formDiscountAmount = $discount->discount_amount;
- } elseif ($discount->discount_percent) {
- $formDiscountAmount = $participantFormPrice * $discount->discount_percent / 100;
- } else {
- $formDiscountAmount = $participantFormPrice - $discount->discount_price;
- }
- if ($formDiscountAmount > $participantFormPrice) {
- $formDiscountAmount = $participantFormPrice;
- }
- $discountSum += $formDiscountAmount;
- if (!$discount->all_basket_reduction) {
- unset($discount);
- }
- }
- $participantPrice += $participantFormPrice;
- }
- }
- }
- $optionsPrice = 0;
- if (! $event->service_fees_per_subforms && $notAddedParentFormFee) {
- foreach ($request->participant as $request_participant_id => $request_participant) {
- $tempExploded = explode('_', $request_participant_id);
- $mainRequestParticipantKey = reset($tempExploded);
- if (isset($request_participant['first_name']) && isset($request_participant['form'])
- && $request_participant['form'] > 0 && $mainRequestParticipantKey == $mainRequestParticipantKey
- ) {
- $optionsPrice += $this->calculateItemsPricesFromForm($request_participant, $request_participant_id);
- }
- }
- } elseif ($event->service_fees_per_subforms) {
- $optionsPrice += $this->calculateItemsPricesFromForm($participant, $participant_id);
- }
- $participantPrice += $optionsPrice;
- //save main form values like "north challenge" for each participant
- $index = explode('_', $participant_id);
- $index = count($index) > 1 ? $index[0] : 'nonexistingkey';
- foreach ($request->input('participant.' . $index, []) as $key => $value) {
- if (substr($key, 0, 7) == 'option_' && $value != '' && $value != '0') {
- $option = substr($key, 7);
- $forms_field = FormsFields::select('forms_fields.id', 'forms_fields.price')
- ->join('forms_fields_types', 'forms_fields.field_type_id', '=', 'forms_fields_types.id')
- ->where('forms_fields.form_id', $request->input("participant.{$index}.form", 0))
- ->where('forms_fields_types.title', $option)
- ->first();
- if ($forms_field && $forms_field->getPriceBySelectedValue($value)) {
- $participantPrice += $forms_field->getPriceBySelectedValue($value);
- }
- }
- }
- if ($participantPrice && ($event->service_fees_per_subforms || $notAddedParentFormFee)) {
- $fee = $priceForm->forms_group->event->serviceFees()
- ->where('price_from', '<=', $participantPrice)
- ->where('price_to', '>', $participantPrice)
- ->first();
- if ($fee && $participantPrice > $formDiscountAmount) {
- $feePrice = 0;
- if ($participantPrice > 0 && $fee->fee_amount) {
- $feePrice += $fee->fee_amount;
- }
- if ($notAddedParentFormFee && $fee->fee_percent) {
- $feePrice += round(($participantFormPrice - $formDiscountAmount) * $fee->fee_percent) / 100;
- $feePrice += round($optionsPrice * $fee->fee_percent) / 100;
- }
- $totalFees += $feePrice;
- if (! $form->forms_group->event->fees_include && ! $register_by_organiser) {
- $participantPrice += $feePrice;
- }
- }
- }
- $totalPrice += $participantPrice;
- $parentFormAmountAdded[$mainParticipantKey] = true;
- }
- }
- $totalPrice -= $discountSum;
- $totalPrice = round($totalPrice, 2);
- $totalFees = round($totalFees, 2);
- if (\Input::get('total_price') != $totalPrice) {
- \Bugsnag::notifyException(new \Exception('Bad total price: ' . \Input::get('total_price') . ' vs ' . $totalPrice));
- }
- if (\Input::get('event_fee') != $totalFees) {
- \Bugsnag::notifyException(new \Exception('Bad fees price: ' . \Input::get('event_fee') . ' vs ' . $totalFees));
- }
- $nothing_to_pay = $totalPrice == 0;
- $prediscountFree = $nothing_to_pay && ! $discountSum;
- $once = false;
- $cartItems = json_decode($request->input('cart_items'));
- $cart = Cart::create([
- 'items' => $cartItems,
- 'total' => $request->input('total_price'),
- 'fees' => ($event->fees_hide || ($register_by_organiser && $payment_method_id == 2)) ? 0 : $request->input('event_fee'),
- ]);
- $unique_group = str_random(50);
- $m = 0;
- $alreadyMarkedAsPaid = [];
- foreach ($request->participant as $participant_id => $participant) {
- if (isset($participant['first_name'])) {
- foreach ($participant as &$participantValue) {
- if (is_string($participantValue)) {
- $participantValue = trim($participantValue);
- }
- }
- $discountRegistrant = $request->input('discount_registrant', null);
- $discountRegistrant = $discountRegistrant ? : null;
- $discountApplying = ! $prediscountFree && (! $discountRegistrant || $discountRegistrant == ($m + 1));
- if (! $once
- && ! $prediscountFree
- && ($discount_code = $request->input('discount_code', null))
- && $discountApplying
- ) {
- $once = true;
- Discounts::where('code', $discount_code)->increment('times_used');
- Discounts::where('code', $discount_code)->first()
- ->usages()->where('ip', getIP())
- ->where('user_uid', $request->input('q9qz8'))
- ->delete();
- }
- $m++;
- $form = Forms::find($participant['form']);
- if ($form && ! $form->isOpenForRegistration($register_by_organiser)) {
- return redirect()->back();
- }
- if (strstr($participant_id, '_')) {
- $form = Forms::find(@$request->participant[explode('_', $participant_id)[0]]['form']);
- if ($form && ! $form->isOpenForRegistration($register_by_organiser)) {
- return redirect()->back();
- }
- }
- $individual_price = strstr($participant_id, '_') ? $request->input('participant.' . explode('_',
- $participant_id)[0] . '.individual_price') : $request->input('participant.' . $participant_id . '.individual_price');
- $parent_id = strstr($participant_id, '_') ? explode('_', $participant_id)[0] : $participant_id;
- if (is_null($registrant_email)) {
- $registrant_email = $participant['email'];
- }
- // $password = str_random(8);
- if (isset($participant['ignore_email_validation']) && $participant['ignore_email_validation']) {
- $user_id = null;
- } elseif (! array_key_exists($participant['email'], $emails)) {
- $user = User::where('email', $participant['email'])->first();
- if (! $user) {
- $password = Str::random(8);
- $user = User::create([
- 'name' => $participant['first_name'],
- 'email' => $participant['email'],
- 'password' => Hash::make($password),
- 'role_id' => 3,
- ]);
- /*
- Mail::send('emails.newUser', [
- 'name' => $user->name,
- 'password' => $password
- ], function ($m) use ($user) {
- $m->to($user->email, $user->name);
- });
- */
- $agent = new Agent();
- FormsRegistrantsAgent::create([
- 'user_id' => $user->id,
- 'country' => '',
- 'browser name' => $agent->browser(),
- 'operating system' => $request->input('os', ''),
- 'device' => $request->input('device', ''),
- 'ip_address' => $_SERVER['REMOTE_ADDR'],
- 'agent' => $agent->getUserAgent(),
- 'screen_size' => $request->input('screen_size', '0x0')
- ]);
- }
- $emails[$participant['email']] = $user->id;
- $user_id = $user->id;
- } else {
- $user_id = $emails[$participant['email']];
- }
- $registrant = Registrants::create($participant + ['user_id' => $user_id, 'nationality_id' => null]);
- if (is_null($registrant_id)) {
- $registrant_id = $registrant->id;
- }
- $paid_fee = ($request->has('event_fee') && is_null($forms_registrant_id)) ? $request->event_fee : null;
- if ($register_by_organiser && $payment_method_id == 2) {
- $paid_fee = 0;
- }
- $team_id = null;
- $team_name = $request->input('participant.' . explode('_', $participant_id)[0] . '.team_name', '');
- if (is_string($team_name)) {
- $team_name = trim($team_name);
- }
- $team_type = $request->input('participant.' . explode('_', $participant_id)[0] . '.team_type_id', '');
- if ($team_type == '') {
- //if we do not have team_type field, check maybe it is optional field
- $team_type = $request->input('participant.' . explode('_',
- $participant_id)[0] . '.option_team_type', '');
- }
- if ($request->has('participant.' . explode('_', $participant_id)[0] . '.team_id')) {
- $team_id = $request->input('participant.' . explode('_', $participant_id)[0] . '.team_id');
- }
- //check if we have team_name field in request
- //note for myself: $request->has() returns false when field exists, but its content empty
- if (! $team_id && $request->input('participant.' . explode('_',
- $participant_id)[0] . '.team_name') !== null
- ) {
- $child_form = Forms::find($participant['form']);
- $root_form_id = $child_form->form_id ? : $child_form->id;
- //maybe we already have team with same name and type
- $team = Team::where('teams_type_id', $team_type ? $team_type : null)
- ->where('form_id', $root_form_id)
- ->where('title', $team_name)->first();
- //no.
- if (! $team && $team_name) {
- //create new Team
- $team = Team::create([
- 'form_id' => $root_form_id,
- 'teams_type_id' => $team_type ? $team_type : null,
- 'title' => $team_name,
- 'registrants_maximum' => 1,
- ]);
- if ($event->team_pins_enabled && ! TeamPin::where('event_id', $event->id)->where('team_name', $team_name)->exists()) {
- TeamPin::create([
- 'team_name' => $team_name,
- 'event_id' => $event->id,
- 'pin' => Team::generatePin(),
- ]);
- }
- }
- $team_id = $team ? $team->id : null;
- //merge team_id into request for the further usage (for team mates)
- // $request->merge(['participant' => [explode('_', $participant_id)[0] => ['team_id' => $team->id]]]);
- }
- $forms_ids = Forms::find($participant['form'])->forms_group->event->forms()->get([DB::raw('forms.id')])->lists('id')->all();
- $currentMax = FormsRegistrants::whereIn('form_id', $forms_ids)->max('registrant_number');
- $next_registrant_number = $currentMax ? ++$currentMax : '1';
- $form_registrant = FormsRegistrants::create([
- 'discount_code' => $discountApplying ? ($request->input('discount_code') ? : null) : null,
- 'user_id' => $register_by_organiser ? \Auth::id() : null,
- 'form_id' => $participant['form'],
- 'registrant_id' => $registrant->id,
- 'forms_registrant_id' => $forms_registrant_id,
- 'registrant_comment' => (isset($participant['comments'])) ? $participant['comments'] : '',
- 'team_id' => $team_id,
- 'forms_registrants_status_id' => 1,
- 'registrant_number' => $register_by_organiser || $nothing_to_pay ? $next_registrant_number : null,
- 'individual_price' => (! in_array($parent_id,
- $alreadyMarkedAsPaid) ? $individual_price : null),
- 'unique_group' => $unique_group,
- 'form_group' => $parent_id,
- 'paid_amount' => $register_by_organiser || $nothing_to_pay ? ($first_registrant ? $request->total_price : null) : null,
- 'paid_fee' => $paid_fee,
- 'testing_mode' => $event->testing_mode,
- 'invoice_data' => json_decode($request->input('invoice')),
- 'cart_id' => $cart->id,
- ]);
- $first_registrant = false;
- $alreadyMarkedAsPaid[] = $parent_id;
- if (is_null($forms_registrant_id)) {
- $forms_registrant_id = $form_registrant->id;
- }
- if (! empty($participant['challengeGroup'])) {
- $group_id = Registrants::saveRegistrantGroups($participant, $event);
- $form_registrant->update(['group_id' => $group_id]);
- }
- $added = [];
- if (! empty($files[$participant_id])) {
- foreach ($files[$participant_id] as $field_name => $filename) {
- $document = [
- 'registrant_id' => $registrant->id,
- 'filename' => $filename,
- ];
- $type = 2; // Licence
- if (isset($participant['medical-license-button']) && $participant['medical-license-button'] == 1) {
- $type = 1;
- } // Medical
- if ($field_name == 'parental_uploaded_file') {
- $type = 3;
- } // Parental
- $document['registrants_documents_type_id'] = $type;
- $document_field = 'parental_document_id';
- $document_status_field = 'parental_status_id';
- $document_status_id = ParentalStatuses::whereTitle('en attente de validation')->pluck('id');
- if ($type == 2) {
- $document['licence_type_id'] = \Arr::get($participant, 'licence_type_id');
- $document['licence_number'] = \Arr::get($participant, 'licence_number');
- $document['club_name'] = \Arr::get($participant, 'club_name');
- $document['club_number'] = \Arr::get($participant, 'club_number');
- $document['document_date'] = \Arr::get($participant, 'licence_date');
- $document_field = 'medical_or_licence_document_id';
- $document_status_field = 'medical_or_licence_status_id';
- $document_status_id = MedicalStatuses::whereTitle('en attente de validation')->pluck('id');
- }
- if ($type == 1) {
- if (isset($participant['medical_certificate_date'])) {
- $document['document_date'] = $participant['medical_certificate_date'];
- }
- $document_field = 'medical_or_licence_document_id';
- $document_status_field = 'medical_or_licence_status_id';
- $document_status_id = MedicalStatuses::whereTitle('en attente de validation')->pluck('id');
- }
- $registrant_document = RegistrantsDocuments::create($document);
- $form_registrant->update([
- $document_field => $registrant_document->id,
- $document_status_field => $document_status_id
- ]);
- $added[] = $document_status_field;
- }
- } elseif ((isset($participant['licence_type_id']) && $participant['licence_type_id'] != '' && $participant['licence_type_id'] > 0) ||
- (isset($participant['licence_number']) && $participant['licence_number'] != '')
- ) {
- $document = [
- 'registrant_id' => $registrant->id,
- 'filename' => '',
- 'registrants_documents_type_id' => 2,
- ];
- $document['licence_type_id'] = \Arr::get($participant, 'licence_type_id');
- $document['licence_number'] = \Arr::get($participant, 'licence_number');
- $document['club_name'] = \Arr::get($participant, 'club_name');
- $document['club_number'] = \Arr::get($participant, 'club_number');
- $document['document_date'] = \Arr::get($participant, 'licence_date');
- $document_field = 'medical_or_licence_document_id';
- $registrant_document = RegistrantsDocuments::create($document);
- $form_registrant->update([
- $document_field => $registrant_document->id
- ]);
- }
- if (! in_array('medical_or_licence_status_id', $added)) {
- $form_registrant->medical_or_licence_status_id = 1;
- }
- if (! in_array('parental_status_id', $added)) {
- $mainForm = (! $form_registrant->form->form_id ? $form_registrant->form : $form_registrant->form->parent_form);
- if ($form_registrant->registrant->is_18_at_start || ! $mainForm->parental_required) {
- $form_registrant->parental_status_id = 11;
- } else {
- $form_registrant->parental_status_id = 5;
- }
- }
- $form_registrant->save();
- //save form values
- foreach ($participant as $key => $value) {
- if (substr($key, 0, 7) == 'option_' && $value != '' && $value != '0') {
- $option = substr($key, 7);
- $forms_fields = FormsFields::where('form_id', $participant['form'])->get();
- $form_field_id = null;
- $field_type_id = null;
- $forms_fields->each(function (FormsFields $formsField) use (
- $option,
- &$form_field_id,
- &$field_type_id
- ) {
- if ($formsField->field_type && $formsField->field_type->title == $option) {
- $field_type_id = $formsField->field_type->id;
- $form_field_id = $formsField->id;
- }
- if ($formsField->fieldGroup) {
- foreach ($formsField->fieldGroup->fields as $field) {
- if ($field->title == $option) {
- $field_type_id = $field->id;
- $form_field_id = $formsField->id;
- }
- }
- }
- });
- if ($form_field_id && $field_type_id) {
- $forms_field = FormsFields::find($form_field_id);
- FormsRegistrantsFields::create([
- 'forms_registrant_id' => $form_registrant->id,
- 'forms_field_id' => $form_field_id,
- 'field_type_id' => $field_type_id,
- 'field_value' => $value,
- 'price' => $forms_field->getPriceBySelectedValue($value) ? : 0
- ]);
- }
- }
- }
- //save customizable fields
- foreach ($participant as $key => $value) {
- if (preg_match('/^customizable_/', $key) && $value != '' && $value != '0') {
- //get field id (last number in title)
- $form_field_id = preg_replace('/^customizable_(?:.*?)([0-9]+)/', '$1', $key);
- $forms_field = FormsFields::whereFormId($participant['form'])->find($form_field_id);
- //if field found, create form registrant field with data
- if ($forms_field) {
- FormsRegistrantsFields::create([
- 'forms_registrant_id' => $form_registrant->id,
- 'forms_field_id' => $forms_field->id,
- 'field_type_id' => $forms_field->field_type_id,
- 'field_value' => $value,
- 'price' => $forms_field->getPriceBySelectedValue($value) ? : 0
- ]);
- }
- }
- }
- //check if this is child form
- if (strstr($participant_id, '_')) {
- //yes, it is, check if we can get parent form data
- $parent_data = Arr::get($request->participant, explode('_', $participant_id)[0]);
- if ($parent_data) {
- foreach ($parent_data as $key => $value) {
- //we need to save each parent forms data as registrant own data
- if (preg_match('/^customizable_/', $key) && $value != '' && $value != '0') {
- //get field id (last number in title)
- $form_field_id = preg_replace('/^customizable_(?:.*?)([0-9]+)/', '$1', $key);
- $forms_field = FormsFields::whereFormId($parent_data['form'])->find($form_field_id);
- //if field found, create form registrant field with data
- if ($forms_field) {
- FormsRegistrantsFields::create([
- 'forms_registrant_id' => $form_registrant->id,
- 'forms_field_id' => $forms_field->id,
- 'field_type_id' => $forms_field->field_type_id,
- 'field_value' => $value,
- 'price' => $forms_field->getPriceBySelectedValue($value) ? : 0
- ]);
- }
- }
- }
- }
- }
- //save main form values like "north challenge" for each participant
- $index = explode('_', $participant_id);
- $index = count($index) > 1 ? $index[0] : 'nonexistingkey';
- foreach ($request->input('participant.' . $index, []) as $key => $value) {
- if (substr($key, 0, 7) == 'option_' && $value != '' && $value != '0') {
- $option = substr($key, 7);
- $forms_field = FormsFields::select('forms_fields.id', 'forms_fields.price')
- ->join('forms_fields_types', 'forms_fields.field_type_id', '=', 'forms_fields_types.id')
- ->where('forms_fields.form_id', $request->input("participant.{$index}.form", 0))
- ->where('forms_fields_types.title', $option)
- ->first();
- if ($forms_field) {
- FormsRegistrantsFields::create([
- 'forms_registrant_id' => $form_registrant->id,
- 'forms_field_id' => $forms_field->id,
- 'field_value' => $value,
- 'price' => $forms_field->getPriceBySelectedValue($value) ? : 0
- ]);
- }
- }
- }
- }
- }
- if ($register_by_organiser) {
- $order_number = Transactions::join('forms_registrants', 'transactions.forms_registrant_id', '=',
- 'forms_registrants.id')
- ->join('forms', 'forms_registrants.form_id', '=', 'forms.id')
- ->join('forms_groups', 'forms.forms_group_id', '=', 'forms_groups.id')
- ->where('forms_groups.event_id', $event->id)
- ->max('transactions.order_number');
- if (is_null($order_number)) {
- $order_number = 0;
- }
- $order_number++;
- $paid_fee = $request->input('event_fee', 0);
- $amount = ($request->has('payment_amount') ? $request->input('payment_amount') : $request->total_price + $paid_fee);
- if ($payment_method_id == 2) {
- $paid_fee = 0;
- $amount = $request->total_price;
- }
- Transactions::create([
- 'registrant_id' => $registrant_id,
- 'forms_registrant_id' => $forms_registrant_id,
- 'user_id' => (\Auth::check() ? \Auth::user()->id : null),
- 'amount' => $amount,
- 'currency_id' => $event->organisation->currency_id,
- 'payment_method_id' => $payment_method_id,
- 'order_number' => $order_number,
- 'info' => 'Inscriptions',
- 'comments' => ($request->has('payment_comments') ? $request->input('payment_comments') : null)
- ]);
- $registrants = FormsRegistrants::where('unique_group', $unique_group)->get();
- $details = OrderDetails::generateForFormRegistrant($registrants->first());
- /** @var FormsRegistrants $item */
- foreach ($registrants as $item) {
- $item->registrant->orderDetails()->associate($details)->save();
- }
- return redirect()->route('user.registrants')->withMessage(trans('event.admin.newParticipantAdded'));
- }
- if ($request->input('payment_type_hidden') == '2') {
- return view('payment_cheque');
- }
- if ($nothing_to_pay) {
- $order_number = Transactions::join('forms_registrants', 'transactions.forms_registrant_id', '=',
- 'forms_registrants.id')
- ->join('forms', 'forms_registrants.form_id', '=', 'forms.id')
- ->join('forms_groups', 'forms.forms_group_id', '=', 'forms_groups.id')
- ->where('forms_groups.event_id', $event->id)
- ->max('transactions.order_number');
- if (is_null($order_number)) {
- $order_number = 0;
- }
- $order_number++;
- if (!is_null($registrant_id)) {
- Transactions::create([
- 'registrant_id' => $registrant_id,
- 'forms_registrant_id' => $forms_registrant_id,
- 'user_id' => (\Auth::check() ? \Auth::user()->id : null),
- 'amount' => 0,
- 'currency_id' => $event->organisation->currency_id,
- 'payment_method_id' => null,
- 'order_number' => $order_number,
- 'info' => 'Inscriptions',
- ]);
- }
- // Send confirmation email
- /** @var \App\Events $event */
- $registrants = FormsRegistrants::where('unique_group', $unique_group)->get();
- $uniqueEmails = array_unique(array_keys($emails));
- foreach ($uniqueEmails as $email) {
- $event->sendSuccessEmail($email, $registrants);
- }
- // @todo Duplicate code
- $registrant_number = FormsRegistrants::join('forms', 'forms_registrants.form_id', '=',
- 'forms.id')
- ->join('forms_groups', 'forms.forms_group_id', '=', 'forms_groups.id')
- ->where('forms_groups.event_id', $event->id)
- ->where('forms_registrants.unique_group', '<>', $unique_group)
- ->max('forms_registrants.registrant_number');
- if (is_null($registrant_number)) {
- $registrant_number = 0;
- }
- $registrant_number++;
- foreach ($registrants as $row) {
- $row->update(['registrant_number' => $registrant_number++]);
- if ($row->discount_code) {
- $row->update(['discount_used' => 1]);
- }
- }
- return redirect()->route('eventSuccess', [$event->slug, 'event_id' => $event->id]);
- }
- $cle = 'F54D5EA925D2E3392F497B3F966F71A2939B2A94';
- $tpe = '6389328';
- try {
- $oTpe = new CMCIC_Tpe('FR', $cle, $tpe);
- $oHmac = new CMCIC_Hmac($oTpe);
- $form_data = [
- 'tpe' => $tpe,
- 'date' => date('d/m/Y:H:i:s'),
- 'price' => $request->total_price,
- 'currency' => $event->organisation->currency->code,
- 'reference' => $registrant_id . '-A2',
- 'event_id' => $event->id,
- 'buyer_email' => $registrant_email,
- ];
- $PHP1_FIELDS = sprintf(CMCIC_CGI1_FIELDS,
- $form_data['tpe'],
- $form_data['date'],
- $form_data['price'],
- $event->organisation->currency->code,
- $form_data['reference'],
- "",
- "3.0",
- "FR",
- "kiadeo",
- $form_data['buyer_email'],
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "");
- $form_data['MAC'] = $oHmac->computeHmac($PHP1_FIELDS);
- } catch (\Exception $ex) {
- Log::error($ex->getMessage());
- }
- return view('payment_form', compact('event', 'form_data'));
- // return view('payment_success', compact('event'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement