Repository: fossasia/open-event-server

Issue:
Save attendee data once Pay Now is clicked
Right now the attendee data gets saved only after the order has been placed or completed. What we want to achieve is save the attendee data immediately after pay now is clicked with status="pending".


Discussion:
@SaptakS @mariobehling I followed the discussion on #2934.

Some points i'd like to mention.
- Currently the data is indeed being saved on clicking pay now.
- In the discussion there seemed to be a confusion b/w `Initialized` and `Pending` status 
  - `Initialized` - User has entered the attendee details and clicked on pay now.
  - `Pending` -  User is on the fill attendee information page and has not clicked on Pay Now



- In attendees section, After clicking pay now, order status is changed to `Initialized`, so `pending` status tab seems redundant and instead an `Initialized` tab should be added
- In addition to that an `Initialized` tab should also be added to orders section.

`Initialized` attendee: 
![selection_076](https://cloud.githubusercontent.com/assets/13910561/21946434/8462f06e-da06-11e6-8830-6ce391d397c4.png)

If the above seems okay, i'd like to work on that. 
Please do not add an initialized status. This is information is not relevant for organizers. Please follow existing services. Maybe we should postpone this as well, cause there are bugs that really prevent us from a release whereas the initialize information adds little value for the actual event management. Please help to keep things simple. We do not need to re-invent things. Just follow existing services.
@mariobehling I think there is a misunderstanding, there is no mention of re-inventing :) .
**The `Initialized` status is a pre-existing field already existing in the current app**

> - Currently the data is indeed being saved on clicking pay now.
> - In the discussion there seemed to be a confusion b/w `Initialized` and `Pending` status 
>    - `Initialized` - User has entered the attendee details and clicked on pay now.
>   - `Pending` -  User is on the fill attendee information page and has not clicked on Pay Now
>  - In attendees section, After clicking pay now, order status is changed to `Initialized`

 The above comment clarifies how things are working with the app right now, not how they should be implemented in the future.

The screenshot in the above comment is also from the current(existing) implementation without any changes made to it.
Please keep this discussion shorter: No additional UI statuses. Keep it simple for users.
> No additional UI statuses

The initialized status is not additional, it is already displayed in the UI, then should it be removed?

> Please keep this discussion shorter

Agreed. Maybe we can come on this later.

@shubham-padia I have already fixed this. System crashed yesterday so couldn't send a PR.

Resolving patch:
diff --git a/app/helpers/ticketing.py b/app/helpers/ticketing.py
--- a/app/helpers/ticketing.py
+++ b/app/helpers/ticketing.py
@@ -274,6 +274,25 @@ def initiate_order_payment(form, paid_via=None):
 
         if order:
 
+            holders_firstnames = form.getlist('holders[firstname]')
+            holders_lastnames = form.getlist('holders[lastname]')
+            holders_ticket_ids = form.getlist('holders[ticket_id]')
+            holders_emails = form.getlist('holders[email]')
+
+            for i, firstname in enumerate(holders_firstnames):
+                data = {
+                    'firstname': firstname,
+                    'lastname': holders_lastnames[i]
+                }
+                holder_user = TicketingManager.get_or_create_user_by_email(holders_emails[i], data)
+                ticket_holder = TicketHolder(firstname=data['firstname'],
+                                             lastname=data['lastname'],
+                                             ticket_id=int(holders_ticket_ids[i]),
+                                             email=holder_user.email,
+                                             order_id=order.id)
+                DataManager.add_attendee_role_to_event(holder_user, order.event_id)
+                db.session.add(ticket_holder)
+
             user = TicketingManager.get_or_create_user_by_email(email, form)
             order.user_id = user.id
 
@@ -308,24 +327,6 @@ def initiate_order_payment(form, paid_via=None):
                 if not order.paid_via:
                     order.paid_via = 'free'
 
-            holders_firstnames = form.getlist('holders[firstname]')
-            holders_lastnames = form.getlist('holders[lastname]')
-            holders_ticket_ids = form.getlist('holders[ticket_id]')
-            holders_emails = form.getlist('holders[email]')
-
-            for i, firstname in enumerate(holders_firstnames):
-                data = {
-                    'firstname': firstname,
-                    'lastname': holders_lastnames[i]
-                }
-                holder_user = TicketingManager.get_or_create_user_by_email(holders_emails[i], data)
-                ticket_holder = TicketHolder(firstname=data['firstname'],
-                                             lastname=data['lastname'],
-                                             ticket_id=int(holders_ticket_ids[i]),
-                                             email=holder_user.email, order_id=order.id)
-                DataManager.add_attendee_role_to_event(holder_user, order.event_id)
-                db.session.add(ticket_holder)
-
             # add attendee role to user
             DataManager.add_attendee_role_to_event(user, order.event_id)
             # save items
diff --git a/app/views/users/ticket_sales.py b/app/views/users/ticket_sales.py
--- a/app/views/users/ticket_sales.py
+++ b/app/views/users/ticket_sales.py
@@ -143,6 +143,20 @@ def display_attendees(event_id):
             order_holder['checked_in'] = holder.checked_in
             order_holder['id'] = holder.id
             holders.append(order_holder)
+        if len(order.ticket_holders) == 0:
+            order_holder={}
+            order_holder['order_invoice'] = order.get_invoice_number()
+            order_holder['order_url'] = url_for('ticketing.view_order_after_payment', order_identifier=order.identifier) \
+                                        if order.status == 'completed' else url_for('ticketing.show_transaction_error', \
+                                        order_identifier=order.identifier)
+            order_holder['by_whom'] = order.user.user_detail.fullname if order.user.user_detail \
+                                        and order.user.user_detail.fullname else order.user.email
+            order_holder['paid_via'] = order.paid_via
+            order_holder['status'] = order.status
+            order_holder['completed_at'] = order.completed_at
+            order_holder['created_at'] = order.created_at
+            holders.append(order_holder)
+
     return render_template('gentelella/admin/event/tickets/attendees.html', event=event,
                            event_id=event_id, holders=holders)
 


Test patch: