+ Start a Discussion
Sricharan Puligundla 11Sricharan Puligundla 11 

Apex:iframe loading a blank page

Hi
I have an visualforce page which calls custom controller.A method getIFrameSrc gets the ifRame URL.That URL i have to pass it to visualforce page <apex:iframe>.I am able to pass it.But i am getting a blank page.
VF Page Code
<apex:page sidebar="false"  controller="CXiIntercept3">
<!--action="{!getIFrameSrc}">-->
<!--showHeader="false"-->
<!--<apex:stylesheet value="{!URLFOR($Resource.paymetricsCSS, 'paymetricsCSS.css')}"/>-->
  <apex:form >
  <!--<apex:actionFunction name="getIFrameSrc" action="{!getIFrameSrc}" rerender="out" status="myStatus"/>-->
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="cache-control" content="no-cache, no-store, max-age=0, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <title>XiIntercept v3 - Implementation Demo</title>
    <script type="text/javascript">
<form id="form1">
   
        <div>
            <p>This sample shows the basic functionality of implementing the iframe solution.</p>
            <!--<iframe id="IFrame" name="dieCommFrame" frameBorder="0" src="http://www.w3schools.com"></iframe>-->
            <apex:iframe id="dieCommFrame" frameborder="0" src="{!getIFrameSrc}"/>
             <!--<apex:commandButton value="Load" action="{!getIFrameSrc}"/>-->
              <!--<apex:commandLink action="{!getIFrameSrc}" value="Load" id="theCommandLink"/>-->
            <!--<apex:param name="strSrcURL"
                value="{!getIFrameSrc}"
                assignTo="{!getIFrameSrc}"/>-->
        <!--</apex:commandButton>-->
                    </div>
        <div>
            <p />
            <table>
                <thead>
                    <tr>
                        <th colspan="2">Billing Address</th>
                    </tr>               
                </thead>
                <tbody>
                    <tr>
                        <td class="Column1">Name</td>
                        <td class="Column2">
                        <input id="Text1" type="text" value="John Doe" size="32" /></td>
                        <!--<apex:InputField label="Name" id="Text1" value="John Doe"/>-->
                    </tr>
                    <tr>
                        <td class="Column1">Address</td>
                        <td class="Column2"><input id="Text2" type="text" value="19500 State Hwy 249" size="32" /></td>
                    </tr>
                    <tr>
                        <td class="Column1">City</td>
                        <td class="Column2"><input id="Text3" type="text" value="Houston" size="32" /></td>
                    </tr>
                    <tr>
                        <td class="Column1">State</td>
                        <td class="Column2"><input id="Text4" type="text" value="Texas" size="16" /></td>
                    </tr>
                    <tr>
                        <td class="Column1">Zip Code</td>
                        <td class="Column2"><input id="Text5" type="text" value="77070" size="8" /></td>
                    </tr>
                    <tr>
                        <td class="Column1">&nbsp;</td>
                        <td class="Column2">&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="Column1">&nbsp;</td>
                        <td class="Column2">
                              <!--<apex:commandButton id="cmdPayment" action="{!submitForm}" value="Tokenize Data"/>-->
                         <input id="cmdPayment" type="button" onclick="submitForm(); return false;" value="Tokenize Data" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </form>
       </body>
       </apex:form>
    </apex:page>
