mirror of
https://github.com/pretix/pretix.git
synced 2026-08-07 10:17:49 +00:00
Review notes: lock payment for execution/capture
This commit is contained in:
@@ -31,6 +31,7 @@ from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
from django.core.cache import cache
|
||||
from django.db import transaction
|
||||
from django.http import HttpRequest
|
||||
from django.template.loader import get_template
|
||||
from django.templatetags.static import static
|
||||
@@ -55,6 +56,7 @@ from pretix.base.models import Event, Order, OrderPayment, OrderRefund, Quota
|
||||
from pretix.base.payment import BasePaymentProvider, PaymentException
|
||||
from pretix.base.services.mail import SendMailException
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
from pretix.helpers import OF_SELF
|
||||
from pretix.helpers.urls import build_absolute_uri as build_global_uri
|
||||
from pretix.multidomain.urlreverse import build_absolute_uri, eventreverse
|
||||
from pretix.plugins.paypal2.client.core.environment import (
|
||||
@@ -621,7 +623,13 @@ class PaypalMethod(BasePaymentProvider):
|
||||
}
|
||||
return template.render(ctx)
|
||||
|
||||
@transaction.atomic
|
||||
def execute_payment(self, request: HttpRequest, payment: OrderPayment):
|
||||
payment = OrderPayment.objects.select_for_update(of=OF_SELF).get(pk=payment.pk)
|
||||
if payment.state == OrderPayment.PAYMENT_STATE_CONFIRMED:
|
||||
logger.warning('payment is already confirmed; possible return-view/webhook race-condition')
|
||||
return
|
||||
|
||||
try:
|
||||
if request.session.get('payment_paypal_oid', '') == '':
|
||||
raise PaymentException(_('We were unable to process your payment. See below for details on how to '
|
||||
|
||||
@@ -507,7 +507,10 @@ def webhook(request, *args, **kwargs):
|
||||
pass
|
||||
elif sale['status'] == 'APPROVED':
|
||||
request.session['payment_paypal_oid'] = payment.info_data['id']
|
||||
payment.payment_provider.execute_payment(request, payment)
|
||||
try:
|
||||
payment.payment_provider.execute_payment(request, payment)
|
||||
except PaymentException as e:
|
||||
logger.exception('PayPal2 - Could not capture/execute_payment from Webhook: {}'.format(str(e)))
|
||||
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user