PPv2: Simulate cart_payments in XHR-calls; only look at multi_use-payments for remaining value calculation (#2970)

Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
Martin Gross
2022-12-12 15:35:16 +01:00
committed by GitHub
parent 495a21c683
commit aab7042cda

View File

@@ -149,19 +149,27 @@ class XHRView(View):
else:
cart_total = get_cart_total(request)
cart_payments = cart_session(request).get('payments', [])
for fee in get_fees(request.event, request, cart_total, None, cart_payments, get_cart(request)):
multi_use_cart_payments = [p for p in cart_payments if p.get('multi_use_supported')]
simulated_payments = multi_use_cart_payments + [{
'provider': 'paypal',
'multi_use_supported': False,
'min_value': None,
'max_value': None,
'info_data': {},
}]
for fee in get_fees(request.event, request, cart_total, None, simulated_payments, get_cart(request)):
cart_total += fee.value
total_remaining = cart_total
for p in cart_session(request).get('payments', []):
if p['provider'] != 'paypal':
if p.get('min_value') and total_remaining < Decimal(p['min_value']):
continue
for p in multi_use_cart_payments:
if p.get('min_value') and total_remaining < Decimal(p['min_value']):
continue
to_pay = total_remaining
if p.get('max_value') and to_pay > Decimal(p['max_value']):
to_pay = min(to_pay, Decimal(p['max_value']))
total_remaining -= to_pay
to_pay = total_remaining
if p.get('max_value') and to_pay > Decimal(p['max_value']):
to_pay = min(to_pay, Decimal(p['max_value']))
total_remaining -= to_pay
cart_total = total_remaining