Apex Class Code is given below
public with sharing class CXiIntercept3
{

   /*public CXiIntercept3(ApexPages.StandardController controller) {
       m_strURL = 'https://qaapp02.xisecurenet.com/diecomm';
        m_strGUID = '8842aa98-d6d1-40a4-9ee0-c02a3393b7af' ;
        m_strPSK = '4Kb/=5ZkrX{7_3HcTt8+!Md6C2$e9}aJ' ;
        getIFrameSrc();
    }*/


    public String getIFrameSrc { get;
    set
    {
        System.debug('Inside IFrameSrc');
        String strWhere = 'getIFrameSrc';
        //alert('getIFrameSrc');
        System.debug('strWhere is'+strWhere);
        String strAccessToken = getIFrameAccessToken();
       
        String strSrcURL = m_strURL + '/view/iframe/' + m_strGUID + '/' + strAccessToken + '/true';
       
        Log(strWhere, 'IFrameSrc', strSrcURL);
        System.debug('iFrame URL is'+strSrcURL);
        getIFrameSrc = strSrcURL;
        System.debug('getIFrameSRc is'+getIFrameSrc);
        //return strSrcURL;
     }
    }
    public PageReference submitForm() {
        /*pageReference acctPage = new PageReference('https://cynosure--slqa--c.cs19.visual.force.com/apex/Paymetrics_Page');
    acctPage.setRedirect(true);*/
        return null ;    }

    public String m_strURL;
    public String m_strGUID;
    public String m_strPSK;
       
    public CXiIntercept3()
    {
        m_strURL = 'https://qaapp02.xisecurenet.com/diecomm';
        m_strGUID = '8842aa98-d6d1-40a4-9ee0-c02a3393b7af' ;
        m_strPSK = '4Kb/=5ZkrX{7_3HcTt8+!Md6C2$e9}aJ' ;
        getIFrameSrc();
      }

    public String getIFrameSrc()
    {
        System.debug('Inside IFrameSrc');
        String strWhere = 'getIFrameSrc';
        //alert('getIFrameSrc');
        System.debug('strWhere is'+strWhere);
        String strAccessToken = getIFrameAccessToken();
       
        String strSrcURL = m_strURL + '/view/iframe/' + m_strGUID + '/' + strAccessToken + '/true';
       
        Log(strWhere, 'IFrameSrc', strSrcURL);
        System.debug('iFrame URL is'+strSrcURL);
       
        return strSrcURL;
    }
   
    public String getIFrameAccessToken()
    {
        String strAT = '';
        String strResponse = '';
        String strURL = m_strURL + '/AccessToken';
        String strWhere = 'getSignedXML';
        StaticResource static_resource = [Select Body From StaticResource Where Name = 'Paymetrics_CSS'];
        String strXml = static_resource.body.toString();
        System.debug('strxml is'+strxml);
        //String strXml = '';
        //String strXml = getIFrameMerchantHTML();
        String strSignature = '';
       
        Dom.Document hDoc = null;
        Dom.XmlNode hRoot = null;
        Dom.XmlNode hResponse = null;
        Dom.XmlNode hAT = null;
        System.debug('packet ' + EncodingUtil.urlEncode(strXml, 'UTF-8'));
        String strPostXml = 'MerchantGuid=' + m_strGUID + '&' +
                    'SessionRequestType=1&' +
                    'Packet=' + EncodingUtil.urlEncode(strXml, 'UTF-8') + '&' +
                    'Signature=' + EncodingUtil.urlEncode(getDigitalSignature(strXml), 'UTF-8') + '&' +
                    'MerchantDevelopmentEnvironment=SalesForce';
        System.debug('strPostxml is ' +strPostXml);
        //System.debug('packet ' + EncodingUtil.urlEncode(strXml, 'UTF-8'));
        //Log(strWhere, 'strXml', strXml);
        //Log(strWhere, 'strPostXml', strPostXml);
        //Log(strWhere, 'strSignature', strSignature);
       
        hDoc = executeHttpRequest(strURL, strPostXml, 'POST');
        hRoot = hDoc.getRootElement();
        if(hRoot != null)
        {
            hResponse = hRoot.getChildElement('ResponsePacket', null);
            if(hResponse != null)
            {
                hAT = hResponse.getChildElement('AccessToken', null);
                if(hAT != null)
                    strAT = hAT.getText();
            }
        }
        Log(strWhere, 'AccessToken', strAT);
        System.debug('Access Token is'+strAT);
       
        return strAT;
    }
   
    public String getXmlRequest()
    {
        String strWhere = 'getXmlRequest';
        //String strRedirect = getRequestUrl();
        String strRedirect = '';
        String xmlRequest = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
       

        //strRedirect = strRedirect.replace('XiIntercept3RQ', 'XiIntercept3RS');
        xmlRequest += '<PostPacketModel><RedirectUri>' + strRedirect + '</RedirectUri></PostPacketModel>';
       
        Log(strWhere, 'strRedirect', strRedirect);
        Log(strWhere, 'xmlRequest', xmlRequest);
       
        return xmlRequest;
    }
   
    /*public String getIFrameMerchantHTML()
    {
        /* code snippet to retrieve merchant xml into string */
        /*
            String strURL = '' + Site.getBaseUrl();
       
            if(strURL.length() == 0)
            {
                strURL = URL.getCurrentRequestUrl().toExternalForm().replace('XiIntercept3RQ', 'XiIntercept3RS');
            }
            else strURL += '/XiIntercept3RS';
           
           
           
            String xmlRequest = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
        */
   // }
   
    private void Log(String strWhere, String strName, String strValue)
    {
        System.debug(strWhere + '() - ' + strName + ' => ' + strValue);
    }

    private String getDigitalSignature(String strData)
    {
        String strWhere = 'getDigitalSignature';
        String strSignature = '';
       
        strSignature = EncodingUtil.base64Encode(Crypto.generateMac('hmacSHA256', Blob.valueOf(strData), Blob.valueOf(m_strPSK)));
        System.debug('strsignature is'+strsignature);
        Log(strWhere, 'strData', strData);
        Log(strWhere, 'strSignature', strSignature);
       
        return strSignature;
    }

    private Dom.Document getResponsePacket(String strAccessToken)
    {
        String strWhere = 'getResponsePacket';
        String strSignature = getDigitalSignature(strAccessToken);
        String strUrlParams = m_strURL + '/ResponsePacket';
        Dom.Document hDoc = null;
       
        strUrlParams += '?MerchantGUID=' + m_strGUID;
        strUrlParams += '&Signature=' + EncodingUtil.urlEncode(strSignature, 'UTF-8');
        strUrlParams += '&AccessToken=' + strAccessToken;
       
        Log(strWhere, 'strUrlParams', strUrlParams);
        hDoc = executeHttpRequest(strUrlParams, '', 'GET');
        Log(strWhere, 'hDoc.toXmlString()', hDoc.toXmlString());
       
        return hDoc;
    }
   
    private Dom.Document executeHttpRequest(String targetURL, String urlParameters, String requestType)
    {
        String strWhere = 'executeHttpRequest';
        Dom.Document hDoc = null;
        Http myHttp = new Http();
        HttpRequest httpRQ = new HttpRequest();
        HttpResponse httpRS = null;
       
        Log(strWhere, 'targetURL', targetURL);
        Log(strWhere, 'requestType', requestType);
        Log(strWhere, 'urlParameters', urlParameters);
       
        httpRQ.setEndpoint(targetURL);
        httpRQ.setMethod(requestType);
        if(requestType.equalsIgnoreCase('POST'))
        {
            httpRQ.setHeader('Content-Type', 'application/x-www-form-urlencoded');
            httpRQ.setHeader('Content-Length', String.valueOf(urlParameters.Length()));
            httpRQ.setHeader('Content-Language', 'en-US');
            httpRQ.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate');
            httpRQ.setHeader('Pragma', 'no-cache');
            httpRQ.setBody(urlParameters);
        }
       
        httpRS = myHttp.send(httpRQ);
        if(httpRS != null)
        {
            Log(strWhere, 'httpRS.getBody()', httpRS.getBody());
            hDoc = httpRS.getBodyDocument();
        }
        else
        {
            hDoc = new Dom.Document();
        }
       
        return hDoc;
    }
}
Any suggestions are welcome..
Thanks
Sricharan
 
