下面的代码:-
public bool AuthorizePayment(string Card_Num, string Exp_Date, string Card_Code, string amount)
{
//Console.WriteLine("Charge Credit Card Sample");
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
// define the merchant information (authentication / transaction id)
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ConfigurationManager.AppSettings["AuthNetID"],
ItemElementName = ItemChoiceType.transactionKey,
Item = ConfigurationManager.AppSettings["AuthNetKey"],
};
var creditCard = new creditCardType
{
cardNumber = Card_Num,
expirationDate = Exp_Date,
cardCode = Card_Code
};
//standard api call to retrieve response
var paymentType = new paymentType { Item = creditCard };
var transactionType = objInf.Get("x_type") == "AUTH_CAPTURE" ? transactionTypeEnum.authCaptureTransaction.ToString() : transactionTypeEnum.refundTransaction.ToString();
var transactionRequest = new transactionRequestType
{
transactionType = transactionType,
amount = Convert.ToDecimal(amount),
payment = paymentType,
};
if (objInf.Get("x_invoice_num") != null)
{
transactionRequest.order = new orderType { invoiceNumber = objInf.Get("x_invoice_num") };
}
if (objInf.Get("x_trans_id") != null)
{
transactionRequest.refTransId = objInf.Get("x_trans_id");
}
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the controller 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 response
if (response != null)
{
//other code
}
else
{
//other code
}
}
[大多数代码是从AuthNet网站复制粘贴的,如果我发送到AuthNet的卡代码是3位数字,则交易失败,Api返回空响应,即使API文档中明确提到了3位卡代码已验证。在这个问题上的任何帮助,将不胜感激。
错误消息中的XXXXXXX提示Authorize.Net正在获取5个字符,请检查您的cardCode是否用空格包装(例如“ cardCode”:“ 123”或“ 123”或“ 123”)。