Reply
Highlighted
Member
Posts: 4
Registered: ‎08-31-2018

ARB - Error Generating XML Document

[ Edited ]

 I'm trying to set up ARB for the first time and am receiving the following error:

 

"System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.String may not be used in this context."

 

Here is my code: 

 

 

 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 = 12,
                                                         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;
        }


The error occurs at controller.Execute(). 

 

 

Thank you!