我在我的网站上使用自适应付款,我可以点击购买该项目并完成交易工作正常。但在购买该商品或点击取消后,它不会重定向回我的网站。
我试着效仿这个例子: Adaptive Payments without modal box or popups?
但仍然无法正常工作
这是我目前使用的Javascript:
$( document ).ready(function() {
$("form").submit(function (e) {
var className = $('form').attr('class');
var formname = this.name;
//alert(formname);
if(formname=="paypalform"){
//alert("testing");
var login = 'elgg-search elgg-search-header';
if(login) {
e.preventDefault();
//var agree = confirm('You are just about to ask the Post Pay Counter to prepare a PayPal payment on your behalf. Note that this will really take money from your account and into the selected writers ones\’. Please double check what you are doing, it is only your fault if something goes wrong.\n\nIf what you have done is fine, then you can go on with the payment. Just be patient during loading, please. In a couple of seconds the execute payment button will be clickable and you will be able to confirm this action. From this moment on you can not modify the payment selection, but if you reload the page before clicking the execute payment button, nothing will be done.');
//if (!agree)
// return false;
var className = $('form').attr('class');
//alert(className);
var data = {
action: 'the_php_page_that_will_handle_the_request.php',
payment_data: $(this).serialize()
};
$('#prepare_payment').attr("disabled", "true");
$("#prepare_payment_form :text").each(function() {
$(this).attr("disabled", "true");
});
var url_to_submit = $('#url_submit').text();
$.post(url_to_submit, data, function(response) {
if(response.indexOf("Error: ") != -1) {
$("#paypal_error").css("display", "block");
$("#paypal_error").html(response);
$('#prepare_payment').removeAttr("disabled");
jQuery("#prepare_payment_form :text").each(function() {
jQuery(this).removeAttr("disabled");
});
return false;
}
// enable for testing mode, to display pay key on ad view
//$('#txtHint').html( response );
//$('#txtHint').html( 'Redirecting to PayPal' );
//Store PayKey in the form action and enable execute payment button
$("#execute_payment_form").attr("action", "https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + response+"&expType=mini");
//document.getElementById('iframeid').src = url;
$('#execute_payment').removeAttr("disabled");
var url = "https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + response+"&expType=mini";
$(location).attr('href',url);
//document.getElementById('iframeid').src = url;
});
}
}
});
});