mirror of
https://github.com/pretix/pretix.git
synced 2026-08-15 11:36:27 +00:00
rename method and change defaults
This commit is contained in:
@@ -338,8 +338,9 @@ class BasePaymentProvider:
|
||||
"""
|
||||
return False
|
||||
|
||||
def payment_abort_pending_allowed(self, payment: OrderPayment) -> bool:
|
||||
def _payment_abort_pending_allowed(self, payment: OrderPayment) -> bool:
|
||||
"""
|
||||
Experimental: This might change during upcomming releases.
|
||||
Whether or not a user can abort a payment in pending state to switch to another
|
||||
payment method. This returns ``self.abort_pending_allowed`` by default which is
|
||||
no guarantee that aborting a pending payment can never happen, it just hides the
|
||||
@@ -1035,7 +1036,7 @@ class BasePaymentProvider:
|
||||
"""
|
||||
|
||||
if payment.state == OrderPayment.PAYMENT_STATE_PENDING:
|
||||
if not self.payment_abort_pending_allowed(payment):
|
||||
if not self._payment_abort_pending_allowed(payment):
|
||||
raise PaymentException(_(
|
||||
"This payment is already being processed and cannot be canceled any more."
|
||||
))
|
||||
|
||||
@@ -540,13 +540,13 @@ class PaypalMethod(BasePaymentProvider):
|
||||
'XPF': 0,
|
||||
}))
|
||||
|
||||
def payment_abort_pending_allowed(self, payment) -> bool:
|
||||
if not self.settings.get('allow_retries_during_compliance_hold', as_type=bool, default=True):
|
||||
def _payment_abort_pending_allowed(self, payment) -> bool:
|
||||
if not self.settings.get('allow_retries_during_compliance_hold', as_type=bool, default=False):
|
||||
return False
|
||||
|
||||
if payment.info_data.get('create_time', False):
|
||||
create_time = datetime.fromisoformat(payment.info_data['create_time'])
|
||||
duration = self.settings.get('timeout_payment_during_compliance_hold', as_type=int, default=0)
|
||||
duration = self.settings.get('timeout_payment_during_compliance_hold', as_type=int, default=10)
|
||||
if datetime.now(tz=timezone.utc) - create_time > timedelta(minutes=duration):
|
||||
return True
|
||||
|
||||
@@ -893,7 +893,7 @@ class PaypalMethod(BasePaymentProvider):
|
||||
|
||||
def payment_pending_render(self, request, payment) -> str:
|
||||
stuck_in_compliance = False
|
||||
retry = self.payment_abort_pending_allowed(payment)
|
||||
retry = self._payment_abort_pending_allowed(payment)
|
||||
try:
|
||||
for purchase_unit in payment.info_data['purchase_units']:
|
||||
for capture in purchase_unit['payments']['captures']:
|
||||
@@ -1162,10 +1162,6 @@ class PaypalMethod(BasePaymentProvider):
|
||||
return self.settings.get('_invoice_text', as_type=LazyI18nString, default='')
|
||||
|
||||
|
||||
settings_hierarkey.add_default('payment_paypal_allow_retries_during_compliance_hold', True, bool)
|
||||
settings_hierarkey.add_default('payment_paypal_timeout_payment_during_compliance_hold', 0, int)
|
||||
|
||||
|
||||
class PaypalWallet(PaypalMethod):
|
||||
identifier = 'paypal'
|
||||
verbose_name = _('PayPal')
|
||||
|
||||
@@ -166,7 +166,8 @@ def signal_process_response(sender, request: HttpRequest, response: HttpResponse
|
||||
|
||||
settings_hierarkey.add_default('payment_paypal_debug_buyer_country', '', str)
|
||||
settings_hierarkey.add_default('payment_paypal_method_wallet', True, bool)
|
||||
|
||||
settings_hierarkey.add_default('payment_paypal_allow_retries_during_compliance_hold', False, bool)
|
||||
settings_hierarkey.add_default('payment_paypal_timeout_payment_during_compliance_hold', 10, int)
|
||||
|
||||
def _nonce(request):
|
||||
if not hasattr(request, "_paypal_nonce"):
|
||||
|
||||
@@ -349,7 +349,7 @@ 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.payment_abort_pending_allowed(lp):
|
||||
if lp.state == OrderPayment.PAYMENT_STATE_PENDING and not pp._payment_abort_pending_allowed(lp):
|
||||
ctx['can_pay'] = False
|
||||
|
||||
ctx['can_pay'] = ctx['can_pay'] and self.order._can_be_paid() is True
|
||||
@@ -611,7 +611,7 @@ 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.payment_abort_pending_allowed(
|
||||
if self.open_payment.state == OrderPayment.PAYMENT_STATE_PENDING and not pp._payment_abort_pending_allowed(
|
||||
self.open_payment):
|
||||
messages.error(request, _('A payment is currently pending for this order.'))
|
||||
return redirect(self.get_order_url())
|
||||
@@ -1719,7 +1719,7 @@ 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.payment_abort_pending_allowed(p):
|
||||
if not p.payment_provider._payment_abort_pending_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