def _call(url, paypal_data, ip=None, token=None): headers = {} auth = settings.PAYPAL_EMBEDDED_AUTH if 'requestEnvelope.errorLanguage' not in paypal_data: paypal_data['requestEnvelope.errorLanguage'] = 'en_US' # We always need these headers. for key, value in [ ('application-id', settings.PAYPAL_APP_ID), ('request-data-format', 'NV'), ('response-data-format', 'NV')]: headers['X-PAYPAL-%s' % key.upper()] = value # If we've got a token, we need to auth using the token which uses the # paypalx lib. This is primarily for the GetDetails API. if token: token = dict(urlparse.parse_qsl(token)) ts, sig = get_auth_header(auth['USER'], auth['PASSWORD'], token['token'], token['secret'], 'POST', url) headers['X-PAYPAL-AUTHORIZATION'] = ('timestamp=%s,token=%s,' 'signature=%s' % (ts, token['token'], sig)) else: # Otherwise, we just authenticate the normal way. for key, value in [ ('application-id', settings.PAYPAL_APP_ID), ('security-userid', auth['USER']), ('security-password', auth['PASSWORD']), ('security-signature', auth['SIGNATURE'])]: headers['X-PAYPAL-%s' % key.upper()] = value if ip: headers['X-PAYPAL-DEVICE-IPADDRESS'] = ip # Warning, a urlencode will not work with chained payments, it must # be sorted and the key should not be escaped. try: data = _nvp_dump(paypal_data) feeddata = requests.post(url, headers=headers, timeout=10, data=data, verify=True, cert=settings.PAYPAL_CERT) except AuthError, error: paypal_log.error('Authentication error: %s' % error) raise
def _call(url, paypal_data, ip=None, token=None): headers = {} auth = settings.PAYPAL_EMBEDDED_AUTH if 'requestEnvelope.errorLanguage' not in paypal_data: paypal_data['requestEnvelope.errorLanguage'] = 'en_US' # We always need these headers. for key, value in [('application-id', settings.PAYPAL_APP_ID), ('request-data-format', 'NV'), ('response-data-format', 'NV')]: headers['X-PAYPAL-%s' % key.upper()] = value # If we've got a token, we need to auth using the token which uses the # paypalx lib. This is primarily for the GetDetails API. if token: token = dict(urlparse.parse_qsl(token)) ts, sig = get_auth_header(auth['USER'], auth['PASSWORD'], token['token'], token['secret'], 'POST', url) headers['X-PAYPAL-AUTHORIZATION'] = ('timestamp=%s,token=%s,' 'signature=%s' % (ts, token['token'], sig)) else: # Otherwise, we just authenticate the normal way. for key, value in [('application-id', settings.PAYPAL_APP_ID), ('security-userid', auth['USER']), ('security-password', auth['PASSWORD']), ('security-signature', auth['SIGNATURE'])]: headers['X-PAYPAL-%s' % key.upper()] = value if ip: headers['X-PAYPAL-DEVICE-IPADDRESS'] = ip # Warning, a urlencode will not work with chained payments, it must # be sorted and the key should not be escaped. try: data = _nvp_dump(paypal_data) feeddata = requests.post(url, headers=headers, timeout=10, data=data, verify=True, cert=settings.PAYPAL_CERT) except AuthError, error: paypal_log.error('Authentication error: %s' % error) raise
def _call(url, paypal_data, ip=None, token=None): request = urllib2.Request(url) auth = settings.PAYPAL_EMBEDDED_AUTH if 'requestEnvelope.errorLanguage' not in paypal_data: paypal_data['requestEnvelope.errorLanguage'] = 'en_US' # We always need these headers. for key, value in [ ('application-id', settings.PAYPAL_APP_ID), ('request-data-format', 'NV'), ('response-data-format', 'NV')]: request.add_header('X-PAYPAL-%s' % key.upper(), value) # If we've got a token, we need to auth using the token which uses the # paypalx lib. This is primarily for the GetDetails API. if token: token = dict(urlparse.parse_qsl(token)) ts, sig = get_auth_header(auth['USER'], auth['PASSWORD'], token['token'], token['secret'], 'POST', url) request.add_header('X-PAYPAL-AUTHORIZATION', 'timestamp=%s,token=%s,signature=%s' % (ts, token['token'], sig)) else: # Otherwise, we just authenticate the normal way. for key, value in [ ('application-id', settings.PAYPAL_APP_ID), ('security-userid', auth['USER']), ('security-password', auth['PASSWORD']), ('security-signature', auth['SIGNATURE'])]: request.add_header('X-PAYPAL-%s' % key.upper(), value) if ip: request.add_header('X-PAYPAL-DEVICE-IPADDRESS', ip) # Warning, a urlencode will not work with chained payments, it must # be sorted and the key should not be escaped. opener = urllib2.build_opener() try: with socket_timeout(10): feeddata = opener.open(request, _nvp_dump(paypal_data)).read() except AuthError, error: paypal_log.error('Authentication error: %s' % error) raise
def _call(url, paypal_data, ip=None, token=None): request = urllib2.Request(url) auth = settings.PAYPAL_EMBEDDED_AUTH if "requestEnvelope.errorLanguage" not in paypal_data: paypal_data["requestEnvelope.errorLanguage"] = "en_US" # We always need these headers. for key, value in [ ("application-id", settings.PAYPAL_APP_ID), ("request-data-format", "NV"), ("response-data-format", "NV"), ]: request.add_header("X-PAYPAL-%s" % key.upper(), value) # If we've got a token, we need to auth using the token which uses the # paypalx lib. This is primarily for the GetDetails API. if token: token = dict(urlparse.parse_qsl(token)) ts, sig = get_auth_header(auth["USER"], auth["PASSWORD"], token["token"], token["secret"], "POST", url) request.add_header("X-PAYPAL-AUTHORIZATION", "timestamp=%s,token=%s,signature=%s" % (ts, token["token"], sig)) else: # Otherwise, we just authenticate the normal way. for key, value in [ ("application-id", settings.PAYPAL_APP_ID), ("security-userid", auth["USER"]), ("security-password", auth["PASSWORD"]), ("security-signature", auth["SIGNATURE"]), ]: request.add_header("X-PAYPAL-%s" % key.upper(), value) if ip: request.add_header("X-PAYPAL-DEVICE-IPADDRESS", ip) # Warning, a urlencode will not work with chained payments, it must # be sorted and the key should not be escaped. opener = urllib2.build_opener() try: with socket_timeout(10): feeddata = opener.open(request, _nvp_dump(paypal_data)).read() except AuthError, error: paypal_log.error("Authentication error: %s" % error) raise
def _call(url, paypal_data, ip=None, token=None): headers = {} auth = settings.PAYPAL_EMBEDDED_AUTH if "requestEnvelope.errorLanguage" not in paypal_data: paypal_data["requestEnvelope.errorLanguage"] = "en_US" # We always need these headers. for key, value in [ ("application-id", settings.PAYPAL_APP_ID), ("request-data-format", "NV"), ("response-data-format", "NV"), ]: headers["X-PAYPAL-%s" % key.upper()] = value # If we've got a token, we need to auth using the token which uses the # paypalx lib. This is primarily for the GetDetails API. if token: token = dict(urlparse.parse_qsl(token)) ts, sig = get_auth_header(auth["USER"], auth["PASSWORD"], token["token"], token["secret"], "POST", url) headers["X-PAYPAL-AUTHORIZATION"] = "timestamp=%s,token=%s," "signature=%s" % (ts, token["token"], sig) else: # Otherwise, we just authenticate the normal way. for key, value in [ ("application-id", settings.PAYPAL_APP_ID), ("security-userid", auth["USER"]), ("security-password", auth["PASSWORD"]), ("security-signature", auth["SIGNATURE"]), ]: headers["X-PAYPAL-%s" % key.upper()] = value if ip: headers["X-PAYPAL-DEVICE-IPADDRESS"] = ip # Warning, a urlencode will not work with chained payments, it must # be sorted and the key should not be escaped. try: data = _nvp_dump(paypal_data) feeddata = requests.post(url, headers=headers, timeout=10, data=data, verify=True, cert=settings.PAYPAL_CERT) except AuthError, error: paypal_log.error("Authentication error: %s" % error) raise