使用 Python 进行 Paypal 交易搜索 [英] Paypal Transactionsearch using Python

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

问题描述

我有必要的身份验证详细信息,并且正在尝试进行 TransactionSearch.我不断收到错误消息:的 TIMESTAMP = 2013%2d09%2d07T19%3a06%3a35Z&安培;的correlationID = b7af040415e92&安培; ACK =失败&安培; VERSION = 0%2e000000&安培; BUILD = 7507921&安培; L_ERRORCODE0 = 10002&安培; L_SHORTMESSAGE0 =认证%2fAuthorization%20Failed&安培; L_LONGMESSAGE0 =你%20do%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 交易搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