Sunil MadanaSunil Madana
Hi Sricharan, i tried to fix your code but received the below response from server.
<AccessTokenResponsePacket xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RequestError>
    <StatusCode>103</StatusCode>
    <DT>2016-03-01T01:05:13.4778493</DT>
    <Message>Request Packet is Invalid</Message>
  </RequestError>
</AccessTokenResponsePacket>
I suspect the packet you are sending is not valid which is why your VF iframe is blank.
May i know the output you are trying to acheive to understand your problem.
Thanks, Sunil.
Sricharan Puligundla 11Sricharan Puligundla 11
Hi Sunil

Thanks for the reply.we have to create the static resource and put the below xml in the static resource.
Name of the Static Resource : paymetricsCSS
MIME Type : text/xml

<?xml version="1.0" encoding="UTF-8"?>
<merchantHtmlPacketModel xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="Paymetric:XiIntercept:MerchantHtmlPacketModel">
  <iFramePacket>
    <hostUri>https://cynosure--slqa.cs19.my.salesforce.com/</hostUri>
    <cssUri>https://qaapp02.xisecurenet.com/diecomm/Content/IFrameStyleSheet.css</cssUri>
  </iFramePacket>
  <merchantHtml>
    <htmlSection class="merchant_paycontent">
        <cardDropdownSection>
        <tag name='div' class='PaymentDetailHeader'>Enter your credit card information</tag>
        <tag name="div">
          <label for="cardType" text="card type"/>
          <ddlCardType id="cd">
            <items>
              <item for="american express"/>
              <item for="mastercard"/>
              <item for="visa"/>
              <item for="maestro"/>
            </items>
          </ddlCardType>
        </tag>
        <tag name='div'>
          <label for='cardNumber' text='card number'/>
          <tboxCardNumber tokenize='true'/>
          <validationMsg for='cardNumber' class='valmsg'/>
        </tag>
        <tag name='div'>
          <label for='startMonth' text='start date'/>
          <ddlStartMonth default-text="month" display-format="MMM" class='merchant_combos' required='false'/>
          <ddlStartYear default-text="year" class='merchant_combos' years-to-display='10' required='false' start-date='true'/>
          <validationMsg for='startYear' class='valmsg'/>
        </tag>
        <tag name='div'>
          <label for='expMonth' text='exp date'/>
          <ddlExpMonth default-text="month" class='merchant_combos' required='false'/>
          <ddlExpYear default-text="year" class='merchant_combos' years-to-display='10' required='false' exp-date='true'/>
          <validationMsg for='expYear' class='valmsg'/>
        </tag>
      </cardDropdownSection>
    </htmlSection>
  </merchantHtml>
