From e7134106d33f36c85e4b6ecfdac4533e79972e2e Mon Sep 17 00:00:00 2001 From: alice Date: Wed, 7 Oct 2020 22:20:20 +0200 Subject: [PATCH] fix paypal api url joining --- payments/backends/paypal.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/payments/backends/paypal.py b/payments/backends/paypal.py index ecee585..d959bd6 100644 --- a/payments/backends/paypal.py +++ b/payments/backends/paypal.py @@ -9,6 +9,14 @@ import requests from .base import BackendBase +def urljoin(a, b): + if b.startswith('/') and a.endswith('/'): + return a + b[1:] + if b.startswith('/') or a.endswith('/'): + return a + b + return a + "/" + b + + class PaypalBackend(BackendBase): backend_id = 'paypal' backend_verbose_name = _("PayPal") @@ -60,7 +68,7 @@ class PaypalBackend(BackendBase): "It can take up to a few minutes...") payment.save() - return redirect(self.api_base + '/cgi-bin/webscr?' + urlencode(params)) + return redirect(urljoin(self.api_base, '/cgi-bin/webscr?' + urlencode(params))) def new_subscription(self, rps): months = { @@ -91,7 +99,7 @@ class PaypalBackend(BackendBase): rps.save() - return redirect(self.api_base + '/cgi-bin/webscr?' + urlencode(params)) + return redirect(urljoin(self.api_base, '/cgi-bin/webscr?' + urlencode(params))) def handle_verified_callback(self, payment, params): if self.test and params['test_ipn'] != '1': @@ -165,7 +173,7 @@ class PaypalBackend(BackendBase): return True def verify_ipn(self, request): - v_url = self.api_base + '/cgi-bin/webscr?cmd=_notify-validate' + v_url = urljoin(self.api_base, '/cgi-bin/webscr?cmd=_notify-validate') v_req = urlopen(v_url, data=request.body, timeout=5) v_res = v_req.read() return v_res == b'VERIFIED'