我正在尝试通过Authorize.Net设置定期订阅付款。我基本上逐字遵循了他们的示例代码,并收到以下错误:
System.InvalidOperationException:'生成一个错误 XML文档。” 内部异常1:InvalidOperationException:类型System.String 在这种情况下可能无法使用。
如您所见,错误消息并不是非常有用。该错误发生在“ controller.Execute()”上。任何想法可能是什么问题?提前致谢。
public ANetApiResponse Run(string apiLoginId, string apiTransactionKey, AuthNetQuickCheckoutModel model)
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = apiLoginId,
ItemElementName = ItemChoiceType.transactionKey,
Item = apiTransactionKey,
};
paymentScheduleTypeInterval interval = new paymentScheduleTypeInterval
{
length = (short)model.SubscriptionLength,
unit = ARBSubscriptionUnitEnum.months
};
paymentScheduleType schedule = new paymentScheduleType
{
interval = interval,
startDate = DateTime.Now,
totalOccurrences = (short)model.SubscriptionLength,
trialOccurrences = 0,
};
#region Payment Information
var creditCard = new creditCardType
{
cardNumber = model.CardNumber,
expirationDate = model.ExpirationDate,
cardCode = model.CardCode
};
paymentType cc = new paymentType { Item = creditCard };
#endregion
nameAndAddressType addressInfo = new nameAndAddressType()
{
firstName = model.FirstName,
lastName = model.LastName
//company =
};
ARBSubscriptionType subscriptionType = new ARBSubscriptionType()
{
amount = model.Amount,
trialAmount = 0,
paymentSchedule = schedule,
billTo = addressInfo,
payment = cc
};
var request = new ARBCreateSubscriptionRequest { subscription = subscriptionType };
var controller = new ARBCreateSubscriptionController(request);
controller.Execute();
ARBCreateSubscriptionResponse response = controller.GetApiResponse();
if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
{
if (response?.messages.message != null)
{
Console.WriteLine("Success, Subscription ID: " + response.subscriptionId);
}
}
else if (response != null)
{
Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text);
}
return response;
}
}