</merchantHtmlPacketModel>
 
I am getting valid response back.But still page is blank

<AccessTokenResponsePacket xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ResponsePacket>
    <MerchantGuid>8842aa98-d6d1-40a4-9ee0-c02a3393b7af</MerchantGuid>
    <AccessToken>4a14406c-37e6-42cf-a468-46734115ded2</AccessToken>
    <Signature>aU9pGL3mGMzPHJv8pL0b3nw9yWXo5J8faiNesax5vPU=</Signature>
  </ResponsePacket>

we are trying to get iframe URL from controller and open the iframe URL from visualforce page.we are trying to integrate salesforce with credit card processing system.

Thanks
Sricharan
Dave AlvaroDave Alvaro
hi Sricharan,
were you ever able to figure out what the problem was?  I am also working on a paymetric iframe solution, so far no luck in getting the authorization token back.  Thanks!
Dave
Michael PaisnerMichael Paisner
Anyone ever able to solve this one?  I am also getting a blank page in my iFrame.
Mike
Dave AlvaroDave Alvaro
@Michael Paisner  I was able to successfully get xiintercept up and running inpur org.  message me and I can help you out.
Riley SpillerRiley Spiller
@dave Would you be able to post your solution? I'm experience the same issue.
Dave AlvaroDave Alvaro
@Riley Spiller shoot me an email to dalvaro@nextgen.com and I'll send you what I got.
Yeshas KonduruYeshas Konduru
@Dave Alvaro Can you please help me with the solution. I have already emailed you.
Yeshas KonduruYeshas Konduru
Can anyone help me with the same issue please??..Trying to load Iframe from Visualforce page for the same Paymetric Credit Card Integration.