0

I have a remote action invocation in my payment method to initialize things. I basically return a URL and some parameters to use in the UI.

However B2B Commerce always passes the data with HTML entity encoding back to my JS callback methods.

I've checked the call stack and it seems to me as it is returned just fine from Apex - so the encoding happens somewhere in the CC stack.

My code (VF):

this.invokeCtx(
'initiatePaymentRequest',
        function(resp)
        {
            // Here, resp.data already has HTML entities encoded.
            callback(resp);
        },
        {
            buffer : false, 
            nmsp   : false
        }
    );

My code (apex):

@RemoteAction
global static ccrz.cc_RemoteActionResult initiatePaymentRequest(ccrz.cc_RemoteActionContext ctx)
{
    ccrz.cc_RemoteActionResult res = ccrz.cc_CallContext.init(ctx);

    Map<String, Object> resultMap = new Map<String, Object>();
    resultMap.put('url', './B2B_PaymentCallback?isCallback=1&fromApex=1');

    resultMap.put('params', new Map<String, Object>());
    ((Map<String, Object>)resultMap.get('params')).put('param1', 'apex&val1');
    ((Map<String, Object>)resultMap.get('params')).put('currencyCode', 'EUR');
    ((Map<String, Object>)resultMap.get('params')).put('locale', 'en_US');

    res.data = resultMap;
    res.success = true; 
    return res;
}

Note the 2 "&" characters in the mock result.

In my JS method, resp.data.url comes back as './B2B_PaymentCallback?isCallback=1&amp;fromApex=1'. The same happens with the other ampersand. It also happens to other characters that can be HTML encoded, e.g. a quotation mark ( " will result in &quot;).

Can anyone give me a hint how to prevent this encoding behaviour? I could not find anything in the CC documentation.

Thanks!

0

I could not find a proper solution to this but kind of a workaround - not a nice one though.

I ended up simply decoding the HTML entities using B2B Commerce's Handlebars helper function. Now my JS looks like this:

this.invokeCtx(
    'initiatePaymentRequest',
    function(resp, event)
    {
        // Decode all the parameter values
        Object.keys(resp.data.params).forEach(k => resp.data.params[k] = Handlebars.helpers.decodeHTML(resp.data.params[k]).string);
        // Decode the URL (or rather its query parameters)
        resp.data.url = Handlebars.helpers.decodeHTML(resp.data.url).string;

        callback(resp);
    },
    {
        buffer : false,
        nmsp   : false
    }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.