Reputation: 371
I am experiencing some really annoying issues with the PayPal Adaptive Payments API. I am trying to embed payments in a lightboxed iframe, I have implemented everything as instructions say. When I go to pay, and click on the button, the lightboxed iframe opens and I execute the payment without problems. However, if I cancel the payment or go through it and get the paymentSuccess called, the checkout page is loaded inside the iframe, which does not get closed. The paymentCanceled is not called at all, since the pino that should be alerted is not shown.
I am showing some code to you, but the fact is that it is taken from a Wordpress plugin that is not yet working and I can not therefore show you a "working version" of the page. Anyway, if you needed some more details, just ask and I will try to make them available.
The PayPal javascript
<script type="text/javascript" charset="utf-8">
var dgFlow = new PAYPAL.apps.DGFlow({trigger: 'post_pay_counter_paypal_execute_payment'});
function MyEmbeddedFlow(embeddedFlow) {
this.embeddedPPObj = embeddedFlow;
this.paymentSuccess = function () {
this.embeddedPPObj.closeFlow();
// handle payment success here
top.close();
};
this.paymentCanceled = function () {
alert('pippo');
this.embeddedPPObj.closeFlow();
// handle payment cancellation here
top.close();
}
}
var myEmbeddedPaymentFlow = new MyEmbeddedFlow(dgFlow);
</script>
Thank you all!
Upvotes: 3
Views: 2524
Reputation: 371
I got my problem solved. Here's the code:
jQuery(document).ready(function($) {
//Manage the closing of the iframe when payment is executed/canceled
if (window != top) {
top.location.replace(document.location);
}
}
//Initialize PayPal embedded payment flow. Now loading it on document ready so that we only have it if user prepares payment, not just loads the page...
var dgFlow = new PAYPAL.apps.DGFlow({trigger: 'post_pay_counter_paypal_execute_payment'});
Upvotes: 4