我有一个如下所示的权限请求:
timestamp, signature = genPermissionsAuthHeader.getAuthHeader(str(self.username), str(self.password), str(access_token), str(token_secret), "POST", "https://api-3t.sandbox.paypal.com/nvp") # https://svcs.sandbox.paypal.com/Permissions/GetBasicPersonalData
log.info(timestamp)
log.info(signature)
authorization_header = "timestamp=" + timestamp + ",token=" + access_token + ",signature=" + signature
log.info(authorization_header)
headers = {
"X-PAYPAL-AUTHORIZATION": authorization_header,
}
url = "https://api-3t.sandbox.paypal.com/nvp"
nvp_params = {
"METHOD": "TransactionSearch",
"STARTDATE": "2012-01-01T05:38:48Z",
}
r = requests.post(url, data=nvp_params, headers=headers)
log.info(r.text)
self.response.content_disposition = "text/html"
self.response.write(r.text)
我在“沙盒帐户”下的developer.paypal.com上使用我的PayPal凭据从权限API获取了访问令牌和令牌密钥
当我运行此方法时,我收到错误消息:
TIMESTAMP=2014%2d04%2d21T22%3a50%3a18Z&CORRELATIONID=c8f9212035b60
&ACK=Failure&VERSION=0%2e000000&BUILD=10277387&L_ERRORCODE0=10002
&L_SHORTMESSAGE0=Authentication%2f
Authorization%20Faile
d&L_LONGMESSAGE0=You%20do%20not%20have%20permissions%20to%20make%20this%20API%20call
&L_SEVERITYCODE0=ErrorNone
我可以调用GetBasicPersonalDetails,它似乎有效。任何帮助都会很棒,谢谢!
答案 0 :(得分:1)
我找到了答案,我错过了为付款发送的参数字符串上的“SUBJECT”参数。所以,以防万一其他人在将来遇到这个问题后获得权限令牌以运行沙箱测试付款的完整代码是:
def test_sales(self, access_token=None, token_secret=None):
timestamp, signature = genPermissionsAuthHeader.getAuthHeader(str(self.username), str(self.password), str(access_token), str(token_secret), "POST", "https://api-3t.sandbox.paypal.com/nvp") # https://svcs.sandbox.paypal.com/Permissions/GetBasicPersonalData
log.info(timestamp)
log.info(signature)
authorization_header = "timestamp=" + timestamp + ",token=" + access_token + ",signature=" + signature
log.info(authorization_header)
headers = {
"X-PAYPAL-AUTHORIZATION": authorization_header,
}
url = "https://api-3t.sandbox.paypal.com/nvp"
nvp_params = {
"METHOD": "DoDirectPayment",
"PAYMENTACTION": "Sale",
"AMT": "22.00",
"ACCT": "4111111111111111",
"CVV2": "111",
"FIRSTNAME": "Jane",
"LASTNAME": "Smith",
"EXPDATE": "012018",
"IPADDRESS": "127.0.0.1",
"STREET": "123 Street Way",
"CITY": "Englewood",
"STATE": "CO",
"ZIP": "80112",
"VERSION": "86",
"SIGNATURE": self.signature,
"USER": self.username,
"PWD": self.password,
"SUBJECT": "person_who_you_acting_on_behalf_of@domain.com"
}
r = requests.post(url, data=nvp_params, headers=headers)
log.info("Search transaction\n\n" + r.text + "\n\n")
self.response.content_disposition = "text/html"
self.response.write(urllib.unquote(r.text).decode('utf8'))
为了生成我使用的标题:https://github.com/paypal/python-signature-generator-for-authentication-header
希望这对某人有所帮助,谢谢!
答案 1 :(得分:0)
以下是您收到的错误消息的一些信息。一个原因是无效的API凭据。另一种可能性是您尝试传递过期的令牌。在PayPal上创建交易后,令牌不再有效。相反,您创建了交易ID
以下是有关PayPal API错误消息的更多信息。
PayPal API Error Messages
如果您尝试在PayPal中搜索最近的交易,则可以使用 PaymentDetailsRequest API
以下是PayPal开发者网站的集成指南:
答案 2 :(得分:0)
TransactionSearch不是AdaptivePayments API的一部分, 所以没有" X-PAYPAL-AUTHORIZATION"这种方法是必需的。 假设您在目标帐户上获得了TransactionSearch方法的权限(请参阅https://developer.paypal.com/docs/classic/permissions-service/gs_PermissionsService/) 以下代码将起作用:
import requests
api_username="username"
api_password="password"
api_signature="signature"
target_account_email="xxx.yyy-buyer@zzz.com" #customers email
data_req = {
'METHOD':'TransactionSearch',
'SUBJECT':, target_account_email,
'VERSION':'86.0',
'STARTDATE':'2009-10-11T00:00:00Z',
'USER':api_username,
'PWD':api_password,
'SIGNATURE':api_signature
}
response=requests.post(url_en_point,data=data_req,timeout=3).text
print response