fix paypal api url joining

master
alice 4 years ago
parent e63afcdc6e
commit e7134106d3

@ -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'

Loading…
Cancel
Save