Integration and Testing

Authorize.Net API questions and help with your payment integration.

Reply
Member
Posts: 1
Registered: ‎07-07-2016

Having trouble with XSD's and 1.9.6

As of the 1.9.6 .NET SDK, it looks like the older AIM methods have been deprecated, which caused our build to break. In trying to upgrade our solution to use the newer flavor, I've run into some problems that don't seem to be mentioned in any of the googling I've done.

 

Problem #1: when attempting to charge an eCheck, I get the following error:

 

The element 'bankAccount' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'echeckType' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'nameOnAccount' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.

 

 

Problem #2: When attempting to charge a credit card, I get the following error:

 

The type AuthorizeNet.APICore.creditCardType was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

 

The relevant code for both:

 

        public Task<createTransactionResponse> ChargeCard(PurchaseRequest purchaseRequest)
        {
            // Charge the credit card
            var profiler = MiniProfiler.Current;
            using (profiler.Step("Authorize.net: Charge credit card"))
            {
                var cc = purchaseRequest.CreditCard;
                LogDebug($"Charging credit card with billing address {purchaseRequest.BillingAddress.ToSingleLine()}");

                var creditCard = new creditCardType
                {
                    cardNumber = cc.Number,
                    expirationDate = ToCCExp(cc.Expires),
                    cardCode = cc.Cvv
                };

                var billingAddress = GetBillingAddress(purchaseRequest);
                var customer = GetCustomer(purchaseRequest);

                var paymentType = new paymentType
                {
                    Item = creditCard
                };

                var request = GetTransactionRequest(purchaseRequest, paymentType, billingAddress, customer);

                var apiResponse = GetApiResponse(request);

                // ks 10/15/18 - It's kind of nuts that in this day and age, Authorize.net still doesn't have an async API.
                // But we're leaving the structure of *our* code async, in the hopes that eventually they'll see the light.
                return Task.FromResult(apiResponse);
            }
        }

        /// <summary>
        /// Submit payment request to eCheck system.
        /// </summary>
        public Task<createTransactionResponse> ChargeAccount(PurchaseRequest purchaseRequest)
        {
            var accountType = purchaseRequest.ECheck.AccountType.EqualsNoCase(ECheckAccountTypes.Checking.ToString())
                ? bankAccountTypeEnum.checking
                : bankAccountTypeEnum.savings;

            var eCheck = purchaseRequest.ECheck;
            var bankAccount = new bankAccountType
            {
                accountType = accountType,
                routingNumber = eCheck.RoutingNumber,
                accountNumber = eCheck.AccountNumber,
                nameOnAccount = eCheck.AccountOwner,
                bankName = "",
                echeckType = echeckTypeEnum.WEB,   // change based on how you take the payment (web, telephone, etc)
            };

            var billingAddress = GetBillingAddress(purchaseRequest);
            var customer = GetCustomer(purchaseRequest);

            // standard api call to retrieve response
            var paymentType = new paymentType { Item = bankAccount };

            var request = GetTransactionRequest(purchaseRequest, paymentType, billingAddress, customer);

            var apiResponse = GetApiResponse(request);

            // ks 10/15/18 - It's kind of nuts that in this day and age, Authorize.net still doesn't have an async API.
            // But we're leaving the structure of *our* code async, in the hopes that eventually they'll see the light.
            // instantiate the controller that will call the service
            return Task.FromResult(apiResponse);
        }

        private static customerAddressType GetBillingAddress(PurchaseRequest purchaseRequest)
        {
            var cc = purchaseRequest.CreditCard;
            var billingAddress = new customerAddressType
            {
                firstName = cc.FirstName,
                lastName = cc.LastName,
                phoneNumber = cc.Phone,
                address = purchaseRequest.BillingAddress.Street1,
                city = purchaseRequest.BillingAddress.City,
                state = purchaseRequest.BillingAddress.StateCode,
                zip = purchaseRequest.BillingAddress.Zip,
                email = cc.Email
            };
            return billingAddress;
        }

        private static customerDataType GetCustomer(PurchaseRequest purchaseRequest)
        {
            var customer = new customerDataType
            {
                email = purchaseRequest.CreditCard.Email,
                id = purchaseRequest.QuoteId.ToString()
            };
            return customer;
        }

        private createTransactionRequest GetTransactionRequest(PurchaseRequest purchaseRequest, paymentType paymentType, customerAddressType billingAddress, customerDataType customer)
        {
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
                amount = GetChargeAmount(purchaseRequest),                
                payment = paymentType,
                billTo = billingAddress,
                customer = customer
            };

            var request = new createTransactionRequest
            {
                transactionRequest = transactionRequest
            };
            return request;
        }

        private static createTransactionResponse GetApiResponse(createTransactionRequest request)
        {
            var controller = new createTransactionController(request);
            controller.Execute();

            var apiResponse = controller.GetApiResponse();

            if (apiResponse == null)
            {
                var error = controller.GetErrorResponse();
                var message = error.messages.message.First();
                throw new PaymentFailedException(message.text, message.code);
            }

            return apiResponse;
        }

Any suggestions?

Developer
Posts: 30
Registered: ‎11-22-2017

Re: Having trouble with XSD's and 1.9.6

Hi @smithkl42,

 

Thanks for reaching out to us.

 

For Problem #1, I was able to reproduce this issue. It seems that this happens because the nameOnAccount field is assigned a null value.

 

Can you perform some validation on this field, making sure that the field is not null?

 

For Problem #2, the class creditCardType that should be used, is present in the namespace AuthorizeNet.Api.Contracts.V1, and not in AuthorizeNet.APICore.

 

Can you make this change and try again?

 

Awaiting your reply,

Gabriel