diff --git a/payments/paypal/__init__.py b/payments/paypal/__init__.py index c4fe30c3e..b0f36a16b 100644 --- a/payments/paypal/__init__.py +++ b/payments/paypal/__init__.py @@ -8,7 +8,7 @@ from functools import wraps import requests -from django.http import HttpResponseForbidden +from django.http import HttpResponseForbidden, HttpResponseBadRequest from django.shortcuts import redirect from django.utils import timezone from requests.exceptions import HTTPError @@ -267,7 +267,10 @@ def create_payment(self, payment, extra_data=None): def execute_payment(self, payment, payer_id): post = {"payer_id": payer_id} links = self._get_links(payment) - execute_url = links["execute"]["href"] + try: + execute_url = links["execute"]["href"] + except KeyError: + return HttpResponseBadRequest() return self.post(payment, execute_url, data=post) def get_amount_data(self, payment, amount=None):