Example response JavaScript object onSuccesss

This example shows the three variables for the response JavaScript object; offerLists, messages, and profile.

offerList returns a non null list if you call getOffer or getOffersForMultipleInteractionPoints as an API or as part of your batch commands. You should always check null on this before you perform any operation on this variable.

You should always check the status of the messages JavaScript response.

Profile is returned non null if you use getProfile as an API or part of your batch commands. If you do not use getProfile, you can ignore this variable. You should always check null on this before you perform any operation on this variable.

function onSuccess(response)  
InteractAPI.ResponseTransUtil._buildResponse = function(response) {
        'use strict';

        if (!response) return null;

        var offerList = null;
        //transform offerLists to JS Objects
        if (response.offerLists) {
            offerList = [];
            for (var ofListCt=0; ofListCt<response.offerLists.length;ofListCt++) {
                var ofListObj = this._buildOfferList(response.offerLists[ofListCt]);
                if (ofListObj) offerList.push(ofListObj);
            }
        }

        var messages = null;
        //transform messages to JS Objects
        if (response.messages) {
            messages = [];
            for (var msgCt=0; msgCt<response.messages.length;msgCt++) {
                var msgObj = this._buildAdvisoryMessage(response.messages[msgCt]);
                if (msgObj) messages.push(msgObj);
            }
        }

        var profile = null;
        //transform profile nvps to JS Objects
        if (response.profile) {
            profile = [];
            for (var nvpCt=0; nvpCt<response.profile.length;nvpCt++) {
                var nvpObj = this._buildNameValuePair(response.profile[nvpCt]);
                if (nvpObj) profile.push(nvpObj);
            }
        }

        return InteractAPI.Response.create(response.sessionId, 
                                           response.statusCode, offerList, 
                                           profile, response.version, 
                                           messages) ;
    };