Fix regression in PayPal payments

This commit is contained in:
Raphael Michel
2022-11-25 11:29:19 +01:00
parent ff153164f8
commit 0919d5dbca
2 changed files with 17 additions and 10 deletions

View File

@@ -58,14 +58,16 @@ from paypalcheckoutsdk import orders as pp_orders, payments as pp_payments
from pretix.base.models import Event, Order, OrderPayment, OrderRefund, Quota
from pretix.base.payment import PaymentException
from pretix.base.services.cart import get_fees
from pretix.base.services.cart import add_payment_to_cart, get_fees
from pretix.base.settings import GlobalSettingsObject
from pretix.control.permissions import event_permission_required
from pretix.multidomain.urlreverse import eventreverse
from pretix.plugins.paypal2.client.customer.partners_merchantintegrations_get_request import (
PartnersMerchantIntegrationsGetRequest,
)
from pretix.plugins.paypal2.payment import PaypalMethod, PaypalMethod as Paypal
from pretix.plugins.paypal2.payment import (
PaypalMethod, PaypalMethod as Paypal, PaypalWallet,
)
from pretix.plugins.paypal.models import ReferencedPayPalObject
from pretix.presale.views import get_cart, get_cart_total
from pretix.presale.views.cart import cart_session
@@ -311,6 +313,7 @@ def success(request, *args, **kwargs):
'secret': payment.order.secret
}) + ('?paid=yes' if payment.order.status == Order.STATUS_PAID else ''))
else:
add_payment_to_cart(request, PaypalWallet(request.event), None, None, None)
urlkwargs['step'] = 'confirm'
return redirect(eventreverse(request.event, 'presale:event.checkout', kwargs=urlkwargs))

View File

@@ -1198,10 +1198,8 @@ class PaymentStep(CartMixin, TemplateFlowStep):
request,
cart,
)
if isinstance(resp, str):
return redirect(resp)
elif resp is True:
if pprov.multi_use_supported:
if pprov.multi_use_supported:
if resp is True:
# Provider needs to call add_payment_to_cart itself, but we need to remove all previously
# selected ones that don't have multi_use supported. Otherwise, if you first select a credit
# card, then go back and switch to a gift card, you'll have both in the session and the credit
@@ -1226,14 +1224,20 @@ class PaymentStep(CartMixin, TemplateFlowStep):
)
)
return redirect(self.get_step_url(request))
else:
elif isinstance(resp, str):
return redirect(resp)
else:
if resp is True or isinstance(resp, str):
# There can only be one payment method that does not have multi_use_supported, remove all
# previous ones.
self.cart_session['payments'] = [p for p in self.cart_session.get('payments', []) if p.get('multi_use_supported')]
add_payment_to_cart(request, pprov, None, None, None)
return redirect(self.get_next_url(request))
else:
return self.render()
if isinstance(resp, str):
return redirect(resp)
else:
return redirect(self.get_next_url(request))
return self.render()
if self.is_completed(request, warn=False):
# All payments already accounted for, no need to select one