diff --git a/src/pretix/plugins/paypal2/payment.py b/src/pretix/plugins/paypal2/payment.py index 6f1d3774b9..9f128fc514 100644 --- a/src/pretix/plugins/paypal2/payment.py +++ b/src/pretix/plugins/paypal2/payment.py @@ -786,23 +786,29 @@ class PaypalMethod(BasePaymentProvider): else: pp_captured_order = response.result - for purchaseunit in pp_captured_order.purchase_units: - for capture in purchaseunit.payments.captures: - try: - ReferencedPayPalObject.objects.get_or_create(order=payment.order, payment=payment, reference=capture.id) - except ReferencedPayPalObject.MultipleObjectsReturned: - pass - - if capture.status != 'COMPLETED': - messages.warning(request, _('PayPal has not yet approved the payment. We will inform you as ' - 'soon as the payment completed.')) - payment.info = json.dumps(pp_captured_order.dict()) - payment.state = OrderPayment.PAYMENT_STATE_PENDING - payment.save() - return - payment.refresh_from_db() + any_captures = False + all_captures_completed = True + for purchaseunit in pp_captured_order.purchase_units: + for capture in purchaseunit.payments.captures: + try: + ReferencedPayPalObject.objects.get_or_create(order=payment.order, payment=payment, reference=capture.id) + except ReferencedPayPalObject.MultipleObjectsReturned: + pass + + if capture.status != 'COMPLETED': + all_captures_completed = False + else: + any_captures = True + if not (any_captures and all_captures_completed): + messages.warning(request, _('PayPal has not yet approved the payment. We will inform you as ' + 'soon as the payment completed.')) + payment.info = json.dumps(pp_captured_order.dict()) + payment.state = OrderPayment.PAYMENT_STATE_PENDING + payment.save() + return + if pp_captured_order.status != 'COMPLETED': payment.fail(info=pp_captured_order.dict()) logger.error('Invalid state: %s' % repr(pp_captured_order.dict()))