cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Python Switch to Production Mode (controller environment)

I am trying to change from sandbox to production with Python and I keep getting this error.

Error Code: E00007

Error message: User authentication failed due to invalid authentication values.

My code was working correctly in the sandbox environment, but once I switched my apiLoginId and transactionKey to the production version, I am no longer able to make payments. These credentials are correct (which is the only issue offered by Authorize.net here: https://developer.authorize.net/api/reference/responseCodes.html?code=e00007).

I am wondering if the ...

Here is my code:

import imp

import os

import sys

import importlib

from authorizenet.constants import constants

from authorizenet import apicontractsv1

from authorizenet.apicontrollers import createTransactionController



from .constants import MY_CONSTANTS  #contains my apiLoginId and transactionKey



def charge_credit_card(amount, number, first_name, last_name, expire_month, expire_year, cvv_number, product_name, description, product_pk, user_pk, user_email):



   # Create a merchantAuthenticationType object with authentication details

   # retrieved from the constants file

   merchantAuth = apicontractsv1.merchantAuthenticationType()

   merchantAuth.name = MY_CONSTANTS['apiLoginId']

   merchantAuth.transactionKey = MY_CONSTANTS['transactionKey']



   .........



   # Assemble the complete transaction request

   createtransactionrequest = apicontractsv1.createTransactionRequest()

   createtransactionrequest.merchantAuthentication = merchantAuth

   createtransactionrequest.refId = "MerchantID-0001"

   createtransactionrequest.transactionRequest = transactionrequest

   # Create the controller

   createtransactioncontroller = createTransactionController(

       createtransactionrequest)

   createtransactioncontroller.setenvironment(settings.PRODUCTION)

   createtransactioncontroller.execute()



I am having the same error as https://stackoverflow.com/questions/56741738/how-to-pass-the-production-variable-to-authorize-net-ap...

Could someone please tell me where the url goes or whatever is wrong with my code?

jessej917
Member
1 REPLY 1

I solved error. The way I fixed it was I changed the file constants.py to credentials.py and then I changed the variable to MY_CONSTANTS but you can change them to be credentials if you want.

If it does doesn't work at that point you could try to hard code it instead with createtransactioncontroller.setenvironment('https://api2.authorize.net/xml/v1/request.api') but if you don't then leave it to be constants.PRODUCTION

    createtransactioncontroller = createTransactionController(createtransactionrequest)    createtransactioncontroller.setenvironment(constants.PRODUCTION)
    # or createtransactioncontroller.setenvironment('https://api2.authorize.net/xml/v1/request.api')    createtransactioncontroller.execute()

I used a dictionary for my credentials(constants in your case) so mine looks a little different.

    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 filemerchantAuth = apicontractsv1.merchantAuthenticationType()merchantAuth.name = MY_CONSTANTS['apiLoginId']merchantAuth.transactionKey = MY_CONSTANTS['transactionKey']

 I hope this helps anyone with the same issue.

jessej917
Member