PayPal2: Skip webhook order capture if no OrderPayment exists yet

This commit is contained in:
Martin Gross
2024-11-13 10:13:50 +01:00
parent 7266d90c6b
commit 6e6d6b2746

View File

@@ -505,9 +505,15 @@ def webhook(request, *args, **kwargs):
except Quota.QuotaExceededException:
pass
elif sale['status'] == 'APPROVED':
request.session['payment_paypal_oid'] = payment.info_data['id']
try:
request.session['payment_paypal_oid'] = payment.info_data['id']
payment.payment_provider.execute_payment(request, payment)
except KeyError:
# We might receive the CHECKOUT.ORDER.APPROVED webhook early if the user approves the payment but
# the order has not been created yet. In these cases, we will skip the immediate capture until
# the Order and OrderPayment has been created, and we can capture the payment in the regular
# execute_payment run.
logger.info('PayPal2 - Did not capture/execute_payment from Webhook: payment was not yet populated.')
except PaymentException as e:
logger.exception('PayPal2 - Could not capture/execute_payment from Webhook: {}'.format(str(e)))