Repository: fossasia/open-event-server

Issue:
Configure charging the user using Stripe
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Configure the Ticketing Manager to charge the user using Stripe.

**Additional context**
<!-- Add any other context or screenshots about the feature request here. -->
parent: #4852 


Discussion:

Resolving patch:
diff --git a/app/api/data_layers/ChargesLayer.py b/app/api/data_layers/ChargesLayer.py
--- a/app/api/data_layers/ChargesLayer.py
+++ b/app/api/data_layers/ChargesLayer.py
@@ -20,9 +20,9 @@ def create_object(self, data, view_kwargs):
         if not order:
             raise ObjectNotFound({'parameter': 'id'},
                                  "Order with id: {} not found".format(view_kwargs['id']))
-        elif order.status == 'cancelled' or order.status == 'expired':
+        elif order.status == 'cancelled' or order.status == 'expired' or order.status == 'completed':
             raise ConflictException({'parameter': 'id'},
-                                    "You cannot charge payments on a cancelled or expired order")
+                                    "You cannot charge payments on a cancelled, expired or completed order")
         elif (not order.amount) or order.amount == 0:
             raise ConflictException({'parameter': 'id'},
                                     "You cannot charge payments on a free order")
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
@@ -89,7 +89,9 @@ def charge_stripe_order_payment(order, token_id):
         # charge the user
         charge = StripePaymentsManager.capture_payment(order)
 
-        if charge:
+        # charge.paid is true if the charge succeeded, or was successfully authorized for later capture.
+        if charge.paid:
+            # update the order in the db.
             order.paid_via = 'stripe'
             order.payment_mode = charge.source.object
             order.brand = charge.source.brand
@@ -101,15 +103,18 @@ def charge_stripe_order_payment(order, token_id):
             order.completed_at = datetime.utcnow()
             save_to_db(order)
 
-            invoice_id = order.get_invoice_number()
-            order_url = make_frontend_url(path="/{identifier}/view/".format(identifier=order.identifier))
-            # send_email_for_after_purchase(order.user.email, invoice_id, order_url, order.event.name,
-                                          # order.event.organizer_name)
-            # send_notif_for_after_purchase(order.user, invoice_id, order_url)
+            # send email and notifications
+            send_email_to_attendees(order, current_user.id)
+            send_notif_to_attendees(order, current_user.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)
 
             return True, order
         else:
-            return False, 'Error'
+            # payment failed hence return the failure message from stripe.
+            return False, charge.failure_message
 
     @staticmethod
     def charge_paypal_order_payment(order, token_id):


Test patch: