Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

c# - (13) The merchant login ID or password is invalid or the account is inactive

I want to implement Authorize .net payment gateway in my website using asp.net. I am a beginner in this. Can someone give me a sample code from where I can be redirected to the Authorize.net page to complete payment process. I have created a sandbox account. Redirection URL - https://test.authorize.net/gateway/transact.dll but I get an error

(13) The merchant login ID or password is invalid or the account is inactive.

My account is active and in test mode.

My Code:

protected void Button_pay_Click(object sender, EventArgs e)
    {
        string value = TextBox_amt.Text;
        decimal d = decimal.Parse(value);
        Run("abc", "abcq234", d);
     }
 public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount)
    {
        Console.WriteLine("Create an Accept Payment Transaction Sample");

        ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;

        // define the merchant information (authentication / transaction id)
        ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
        {
            name = ApiLoginID,
            ItemElementName = ItemChoiceType.transactionKey,
            Item = ApiTransactionKey,
        };

        var opaqueData = new opaqueDataType
        {
            dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT",
            dataValue = "119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9"

        };

        var billingAddress = new customerAddressType
        {
            firstName = "John",
            lastName = "Doe",
            address = "123 My St",
            city = "OurTown",
            zip = "98004"
        };

        //standard api call to retrieve response
        var paymentType = new paymentType { Item = opaqueData };

        // Add line Items
        var lineItems = new lineItemType[2];
        lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) };
        lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) };

        var transactionRequest = new transactionRequestType
        {
            transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // charge the card

            amount = amount,
            payment = paymentType,
            billTo = billingAddress,
            lineItems = lineItems
        };

        var request = new createTransactionRequest { transactionRequest = transactionRequest };

        // instantiate the contoller that will call the service
        var controller = new createTransactionController(request);
        controller.Execute();

        // get the response from the service (errors contained if any)
        var response = controller.GetApiResponse();

        //validate
        if (response != null)
        {
            if (response.messages.resultCode == messageTypeEnum.Ok)
            {
                if (response.transactionResponse.messages != null)
                {
                    Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId);
                    Console.WriteLine("Response Code: " + response.transactionResponse.responseCode);
                    Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code);
                    Console.WriteLine("Description: " + response.transactionResponse.messages[0].description);
                    Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode);
                }
                else
                {
                    Console.WriteLine("Failed Transaction.");
                    if (response.transactionResponse.errors != null)
                    {
                        Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                        Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                    }
                }
            }
            else
            {
                Console.WriteLine("Failed Transaction.");
                if (response.transactionResponse != null && response.transactionResponse.errors != null)
                {
                    Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode);
                    Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText);
                }
                else
                {
                    Console.WriteLine("Error Code: " + response.messages.message[0].code);
                    Console.WriteLine("Error message: " + response.messages.message[0].text);
                }
            }
        }
        else
        {
            Console.WriteLine("Null Response.");
        }

        return response;
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Aparajita you must check with the API credentials for sandbox in Authorize.Net account


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...