Repository: fossasia/open-event-server

Issue:
Not being able to pay with Stripe
**Describe the bug**
Not being able to pay with Stripe. Nothing happens when clicking on Pay Now Button


**Desktop (please complete the following information):**
Chrome

**Additional context**
```
vendor-48d1cff85f863d1337bccb28f2fa97e7.js:2961 Uncaught Error: [ember-cli-stripe] Missing required `key` param
    at n._stripeHandler (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:10784)
    at vendor-48d1cff85f863d1337bccb28f2fa97e7.js:10779
    at y (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:5237)
    at S (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:5247)
    at vendor-48d1cff85f863d1337bccb28f2fa97e7.js:5255
    at t.invoke (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4776)
    at e.t.flush (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4768)
    at e.t.flush (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4781)
    at e.n._end (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4843)
    at e.n.end (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4798)
```



Discussion:
@anhanh11001 On local or eventyay ?
eventyay. Try it yourself
Same error:
```
ncaught Error: [ember-cli-stripe] Missing required `key` param
    at n._stripeHandler (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:10784)
    at vendor-48d1cff85f863d1337bccb28f2fa97e7.js:10779
    at y (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:5237)
    at S (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:5247)
    at vendor-48d1cff85f863d1337bccb28f2fa97e7.js:5255
    at t.invoke (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4776)
    at e.t.flush (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4768)
    at e.t.flush (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4781)
    at e.n._end (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4843)
    at e.n.end (vendor-48d1cff85f863d1337bccb28f2fa97e7.js:4798)
```
@CosmicCoder96 Please check
@anhanh11001 @liveHarshit Which event did you try it for? 
Tried for fossasia summit 2020 on eventyay:
got the gateway:
![image](https://user-images.githubusercontent.com/17252805/62204093-1e8ed480-b3aa-11e9-96cf-e5047264d316.png)

I have tried for the same: FOSSASIA Summit. Let me check again.
@CosmicCoder96 Tried for summit 2020

![image](https://user-images.githubusercontent.com/44091822/62214054-e3989b00-b3c1-11e9-839a-6a64bb917949.png)

@CosmicCoder96 Same
![Screenshot from 2019-07-31 18-40-10](https://user-images.githubusercontent.com/27783786/62214414-a7b20580-b3c2-11e9-930e-993671347614.png)

Issue-Label Bot is automatically applying the label `bug` to this issue, with a confidence of 0.97. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback! 

 Links: [app homepage](https://github.com/marketplace/issue-label-bot), [dashboard](https://mlbot.net/data/fossasia/open-event-server) and [code](https://github.com/hamelsmu/MLapp) for this bot.

Resolving patch:
diff --git a/app/api/schema/events.py b/app/api/schema/events.py
--- a/app/api/schema/events.py
+++ b/app/api/schema/events.py
@@ -278,6 +278,13 @@ def validate_timezone(self, data, original_data):
                                 schema='UserSchemaPublic',
                                 type_='user',
                                 many=True)
+    stripe_authorization = Relationship(attribute='stripe_authorization',
+                                        self_view='v1.stripe_authorization_event',
+                                        self_view_kwargs={'id': '<id>'},
+                                        related_view='v1.stripe_authorization_detail',
+                                        related_view_kwargs={'event_id': '<id>'},
+                                        schema='StripeAuthorizationSchema',
+                                        type_='stripe-authorization')
 
 
 class EventSchema(EventSchemaPublic):
@@ -355,10 +362,3 @@ class Meta:
                              schema='AttendeeSchema',
                              many=True,
                              type_='attendee')
-    stripe_authorization = Relationship(attribute='stripe_authorization',
-                                        self_view='v1.stripe_authorization_event',
-                                        self_view_kwargs={'id': '<id>'},
-                                        related_view='v1.stripe_authorization_detail',
-                                        related_view_kwargs={'event_id': '<id>'},
-                                        schema='StripeAuthorizationSchema',
-                                        type_='stripe-authorization')
diff --git a/app/api/schema/stripe_authorization.py b/app/api/schema/stripe_authorization.py
--- a/app/api/schema/stripe_authorization.py
+++ b/app/api/schema/stripe_authorization.py
@@ -5,7 +5,7 @@
 from app.api.schema.base import SoftDeletionSchema
 
 
-class StripeAuthorizationSchema(SoftDeletionSchema):
+class StripeAuthorizationSchemaPublic(SoftDeletionSchema):
     """
         Stripe Authorization Schema
     """
@@ -21,7 +21,6 @@ class Meta:
 
     id = fields.Str(dump_only=True)
     stripe_publishable_key = fields.Str(dump_only=True)
-    stripe_auth_code = fields.Str(load_only=True, required=True)
 
     event = Relationship(attribute='event',
                          self_view='v1.stripe_authorization_event',
@@ -30,3 +29,22 @@ class Meta:
                          related_view_kwargs={'stripe_authorization_id': '<id>'},
                          schema="EventSchema",
                          type_='event')
+
+
+class StripeAuthorizationSchema(StripeAuthorizationSchemaPublic):
+    """
+        Stripe Authorization Schema
+    """
+
+    class Meta:
+        """
+        Meta class for StripeAuthorization Api Schema
+        """
+        type_ = 'stripe-authorization'
+        self_view = 'v1.stripe_authorization_detail'
+        self_view_kwargs = {'id': '<id>'}
+        inflect = dasherize
+
+    stripe_auth_code = fields.Str(load_only=True, required=True)
+
+
diff --git a/app/api/stripe_authorization.py b/app/api/stripe_authorization.py
--- a/app/api/stripe_authorization.py
+++ b/app/api/stripe_authorization.py
@@ -2,13 +2,14 @@
 from sqlalchemy.orm.exc import NoResultFound
 
 from app.api.bootstrap import api
+from flask import request
 from app.api.helpers.db import safe_query, get_count, save_to_db
 from app.api.helpers.exceptions import ForbiddenException, ConflictException, UnprocessableEntity
 from app.api.helpers.payment import StripePaymentsManager
 from app.api.helpers.permission_manager import has_access
 from app.api.helpers.permissions import jwt_required
 from app.api.helpers.utilities import require_relationship
-from app.api.schema.stripe_authorization import StripeAuthorizationSchema
+from app.api.schema.stripe_authorization import StripeAuthorizationSchema, StripeAuthorizationSchemaPublic
 from app.models import db
 from app.models.event import Event
 from app.models.stripe_authorization import StripeAuthorization
@@ -69,7 +70,8 @@ def after_create_object(self, stripe_authorization, data, view_kwargs):
         save_to_db(event)
 
     schema = StripeAuthorizationSchema
-    decorators = (jwt_required, )
+    decorators = (api.has_permission('is_coorganizer', fetch="event_id",
+                                     fetch_as="event_id", model=StripeAuthorization),)
     methods = ['POST']
     data_layer = {'session': db.session,
                   'model': StripeAuthorization,
@@ -83,6 +85,20 @@ class StripeAuthorizationDetail(ResourceDetail):
     """
     Stripe Authorization Detail Resource by ID
     """
+
+    def before_get(self, args, kwargs):
+        """
+        method for assigning schema based on access
+        :param args:
+        :param kwargs:
+        :return:
+        """
+        kwargs = get_id(kwargs)
+        if 'Authorization' in request.headers and has_access('is_coorganizer', event_id=kwargs['id']):
+            self.schema = StripeAuthorizationSchema
+        else:
+            self.schema = StripeAuthorizationSchemaPublic
+
     def before_get_object(self, view_kwargs):
         """
         method to get id of stripe authorization related to an event
@@ -107,8 +123,7 @@ def after_delete_object(self, stripe_authorization, view_kwargs):
         event.is_stripe_linked = False
         save_to_db(event)
 
-    decorators = (api.has_permission('is_coorganizer', fetch="event_id",
-                                     fetch_as="event_id", model=StripeAuthorization),)
+    decorators = (jwt_required,)
     schema = StripeAuthorizationSchema
     data_layer = {'session': db.session,
                   'model': StripeAuthorization,
@@ -123,8 +138,25 @@ class StripeAuthorizationRelationship(ResourceDetail):
     Stripe Authorization Relationship
     """
 
-    decorators = (api.has_permission('is_coorganizer', fetch="event_id",
-                                     fetch_as="event_id", model=StripeAuthorization),)
+    decorators = (jwt_required,)
     schema = StripeAuthorizationSchema
     data_layer = {'session': db.session,
                   'model': StripeAuthorization}
+
+
+def get_id(view_kwargs):
+    """
+    method to get the resource id for fetching details
+    :param view_kwargs:
+    :return:
+    """
+
+    if view_kwargs.get('event_identifier') is not None:
+        event = safe_query(db, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
+        if event.id is not None:
+            view_kwargs['event_id'] = event.id
+
+    if view_kwargs.get('event_id') is not None:
+        stripe_authorization = safe_query(db, StripeAuthorization, 'event_id', view_kwargs['event_id'], 'event_id')
+        view_kwargs['id'] = stripe_authorization.id
+    return view_kwargs


Test patch: