forked from CGM_Public/pretix_original
PPv2: Handle payment execution/capture calls properly even if no captures are present yet. (#5909)
This commit is contained in:
@@ -786,6 +786,10 @@ class PaypalMethod(BasePaymentProvider):
|
|||||||
else:
|
else:
|
||||||
pp_captured_order = response.result
|
pp_captured_order = response.result
|
||||||
|
|
||||||
|
payment.refresh_from_db()
|
||||||
|
|
||||||
|
any_captures = False
|
||||||
|
all_captures_completed = True
|
||||||
for purchaseunit in pp_captured_order.purchase_units:
|
for purchaseunit in pp_captured_order.purchase_units:
|
||||||
for capture in purchaseunit.payments.captures:
|
for capture in purchaseunit.payments.captures:
|
||||||
try:
|
try:
|
||||||
@@ -794,6 +798,10 @@ class PaypalMethod(BasePaymentProvider):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if capture.status != 'COMPLETED':
|
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 '
|
messages.warning(request, _('PayPal has not yet approved the payment. We will inform you as '
|
||||||
'soon as the payment completed.'))
|
'soon as the payment completed.'))
|
||||||
payment.info = json.dumps(pp_captured_order.dict())
|
payment.info = json.dumps(pp_captured_order.dict())
|
||||||
@@ -801,8 +809,6 @@ class PaypalMethod(BasePaymentProvider):
|
|||||||
payment.save()
|
payment.save()
|
||||||
return
|
return
|
||||||
|
|
||||||
payment.refresh_from_db()
|
|
||||||
|
|
||||||
if pp_captured_order.status != 'COMPLETED':
|
if pp_captured_order.status != 'COMPLETED':
|
||||||
payment.fail(info=pp_captured_order.dict())
|
payment.fail(info=pp_captured_order.dict())
|
||||||
logger.error('Invalid state: %s' % repr(pp_captured_order.dict()))
|
logger.error('Invalid state: %s' % repr(pp_captured_order.dict()))
|
||||||
|
|||||||
Reference in New Issue
Block a user