我想使用asp.net在我的网站上实现Authorize .net支付网关。我是这方面的初学者。有人可以给我一个示例代码,我可以将其重定向到Authorize.net页面以完成付款流程。 我创建了一个沙箱帐户。 重定向网址 - 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<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;
}
答案 0 :(得分:0)
Aparajita您必须使用Authorize.Net帐户中的沙箱API凭据进行检查
答案 1 :(得分:0)
这经常出现,原因总是一样的:
验证您实际遇到的端点。
如果您要对生产环境进行测试,请验证代码中的URL是否为实际生产URL(或者如果您使用的是框架,则配置将设置为生产)。
正确的制作网址为https://api2.authorize.net/xml/v1/request.api
。
正确的测试网址为https://apitest.authorize.net/xml/v1/request.api
验证您的凭据
如果您确定要访问正确的端点,则需要验证您是否使用了该环境的正确凭据。
测试模式不是沙箱
将测试模式与沙盒环境混淆是很常见的。生产中的测试模式使用生产环境和生产凭证。使用沙箱凭据或URL无效。
答案 2 :(得分:0)
我用这个示例项目来解决我的问题。这是测试模式。
https://github.com/AuthorizeNet/sdk-dotnet/tree/master/CoffeeShopWebApp