Repository: fossasia/open-event-server

Issue:
Ticketing: Properly handle free tickets
Parent #1848.
Follow up to #1913.

For free tickets, don't ask for billing information and don't show Stripe/Paypal payment mechanism.



Discussion:

Resolving patch:
diff --git a/app/__init__.py b/app/__init__.py
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -78,7 +78,7 @@ def create_app():
     app.config['STATIC_ROOT'] = 'staticfiles'
     app.config['STATICFILES_DIRS'] = (os.path.join(BASE_DIR, 'static'), )
     app.config['SQLALCHEMY_RECORD_QUERIES'] = True
-    #app.config['SERVER_NAME'] = 'open-event-dev.herokuapp.com'
+    # app.config['SERVER_NAME'] = 'open-event-dev.herokuapp.com'
     app.logger.addHandler(logging.StreamHandler(sys.stdout))
     app.logger.setLevel(logging.INFO)
     app.jinja_env.add_extension('jinja2.ext.do')
diff --git a/app/helpers/ticketing.py b/app/helpers/ticketing.py
--- a/app/helpers/ticketing.py
+++ b/app/helpers/ticketing.py
@@ -126,26 +126,36 @@ def create_order(form):
     def initiate_order_payment(form):
         identifier = form['identifier']
         email = form['email']
-        country = form['country']
-        address = form['address']
-        city = form['city']
-        state = form['state']
-        zipcode = form['zipcode']
         order = TicketingManager.get_and_set_expiry(identifier)
+
         if order:
+
             user = TicketingManager.get_or_create_user_by_email(email, form)
             order.user_id = user.id
-            order.address = address
-            order.city = city
-            order.state = state
-            order.country = country
-            order.zipcode = zipcode
-            order.status = 'initialized'
+
+            if order.amount > 0:
+                country = form['country']
+                address = form['address']
+                city = form['city']
+                state = form['state']
+                zipcode = form['zipcode']
+                order.address = address
+                order.city = city
+                order.state = state
+                order.country = country
+                order.zipcode = zipcode
+                order.status = 'initialized'
+                ticket_holder = TicketHolder(name=user.user_detail.fullname,
+                                             email=email, address=address,
+                                             city=city, state=state, country=country, order_id=order.id)
+            else:
+                order.status = 'completed'
+                order.completed_at = datetime.utcnow()
+                ticket_holder = TicketHolder(name=user.user_detail.fullname, email=email, order_id=order.id)
+
             save_to_db(order)
-            ticket_holder = TicketHolder(name=user.user_detail.fullname,
-                                         email=email, address=address,
-                                         city=city, state=state, country=country, order_id=order.id)
             save_to_db(ticket_holder)
+
             return order
         else:
             return False
diff --git a/app/views/public/ticketing.py b/app/views/public/ticketing.py
--- a/app/views/public/ticketing.py
+++ b/app/views/public/ticketing.py
@@ -63,7 +63,8 @@ def initiate_order_payment(self):
         if result:
             return jsonify({
                 "status": "ok",
-                "email": result.user.email
+                "email": result.user.email,
+                "order_status": result.status
             })
         else:
             return jsonify({


Test patch: