mirror of
https://github.com/pretix/pretix.git
synced 2026-08-11 10:57:00 +00:00
extend BasePaymentPaymentProvider to support payment dependent "abort_pending_allow"
This commit is contained in:
@@ -333,6 +333,16 @@ class BasePaymentProvider:
|
||||
"""
|
||||
return False
|
||||
|
||||
def abort_pending_payment_allowed(self, payment: OrderPayment) -> bool:
|
||||
"""
|
||||
Whether a user can abort this specific payment.
|
||||
The result is OR'ed with the result of ``BasePaymentProvider.abort_pending_allowed``.
|
||||
The same other caveats apply. It is sufficient to only implement either
|
||||
``abort_pending_payment_allowed`` or ``abort_pending_allowed``
|
||||
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def requires_invoice_immediately(self):
|
||||
"""
|
||||
@@ -1019,7 +1029,8 @@ class BasePaymentProvider:
|
||||
On success, you should set ``payment.state = OrderPayment.PAYMENT_STATE_CANCELED`` (or call the super method).
|
||||
On failure, you should raise a PaymentException.
|
||||
"""
|
||||
if payment.state == OrderPayment.PAYMENT_STATE_PENDING and not self.abort_pending_allowed:
|
||||
if payment.state == OrderPayment.PAYMENT_STATE_PENDING and not (
|
||||
self.abort_pending_allowed or self.abort_pending_payment_allowed(payment)):
|
||||
raise PaymentException(_(
|
||||
"This payment is already being processed and can not be canceled any more."
|
||||
))
|
||||
|
||||
@@ -349,7 +349,8 @@ class OrderDetails(EventViewMixin, OrderDetailMixin, CartMixin, TicketPageMixin,
|
||||
pp = lp.payment_provider
|
||||
ctx['last_payment_info'] = pp.payment_pending_render(self.request, ctx['last_payment'])
|
||||
|
||||
if lp.state == OrderPayment.PAYMENT_STATE_PENDING and not pp.abort_pending_allowed:
|
||||
if lp.state == OrderPayment.PAYMENT_STATE_PENDING and not (
|
||||
pp.abort_pending_allowed or pp.abort_pending_payment_allowed(lp)):
|
||||
ctx['can_pay'] = False
|
||||
|
||||
ctx['can_pay'] = ctx['can_pay'] and self.order._can_be_paid() is True
|
||||
@@ -611,7 +612,8 @@ class OrderPayChangeMethod(EventViewMixin, OrderDetailMixin, TemplateView):
|
||||
|
||||
if self.open_payment:
|
||||
pp = self.open_payment.payment_provider
|
||||
if self.open_payment.state == OrderPayment.PAYMENT_STATE_PENDING and not pp.abort_pending_allowed:
|
||||
if self.open_payment.state == OrderPayment.PAYMENT_STATE_PENDING and not (
|
||||
pp.abort_pending_allowed or pp.abort_pending_payment_allowed(self.open_payment)):
|
||||
messages.error(request, _('A payment is currently pending for this order.'))
|
||||
return redirect(self.get_order_url())
|
||||
|
||||
@@ -1718,7 +1720,8 @@ class OrderChangeMixin:
|
||||
|
||||
if totaldiff > Decimal('0.00') and self.order.status == Order.STATUS_PENDING:
|
||||
for p in self.order.payments.filter(state=OrderPayment.PAYMENT_STATE_PENDING):
|
||||
if not p.payment_provider.abort_pending_allowed:
|
||||
if not (p.payment_provider.abort_pending_allowed or p.payment_provider.abort_pending_payment_allowed(
|
||||
p)):
|
||||
raise OrderError(_('You may not change your order in a way that requires additional payment while '
|
||||
'we are processing your current payment. Please check back after your current '
|
||||
'payment has been accepted.'))
|
||||
|
||||
Reference in New Issue
Block a user