本文介绍了使用Python的Paypal Transactionsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有必要的身份验证详细信息,并且我正在尝试执行TransactionSearch.我不断收到错误消息: TIMESTAMP = 2013%2d09%2d07T19%3a06%3a35Z& CORRELATIONID = b7af040415e92& ACK = Failure& VERSION = 0%2e000000& BUILD = 7507921& L_ERRORCODE0 = 10002& L_SHORTMESSAGE0 = Authentication%2fAuth %20not%20have%20permissions%20to%20make%20this%20API%20call& L_SEVERITYCODE0 =错误

I have the necessary authentication details and I'm trying to do a TransactionSearch. I keep getting an error: TIMESTAMP=2013%2d09%2d07T19%3a06%3a35Z&CORRELATIONID=b7af040415e92&ACK=Failure&VERSION=0%2e000000&BUILD=7507921&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Authentication%2fAuthorization%20Failed&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call&L_SEVERITYCODE0=Error

这是我的代码:

(timestamp, signature) = signaturegen.getAuthHeader(apiUser=settings.USERNAME, apiPass=settings.PASSWORD, accessTok=res2["token"], secTok=res2["tokenSecret"], httpMethod="POST", scriptURI="https://api-3t.sandbox.paypal.com/nvp")    
#the above operation is used to generate the timestamp and signature

headers = {"X-PAYPAL-AUTHORIZATION": "timestamp="+<timestamp>+",token="+<token>+",signature="+<signature>, "SUBJECT": settings.<API_USERNAME>}

data = {
"METHOD": "TransactionSearch",
"STARTDATE": "2012-01-01T05:38:48Z",
}
req= urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", simplejson.dumps(data), headers)
res = urllib2.urlopen(req).read()

推荐答案

我终于设法修复了代码,以下是完整版本:

I finally managed to fix the code, here is the complete version:

import ast
import signaturegen
headers = {
    "X-PAYPAL-SECURITY-USERID": "xxxxxxxxx.xxxx.com",
    "X-PAYPAL-SECURITY-PASSWORD": "xxxxxxxx",
    "X-PAYPAL-SECURITY-SIGNATURE":  "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T", #APP ID for sandbox

}


    headers = {
    "X-PAYPAL-SECURITY-USERID": settings.USERNAME,
    "X-PAYPAL-SECURITY-PASSWORD": settings.PASSWORD,
    "X-PAYPAL-SECURITY-SIGNATURE": settings.SIGNATURE,
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T"
}

    data = {"scope":"TRANSACTION_SEARCH", "callback":"http://www.example.com/success.html", "requestEnvelope": {"errorLanguage":"en_US"}}
    req = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/RequestPermissions/", simplejson.dumps(data), headers)    
    res = ast.literal_eval(urllib2.urlopen(req).read())
    token = res['token']
    red_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_grant-permission&request_token=%s" % token
   if red_url:
        return HttpResponseRedirect(red_url)
    token = "xxxxxxxxxxxxxxxxxx"
    verification = "xxxxxxxxxxxxxxxxxx"
    headers2 = {
    "X-PAYPAL-SECURITY-USERID": "xxxxxxxxxxxx",
    "X-PAYPAL-SECURITY-PASSWORD": "xxxxxxxxxxxxxxxx",
    "X-PAYPAL-SECURITY-SIGNATURE": "xxxxxxxxxxxxx",
    "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
    "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T",
}
    url = "https://svcs.sandbox.paypal.com/Permissions/GetAccessToken/"


    dat2 = {
        "requestEnvelope": {"errorLanguage":"en_US"}, 
        "token": "AAAAAAAYcambja9iJfUw", 
        "verifier": "iVUJ6c-6ZNk8M6Q9hkC12A"}
    req2 = urllib2.Request("https://svcs.sandbox.paypal.com/Permissions/GetAccessToken/", simplejson.dumps(dat2), headers2)
    res2 = ast.literal_eval(urllib2.urlopen(req2).read())


    (timestamp, signature) = signaturegen.getAuthHeader(apiUser="xxxxxxxxxxxx", apiPass="xxxxxxxxxxxxxxxx", accessTok=res2["token"], secTok=res2["tokenSecret"], httpMethod="POST", scriptURI="https://api-3t.sandbox.paypal.com/nvp")    

    ultimate = {"X-PAYPAL-AUTHORIZATION": "timestamp="+timestamp+",token="+res2["token"]+",signature="+signature, "SUBJECT": settings.USERNAME}

    da = {
        "METHOD": "TransactionSearch",
        "STARTDATE": "2012-01-01T05:38:48Z",
    }
    req3 = urllib2.Request("https://api-3t.sandbox.paypal.com/nvp", urllib.urlencode(da), ultimate)
    res3 = urllib2.urlopen(req3).read()

这篇关于使用Python的Paypal Transactionsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 00:20