From aab7042cdac8a8ccd34a208f04bfe359011a06d3 Mon Sep 17 00:00:00 2001 From: Martin Gross Date: Mon, 12 Dec 2022 15:35:16 +0100 Subject: [PATCH] PPv2: Simulate cart_payments in XHR-calls; only look at multi_use-payments for remaining value calculation (#2970) Co-authored-by: Raphael Michel --- src/pretix/plugins/paypal2/views.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pretix/plugins/paypal2/views.py b/src/pretix/plugins/paypal2/views.py index 3bc450942c..26bad8b091 100644 --- a/src/pretix/plugins/paypal2/views.py +++ b/src/pretix/plugins/paypal2/views.py @@ -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