Repository: fossasia/open-event-server

Issue:
Charge layer endpoint gives internal server error when sending notifications
**Describe the bug**
Charge layer endpoint gives internal server error when sending notifications

**Expected behavior**
Request should succeed.

**Stacktrace**
```
127.0.0.1 - - [28/Jul/2018 00:54:01] "POST /v1/orders/e2962d1d-ad9c-4f4b-9439-5413925ae513/charge? HTTP/1.1" 500 -
INFO:werkzeug:127.0.0.1 - - [28/Jul/2018 00:54:01] "POST /v1/orders/e2962d1d-ad9c-4f4b-9439-5413925ae513/charge? HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/rs/Pradeep/github/open-event-server/app/__init__.py", line 67, in __call__
    return self.app(environ, start_response)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/rs/Pradeep/github/open-event-server/app/api/helpers/permissions.py", line 45, in decorator
    return fn(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 32, in wrapper
    return func(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/lib/python3.5/site-packages/flask/views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 68, in dispatch_request
    response = method(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/decorators.py", line 56, in wrapper
    return func(*args, **kwargs)
  File "/home/rs/Pradeep/github/open-event-server/env/src/flask-rest-jsonapi/flask_rest_jsonapi/resource.py", line 204, in post
    obj = self._data_layer.create_object(data, kwargs)
  File "/home/rs/Pradeep/github/open-event-server/app/api/data_layers/ChargesLayer.py", line 58, in create_object
    data['paypal_payment_id'])
  File "/home/rs/Pradeep/github/open-event-server/app/api/helpers/ticketing.py", line 174, in charge_paypal_order_payment
    send_notif_ticket_purchase_organizer(organizer, order.invoice_number, order_url, order.event.name)
TypeError: send_notif_ticket_purchase_organizer() missing 1 required positional argument: 'subject_id'
```


Discussion:

Resolving patch:
diff --git a/app/api/helpers/ticketing.py b/app/api/helpers/ticketing.py
--- a/app/api/helpers/ticketing.py
+++ b/app/api/helpers/ticketing.py
@@ -30,8 +30,8 @@ def match_discount_quantity(discount_code, ticket_holders=None):
             ticket_holder = TicketHolder.query.filter_by(id=holder).one()
             if ticket_holder.ticket.id in discount_code.tickets.split(","):
                 qty += 1
-        if (qty+old_holders) <= discount_code.tickets_number and \
-           discount_code.min_quantity <= qty <= discount_code.max_quantity:
+        if (qty + old_holders) <= discount_code.tickets_number and \
+            discount_code.min_quantity <= qty <= discount_code.max_quantity:
             return True
 
         return False
@@ -123,7 +123,8 @@ def charge_stripe_order_payment(order, token_id):
 
             order_url = make_frontend_url(path='/orders/{identifier}'.format(identifier=order.identifier))
             for organizer in order.event.organizers:
-                send_notif_ticket_purchase_organizer(organizer, order.invoice_number, order_url, order.event.name)
+                send_notif_ticket_purchase_organizer(organizer, order.invoice_number, order_url, order.event.name,
+                                                     order.id)
 
             return True, 'Charge successful'
         else:
@@ -171,7 +172,8 @@ def charge_paypal_order_payment(order, paypal_payer_id, paypal_payment_id):
 
             order_url = make_frontend_url(path='/orders/{identifier}'.format(identifier=order.identifier))
             for organizer in order.event.organizers:
-                send_notif_ticket_purchase_organizer(organizer, order.invoice_number, order_url, order.event.name)
+                send_notif_ticket_purchase_organizer(organizer, order.invoice_number, order_url, order.event.name,
+                                                     order.id)
 
             return True, 'Charge successful'
         else:


Test patch: