Repository: fossasia/open-event-server

Issue:
Paypal integration not working: MissingConfig
```
MissingConfig
Required PAYPAL_CLIENT_ID and PAYPAL_CLIENT_SECRET. 
```

```
KeyError: 'PAYPAL_CLIENT_ID'
  File "paypalrestsdk/api.py", line 314, in default
    client_id = os.environ["PAYPAL_CLIENT_ID"]
  File "os.py", line 679, in __getitem__
    raise KeyError(key) from None
MissingConfig: Required PAYPAL_CLIENT_ID and PAYPAL_CLIENT_SECRET.                 Refer https://github.com/paypal/rest-api-sdk-python#configuration
  File "flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "flask/_compat.py", line 39, in reraise
    raise value
  File "flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "app/api/helpers/permissions.py", line 48, in decorator
    return fn(*args, **kwargs)
  File "flask_rest_jsonapi/decorators.py", line 32, in wrapper
    return func(*args, **kwargs)
  File "flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "flask_rest_jsonapi/resource.py", line 68, in dispatch_request
    response = method(*args, **kwargs)
  File "flask_rest_jsonapi/decorators.py", line 56, in wrapper
    return func(*args, **kwargs)
  File "flask_rest_jsonapi/resource.py", line 202, in post
    obj = self._data_layer.create_object(data, kwargs)
  File "app/api/data_layers/ChargesLayer.py", line 78, in create_object
    order, data['paypal_payer_id'], data['paypal_payment_id']
  File "app/api/helpers/ticketing.py", line 201, in charge_paypal_order_payment
    paypal_payer_id, paypal_payment_id
  File "app/api/helpers/payment.py", line 287, in execute_payment
    payment = paypalrestsdk.Payment.find(paypal_payment_id)
  File "paypalrestsdk/resource.py", line 107, in find
    api = api or default_api()
  File "paypalrestsdk/api.py", line 318, in default
    Refer https://github.com/paypal/rest-api-sdk-python#configuration")
```

Maybe Related: https://github.com/paypal/PayPal-Python-SDK/issues/49


Discussion:
I have overridden environment variables for now to mitigate the issue. But this needs to be solved

@iamareebjamal - How do i reproduce this issue?
It's difficult to reproduce

Resolving patch:
diff --git a/app/api/helpers/payment.py b/app/api/helpers/payment.py
--- a/app/api/helpers/payment.py
+++ b/app/api/helpers/payment.py
@@ -179,8 +179,7 @@ def configure_paypal():
                 {'pointer': ''},
                 "Payments through Paypal have not been configured on the platform",
             )
-
-        paypalrestsdk.configure(
+        return paypalrestsdk.configure(
             {
                 "mode": paypal_mode,
                 "client_id": paypal_client,
@@ -284,7 +283,7 @@ def execute_payment(paypal_payer_id, paypal_payment_id):
         :param paypal_payer_id: payer_id
         :return: Result of the transaction.
         """
-
+        PayPalPaymentsManager.configure_paypal()
         payment = paypalrestsdk.Payment.find(paypal_payment_id)
 
         if payment.execute({"payer_id": paypal_payer_id}):


Test patch: