我遇到了PayPal Adaptive Payments API的一些非常烦人的问题。我试图在一个lightboxed iframe中嵌入付款,我按照说明说明实现了所有内容。当我去付款并点击按钮时,灯箱的iframe会打开,我会毫无问题地执行付款。但是,如果我取消付款或通过它并调用paymentSuccess,则会在iframe中加载结帐页面,该页面不会被关闭。根本没有调用paymentCanceled,因为不会显示应该被警告的 pino 。
我正在向您展示一些代码,但事实是它是从一个尚未运行的Wordpress插件中获取的,因此我无法向您展示该页面的“工作版本”。无论如何,如果您需要更多细节,请询问,我会尽力使它们可用。
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>
谢谢大家!
答案 0 :(得分:4)
我的问题解决了。这是代码:
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'});