gpt4 book ai didi

python - PayPal 错误 10002 使用权限 API 和 TransactionSearch

转载 作者:太空宇宙 更新时间:2023-11-03 16:02:04 25 4
gpt4 key购买 nike

我有一个如下所示的权限请求:

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 获得了访问 token 和 token secret

当我运行此方法时,我收到错误消息:

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,它似乎有效。任何帮助都会很棒,谢谢!

最佳答案

我找到了答案,我在为付款发送的参数字符串中缺少“SUBJECT”参数。因此,以防万一其他人在未来遇到这个问题,在获得权限 token 以运行沙箱测试支付后的完整代码是:

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

为了生成 header ,我使用了:https://github.com/paypal/python-signature-generator-for-authentication-header

希望这对某人有帮助,谢谢!

关于python - PayPal 错误 10002 使用权限 API 和 TransactionSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23207464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com