# Buggy code
def create_payment(order, return_url, cancel_url):
    """
    Create payment for an order
    :param order: Order to create payment for.
    :param return_url: return url for the payment.
    :param cancel_url: cancel_url for the payment.
    :return: request_id or the error message along with an indicator.
    """
    if (not order.event.paypal_email) or order.event.paypal_email == "":
        raise ConflictException(
            {"pointer": ""},
            "Payments through Paypal hasn't been configured for the event",
        )

    PayPalPaymentsManager.configure_paypal()

    payment = paypalrestsdk.Payment(
        {
            "intent": "sale",
            "payer": {"payment_method": "paypal"},
            "redirect_urls": {"return_url": return_url, "cancel_url": cancel_url},
            "transactions": [
                {
                    "amount": {
                        "total": int(order.amount * 100),
                        "currency": order.event.payment_currency,
                    },
                    "payee": {"email": order.event.paypal_email},
                }
            ],
        }
    )

    if payment.create():
        return True, payment.id
    else:
        return False, payment.error


# Traceback (TypeError)
INFO:werkzeug:127.0.0.1 - - [25/Jul/2018 12:13:40] "POST /v1/orders/852cf23e-f6ca-4af2-ad6d-38639db5fa17/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 156, in charge_paypal_order_payment status, error = PayPalPaymentsManager.execute_payment(paypal_payer_id, paypal_payment_id)
TypeError: 'bool' object is not iterable

# Fixed code
def create_payment(order, return_url, cancel_url):
    """
    Create payment for an order
    :param order: Order to create payment for.
    :param return_url: return url for the payment.
    :param cancel_url: cancel_url for the payment.
    :return: request_id or the error message along with an indicator.
    """
    if (not order.event.paypal_email) or order.event.paypal_email == "":
        raise ConflictException(
            {"pointer": ""},
            "Payments through Paypal hasn't been configured for the event",
        )

    PayPalPaymentsManager.configure_paypal()

    payment = paypalrestsdk.Payment(
        {
            "intent": "sale",
            "payer": {"payment_method": "paypal"},
            "redirect_urls": {"return_url": return_url, "cancel_url": cancel_url},
            "transactions": [
                {
                    "amount": {
                        "total": int(order.amount),
                        "currency": order.event.payment_currency,
                    },
                    "payee": {"email": order.event.paypal_email},
                }
            ],
        }
    )

    if payment.create():
        return True, payment.id
    else:
        return False, payment.error