(13)商家登录ID或密码无效或帐户无效

我想使用asp.net在我的网站上实现Authorize .net支付网关。 我是这方面的初学者。 有人可以给我一个示例代码,我可以将其重定向到Authorize.net页面以完成付款流程。 我创建了一个沙箱帐户。 重定向URL – https://test.authorize.net/gateway/transact.dll但我收到错误

(13)商家登录ID或密码无效或帐户无效。

我的帐户处于有效状态且处于测试模式

我的代码:

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.RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) ApiOperationBase.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; } 

Aparajita您必须使用Authorize.Net帐户中的沙箱API凭据进行检查

这经常出现,原因总是一样的:

  1. 您正在使用生产凭据但是访问沙箱端点
  2. 您正在使用沙盒凭据,但正在访问生产端点
  3. 您使用的凭据不正确

validation您实际遇到的端点。

如果要针对生产环境进行测试,请validation代码中的URL是否为实际生产URL(或者如果使用的是框架,则配置将设置为生产)。

正确的生产URL是https://api2.authorize.net/xml/v1/request.api

正确的测试url是https://apitest.authorize.net/xml/v1/request.api

validation您的凭据

如果您确定要访问正确的端点,则需要validation您是否使用了该环境的正确凭据。

  • 确保使用的是API登录和事务密钥,而不是控制台登录名和密码。 他们不是一回事。 访问API时,只有API登录和事务密钥才有效。 您可以在登录控制台后获取这些信息。
  • 仔细检查控制台中的API登录是否正确。
  • 如果API登录正确,则从客户控制台中生成新的事务密钥以validation您是否具有正确的密钥。
  • 确保在代码中不会意外输入凭据。 确保所有角色都在那里。 此外,凭据区分大小写。 确保没有大写或小写这些值。
  • 如果您需要validation您的登录凭据工作,请设置一个MVCE,该MVCE将使用您的API凭据访问您尝试访问的端点。 它应该是一个简单的脚本,可以进行基本的API调用。 这样可以轻松调试您收到此错误的原因。

测试模式不是沙箱

将测试模式与沙箱环境混淆是很常见的。 生产中的测试模式使用生产环境和生产凭证。 使用沙盒凭据或URL将不起作用。

我用这个示例项目来解决我的问题。 这是测试模式。

https://github.com/AuthorizeNet/sdk-dotnet/tree/master/CoffeeShopWebApp