我尝试生成PayPal payKey以与PayPal lightbox payment选项一起使用。下面的代码非常适合沙盒 - 它返回一个payKey。但是,当我将凭据(和URL)切换为指向生产PayPal网站时,我得到Internal server error. Please check the server logs for details
。没有返回其他信息。我该如何调试此问题?
import requests
import urlparse
import json
_ppuserid_ = "zzz_api1.zzz.zzz"
_pppassword_ = "zzzzz"
_ppsignature_ = "zzzzzzzz"
_ppappid_ = "APP-80W284485P519543T"
_ppendpoint_ = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
def __get_standard_headers__():
return {'X-PAYPAL-SECURITY-USERID': _ppuserid_,
'X-PAYPAL-SECURITY-PASSWORD': _pppassword_,
'X-PAYPAL-SECURITY-SIGNATURE': _ppsignature_,
'X-PAYPAL-REQUEST-DATA-FORMAT': 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON',
'X-PAYPAL-APPLICATION-ID': _ppappid_}
def get_paypal_pay_key(returnUrl, cancelUrl, paymentAmount):
'''Create a pay request. See https://developer.paypal.com/docs/classic/api/adaptive-payments/Pay_API_Operation/'''
headers = __get_standard_headers__()
jsondata = {
'actionType':'PAY',
'clientDetails': { 'applicationId' : _ppappid_ },
'currencyCode':'USD',
'memo':'Product 001',
'receiverList': { 'receiver' : { 'amount': paymentAmount, 'email': _ppreceiveremail_, 'paymentType': 'DIGITALGOODS' }},
'requestEnvelope': { 'errorLanguage': 'en_US' },
'returnUrl': returnUrl,
'cancelUrl': cancelUrl,
}
jsonObj = json.dumps(jsondata)
r = requests.post(_ppendpoint_, headers=headers, data=jsonObj)
parsed_response = r.json()
if parsed_response.get('responseEnvelope'):
if parsed_response.get('responseEnvelope').get('ack') == 'Success' and parsed_response.get('paymentExecStatus') == 'CREATED':
#Payment was created, return the pay key
return parsed_response.get('payKey')
return 'ERROR'
编辑:我还检索了生产响应的标题(作为Python字典),以防这有助于确定原因:
{'Content-Length': '76', 'X-PAYPAL-OPERATION-NAME': 'Pay', 'X-PAYPAL-SERVICE-NAME': '{http://svcs.paypal.com/types/aa}AdaptiveAccounts', 'X-PAYPAL-ERROR-RESPONSE': 'TRUE', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'X-EBAY-SOA-REQUEST-ID': '152a7963-e700-a101-8644-d108fff16e1a!AdaptiveAccounts!10.16.24.100![]', 'Server': 'Apache', 'Connection': 'close', 'Paypal-Debug-Id': 'c31f40fb798e2', 'X-PAYPAL-SERVICE-VERSION': '1.0.0', 'Pragma': 'no-cache', 'Set-Cookie': 'X-PP-SILOVER=name%3DLIVE9.APIT.1%26silo_version%3D880%26app%3Dadaptiveaccountsapiserv%26TIME%3D4212240982; domain=.paypal.com; path=/; Secure; HttpOnly, X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT', 'Date': 'Wed, 03 Feb 2016 14:43:07 GMT', 'CACHE-CONTROL': 'no-cache, max-age=0, no-cache, no-store, must-revalidate', 'X-EBAY-SOA-RESPONSE-DATA-FORMAT': 'JSON', 'Content-Type': 'application/json;charset=UTF-8', 'X-EBAY-SOA-MESSAGE-PROTOCOL': 'NONE'}
Internal server error. Please check the server logs for details