PayPal: Patch API client to cache access tokens (#2600)

This commit is contained in:
Raphael Michel
2022-06-07 17:20:38 +02:00
committed by GitHub
parent b2c76a9e36
commit 597089a89b
2 changed files with 58 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ from pretix.base.payment import BasePaymentProvider, PaymentException
from pretix.base.services.mail import SendMailException
from pretix.base.settings import SettingsSandbox
from pretix.multidomain.urlreverse import build_absolute_uri
from pretix.plugins.paypal.api import Api
from pretix.plugins.paypal.models import ReferencedPayPalObject
logger = logging.getLogger('pretix.plugins.paypal')
@@ -197,7 +198,7 @@ class Paypal(BasePaymentProvider):
def init_api(self):
if self.settings.connect_client_id and not self.settings.secret:
paypalrestsdk.set_config(
paypalrestsdk.api.__api__ = Api(
mode="sandbox" if "sandbox" in self.settings.connect_endpoint else 'live',
client_id=self.settings.connect_client_id,
client_secret=self.settings.connect_secret_key,
@@ -205,10 +206,11 @@ class Paypal(BasePaymentProvider):
openid_client_secret=self.settings.connect_secret_key
)
else:
paypalrestsdk.set_config(
paypalrestsdk.api.__api__ = Api(
mode="sandbox" if "sandbox" in self.settings.get('endpoint') else 'live',
client_id=self.settings.get('client_id'),
client_secret=self.settings.get('secret'))
client_secret=self.settings.get('secret')
)
def payment_is_valid_session(self, request):
return (request.session.get('payment_paypal_id', '') != ''