Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded Payment return url shown in iframe

I'm trying to implement adaptive payments as embedded payment with lightbox.

It works fine until a user makes a payment, but after user completes the payment page specified by return url gets loaded within the iframe. I'm expecting it to be loaded in the window NOT in the iframe. Following is the code that I have. Am I missing something?

Environment
Java(play framework)
PayPal_Platform_Java_SDK_N

Expected Page Transfer Scenario
PageA - ("pay with paypal" button click)
→ paypal dialog - ("close" button click)
→ PageB

PageA.html

<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame">
  <dl>
    <dt></dt>
    <dd>
      <input id="type" type="hidden" name="expType" value="light">
      <input id="paykey" type="hidden" name="paykey" value="AP-KEY">
      <input type="submit" id="paypalSubmitBtn" value="Pay with paypal" />
    </dd>
  </dl>
</form>
<script type="text/javascript"> 
  var dgFlow;
  $(function(){
    dgFlow = new PAYPAL.apps.DGFlow({ trigger: 'paypalSubmitBtn' });
  }); 
</script>

PageB.html

<p>Thank you for your payment!</p>

<script type="text/javascript">
  function handleEmbeddedFlow() {
    if (top && top.opener && top.opener.top) {
      top.opener.top.dgFlow.closeFlow();
    }
    else{
      top.dgFlow.closeFlow();
    }
    top.close();
  }

  jQuery.event.add(window, "load", function(){
    alert("window.load");
    handleEmbeddedFlow();
  });
</script>

I also noticed that dgFlow can not be resolved in else case's top.dgFlow.closeFlow(); in PageB.html.

like image 570
TAT Avatar asked Nov 05 '22 06:11

TAT


1 Answers

You can try to detect if the page is running in an iframe, and if so redirect to the page directly.

How to detect: How to identify if a webpage is being loaded inside an iframe or directly into the browser window?

How to redirect: Redirect the parent page from IFrame

like image 53
Sire Avatar answered Nov 16 '22 12:11

Sire