我正在通过Authorize.Net API进行交易。 我使用的是相同的代码示例,SDK表示,为了切换到生产环境,我需要在控制器上设置环境变量。 链接为here。我不确定应该在哪里添加此行代码
createtransactioncontroller.setenvironment(constants.PRODUCTION)
其余代码为here
这是使用控制器的正确方法
import os
import sys
import imp
from datetime import datetime, timedelta
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import getSettledBatchListController
from authorizenet.apicontrollers import createTransactionController
constants = imp.load_source('modulename', 'constants.py')
def get_settled_batch_list():
"""get settled batch list"""
createTransactionController.setenvironment(constants.PRODUCTION)
merchantAuth = apicontractsv1.merchantAuthenticationType()
答案 0 :(得分:2)
我也遇到了同样的错误,我的解决方法是将constants.py文件更改为凭据.py,然后将变量更改为MY_CONSTANTS,但您可以根据需要将其更改为凭据。
如果那时候不起作用,您可以尝试使用createtransactioncontroller.setenvironment('https://api2.authorize.net/xml/v1/request.api')对其进行硬编码。 但如果您不这样做,则将其保留为常量。PRODUCTION
createtransactioncontroller = createTransactionController(createtransactionrequest)
createtransactioncontroller.setenvironment(constants.PRODUCTION)
# or createtransactioncontroller.setenvironment('https://api2.authorize.net/xml/v1/request.api')
createtransactioncontroller.execute()
我为我的证书使用了一个字典(在您的情况下为常数),所以我的看上去有点不同。
import imp
import os
import sys
import importlib
from authorizenet.constants import constants
from authorizenet import apicontractsv1
from authorizenet.apicontrollers import createTransactionController
from .credentials import MY_CONSTANTS
# retrieved from the constants file
merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = MY_CONSTANTS['apiLoginId']
merchantAuth.transactionKey = MY_CONSTANTS['transactionKey']
希望这对您有所帮助。