cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing error when creating ARB from existing CIM

Using the Authorize.net API to set up Automated Recurring Billing, the ARB is set up correctly when credit card info is input on our view. If, however, we allow the user to select a card within their profile, we get a parsing error in the response.

This is happening in both the sandbox and operational environment. We are using the latest Java SDK, Java 8 and Tomcat 8.

 

The code to create a subscription and asscociate it with an existing profile is based on the sample code in the developer documentation. The ccp object in the code below is our own object that contains the customerProfileid, customerPaymentProfileid, and the customerAddressid, which we harvest upstream.

 

Here is the stack trace, and after that, the code.

 

[INFO,XmlUtility] Exception - while deserializing text:'<?xml version="1.0" encoding="utf-8"?><ErrorResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><messages><resultCode>Error</resultCode><message><code>E00003</code><text>The element 'creditCard' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'expirationDate' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'cardNumber' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.</text></message></messages></ErrorResponse>
' 
[WARN,XmlUtility] Exception Details-> Code:'null', Message:'unexpected element (uri:"AnetApi/xml/v1/schema/AnetApiSchema.xsd", local:"ErrorResponse"). Expected elements are <{AnetApi/xml/v1/schema/AnetApiSchema.xsd}ARBCancelSubscriptionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}ARBCreateSubscriptionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}ARBGetSubscriptionListResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}ARBGetSubscriptionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}ARBGetSubscriptionStatusResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}ARBUpdateSubscriptionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}authenticateTestResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}createCustomerPaymentProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}createCustomerProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}createCustomerProfileTransactionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}createCustomerShippingAddressResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}createTransactionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}decryptPaymentDataResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}deleteCustomerPaymentProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}deleteCustomerProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}deleteCustomerShippingAddressResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getAUJobDetailsResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getAUJobSummaryResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getBatchStatisticsResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getCustomerPaymentProfileListResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getCustomerPaymentProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getCustomerProfileIdsResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getCustomerProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getCustomerShippingAddressResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getHostedPaymentPageResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getHostedProfilePageResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getMerchantDetailsResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getSettledBatchListResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getTransactionDetailsResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getTransactionListResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}getUnsettledTransactionListResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}isAliveResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}logoutResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}mobileDeviceLoginResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}mobileDeviceRegistrationResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}securePaymentContainerResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}sendCustomerTransactionReceiptResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}updateCustomerPaymentProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}updateCustomerProfileResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}updateCustomerShippingAddressResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}updateHeldTransactionResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}updateMerchantDetailsResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}updateSplitTenderGroupResponse>,<{AnetApi/xml/v1/schema/AnetApiSchema.xsd}validateCustomerPaymentProfileResponse>'

 

       net.authorize.api.contract.v1.CustomerProfileIdType profile=null;
    PaymentScheduleType schedule = new PaymentScheduleType();
    PaymentScheduleType.Interval interval = new PaymentScheduleType.Interval();
    interval.setLength((short)intervalLength); 
    interval.setUnit(intervalType);
    schedule.setInterval(interval);
    GregorianCalendar cal=new GregorianCalendar();
    cal.setTime(start);
    schedule.setStartDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));

    schedule.setTotalOccurrences((short)totalPayments);
    schedule.setTrialOccurrences((short)0);

    if(ccp!=null) {
        profile = new net.authorize.api.contract.v1.CustomerProfileIdType();
        profile.setCustomerProfileId(String.valueOf(ccp.getCustomerProfileid()));
        profile.setCustomerPaymentProfileId(String.valueOf(ccp.getPaymentProfileid()));
        profile.setCustomerAddressId(ccp.getCustomerAddressid());  // cannot find how to retrieve customerAddressID from Authorize.net
    }

    ARBSubscriptionType arbSubscriptionType = new ARBSubscriptionType();
    arbSubscriptionType.setPaymentSchedule(schedule);
    arbSubscriptionType.setAmount(amountPerInterval.getBigDecimal());
    arbSubscriptionType.setTrialAmount(Money.ZERO.getBigDecimal());
    arbSubscriptionType.setPayment(pmt);
    arbSubscriptionType.setOrder(order);

    if(ccp!=null) {
        arbSubscriptionType.setProfile(profile);
    }

    NameAndAddressType name = new NameAndAddressType();
    name.setFirstName(customer.getName());
    name.setLastName(customer.getSurName());

    arbSubscriptionType.setBillTo(name);

    ARBCreateSubscriptionRequest apiRequest = new ARBCreateSubscriptionRequest();
    apiRequest.setSubscription(arbSubscriptionType);
    ARBCreateSubscriptionController controller = new ARBCreateSubscriptionController(apiRequest);
    controller.execute();
    ARBCreateSubscriptionResponse response = controller.getApiResponse();
    checkResponse(response);

museminder
Contributor
11 REPLIES 11

I have found the answer to my question.  When setting up an ARB using an existing customer profile you must not include any PaymentType, Order, or BillTo properties in your request.  

 

As you might deduce from my code, I was using the same constructor to create a subscription, and then building a profile if my profile object was not null, but in so doing I left in these lines of code

 

    arbSubscriptionType.setPayment(pmt);
    arbSubscriptionType.setOrder(order);

 

and I left in  

 

    NameAndAddressType name = new NameAndAddressType();
    name.setFirstName(customer.getName());
    name.setLastName(customer.getSurName());

    arbSubscriptionType.setBillTo(name);

 

These should NOT be part of a createsubscription request when it is being created from an existing profile.

 

To clarify things in my code, I have created two separate wrapper methods to construct the create subscription request, one to create a subscription with a fresh set of payment info, and the other that leaves those things out but contains the reference to the existing profile.

 

As it happens, if you leave out the order and payment setters and leave in the billto segment, Authorize.net will return a clear response with a helpful error message that says something like "BillTo should not be used along with profile info".  At least that points you somewhere.  However, if you include the payment and order, all you get is a parsing error.

 

Many thanks to @rajvpate for helping me get on the right track to understanding my error.

museminder
Contributor

Hi

 

Glad that you were able to look into this and find a solution.

Apologies I couldnt get back promptly on this.

 

Please let us know in case you have more questions. I will try to be prompt :)

Best wishes for New Year!