Я пытаюсь настроить периодические платежи по подписке через 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;
}
}