3 Replies Latest reply on Jun 15, 2010 5:29 AM by dtcullen

    Javascript Callback Failure in PayPal Integration


      I have implemented the PayPal integration into a Flash Builder app but am experiencing a strange problem where the callback from Javascript has stopped working and I am trying to figure out why.  I am using the ExternalInterface class to register the callback but the javascript doesn't seem to respond to the call.   It is registered as follows;




      and the php file that should call back is;




      <title>PayPal PHP API Response</title>

      <script type="text/javascript">

      function doCancel() {







      Payment Has been Canceled

      <a href="javascript:doCancel()">Return to Flex</a>




      The application is called PhotoWebsite.  I have downloaded the original examples from Miti Pricope at http://www.adobe.com/devnet/flex/articles/flex_paypal.html and it works fine.  I'm not big on javascript.  Any clues.  It is as almost as if the app is called something else behind the scenes and the php / javascript is not recognizing it.


      Any help would be greatly appreciated.

        • 1. Re: Javascript Callback Failure in PayPal Integration
          jsd99 Level 3

          Does the embedding page have allowScriptAccess set to always or sameDomain?  Is the swf running in the same sandbox as the rest of the page?

          1 person found this helpful
          • 2. Re: Javascript Callback Failure in PayPal Integration
            dtcullen Level 1

            Thanks for that.  I wasn't aware of the allowScriptAccess option so I have now set that to 'always' in my index.template.html.  When I did that it worked first time and then never again even though I did all the normal stuff like clear cache, reset Safari, reboot etc.  I have now added a try, catch to the javascript code to see what the problem is and I get;


            Error: Result of expression 'window.opener' [null] is not an object.


            ... so I'm trying to find out what options this window.opener thing supports (no js experience).


            Thanks for your help!

            • 3. Re: Javascript Callback Failure in PayPal Integration
              dtcullen Level 1

              Okay I have now found what is causing this problem;


              I am testing the integration to PayPal using Flash Builder which uses the well known call to PHP using the URLRequest class.  At the end of the PayPal process (whether it be success, cancel or error) there is a javascript callback into the Flash Builder app.  This was working and stopped for no apparent reason. 


              Having traced back all of my mods since the app 'broke' I discovered that I added a php service call to update some shopping basket details just before I use the URL request to initiate the PayPal process.  The net effect of this is that the javascript call that uses window.opener.window.documentgetElementById to callback into the Flash Builder app is seeing window.opener as 'undefined' basically a null pointer.  For completeness I am including the call sequence which shows the call to PayPal being triggered by the ResultEvent of the CallResponder.


              protected function btnPaypal_clickHandler(event:MouseEvent):void {


              var basket:Basket = new Basket();

              basket.del_name = txtDeliveryName.text;

              basket.del_add1 = txtDeliveryAdd1.text;

              basket.del_add2 = txtDeliveryAdd2.text;

              basket.del_add3 = txtDeliveryAdd3.text;

              basket.del_add4 = txtDeliveryAdd4.text;

              basket.del_add5 = cmbCountry.selectedItem.name;

                  basket.email = txtDeliveryEmail.text;

              basket.id = basketID;

              basket.country_iso = cmbCountry.selectedItem.iso;

              //updateContactResult.addEventListener(ResultEvent.RESULT, callPayPal);

              updateContactResult.token = basketService.updateContact(basket);




              protected function callPayPal(evt:ResultEvent):void {


              ExternalInterface.call('window.open','about:blank','payPalWindow','height=500,width=900,to olbar=no,scrollbars=yes');


              var url:URLRequest = new URLRequest(URL_ROOT + "photoweb/services/startPaymentFlex.php");

              url.data = new URLVariables();

              var obj:URLVariables = new URLVariables();

              url.data.paymentAmount = total.toString();

              url.data.currencyCodeType = "EUR";

              url.data.paymentType = "Sale";

              url.data.basket_id = basketID;

              url.data.del_name = txtDeliveryName.text;

              url.data.del_add1 = txtDeliveryAdd1.text;

              url.data.del_add2 = txtDeliveryAdd2.text;

              url.data.del_add3 = txtDeliveryAdd3.text;

              url.data.del_add4 = txtDeliveryAdd4.text;

              url.data.del_add5 = cmbCountry.selectedItem.iso;

              url.data.email = txtDeliveryEmail.text;

              url.method = "GET";

              navigateToURL(url, "payPalWindow");




              I have now moved the php service call to the point in the app where the PayPal transaction has been accepted and so far it seems to work okay.  I'm suspicious that this may be a bug and this is the second call in the app using the Callresponder in question.  Should I reuse the same Callresponder for multiple calls and why should a php service call mess up the browser environment?