I am using adaptive payments on my site, I can click buy on the item and complete the transaction which works fine. But after buying the item or clicking on cancel it doesnt redirect back to My site.
I tried to follow this example: Adaptive Payments without modal box or popups?
But still cant get it working
Here is my current Javascript that im using:
$( 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;
});
}
}
});
});