I have created code for my functions.php in wordpress but i seem to be getting undefined $
errors in some parts of my code. Here is the image of what happens when i click process payment
here is my code:
function paypalpayment() {
global $wpdb;
$user = wp_get_current_user();
$user_ID = $user->ID;
$shortcode = $wpdb->get_row("SELECT MAX(ap.pending) AS pending, ap.book_datetime, ap.id, ap.hash FROM ea_appointments AS ap "
."INNER JOIN ea_users AS us ON ap.id_users_customer = us.id "
."WHERE us.wp_id ='".$user_ID."'");
$html = '';
if ($shortcode->pending == ''){
$html .= '<h1>Processing Error: Appointment has been deleted. </h1>';
$html .= '<p align="center"><a class="fep-button" style="width: 195px; text-align: center;" href="http://lectiotutoring.co.za/EasyBlue" /> Schedule an appointment</a></p>';
} else {
$html .= '<h2>Fee Policy</h2>';
$html .= '<p>You may reschedule an appointment without charge within 24 hours of your appointment. Cancelation of an appointment within 24 hours can either result in a refund or a credit for your next appointment per your request. You will need to inform Mr. Tucker on the discussion board about how you would like your cancelation to be handled. If you would like a refund, refunds will be the full amount of the cost of your session minus the PayPal processing fees. There are no refunds for cancelations later than 24 hours in advance. <span class="bigger"><b>If payment is not completed within 10 minutes the appointment will be deleted.</b></span></p>';
date_default_timezone_set('America/Los_Angeles');
$refreshtime = strtotime($shortcode->book_datetime) - strtotime("-10 minutes");
$html .= '<meta http-equiv="refresh" content="';
$html .= $refreshtime;
$html .= '">';
if(strtotime($shortcode->book_datetime) > (strtotime("-10 minutes"))){
$html .= '<style>
</style>';
$html .= '<input type="button" id="stepone" onclick="processpaypal()" value="Process Payment">';
$html .= '<div id="spinner" class="loader" style="display:none"></div>';
$html .= do_shortcode($shortcode->pending);
$html .= '<input type="button" onclick="deletapt()" value="Delete Apt.">';
$html .= '<script>
cancelurl = "http://lectiotutoring.co.za/EasyBlue/index.php/appointments/cancel/' . $shortcode->hash . '";
function deletapt(){
window.location = cancelurl;
}
$(document).ready(function() {
$("input[name=return]").val("http://lectiotutoring.co.za/payment-success/");
$("input[name=cancel_return]").val(cancelurl);
});
function processpaypal(){
$("#spinner").css("display","block");
$("#stepone").css("display","none");
setTimeout(
function()
{
$(".wpi_checkout_submit_btn").click();
}, 250);
}
</script>';
}else{
$html .= '<h4 style="text-align: center;">Time has expired</h4>';
$html .= '<p align="center"><a class="fep-button" style="width: 195px; text-align: center;" href="http://lectiotutoring.co.za/EasyBlue" /> Schedule an appointment</a></p>';
}
}
return $html;
}
add_shortcode("paypalpay", "paypalpayment");
//PayPal Callback function that replaces the cryptic suffix with actual service names in patients the WP-Invoice file.
function ea_paypalcallback($transaction_data){
global $wpdb;
//Grab Service Name and Date
$session_id = $transaction_data[post_data][created_by][0];
$posturl = $transaction_data[post_data][guid][0];
$urlArray = explode('=',$posturl);
$postid = $urlArray[sizeof($urlArray)-1];
$dummyname = $transaction_data[items][1][name];
$query = "SELECT concat(eas.name, ' ', DATE_FORMAT(eaa.start_datetime, '%m/%d/%Y') ) FROM ea_services AS eas " .
"LEFT JOIN ea_appointments AS eaa ON eaa.id_services = eas.id WHERE eaa.pending LIKE '%" . $session_id . "%'";
$servicename = $wpdb->get_var($query);
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}posts SET post_content = REPLACE(post_content, 'Items: $dummyname', '$dummyname: $servicename') WHERE ID = $postid"));
$wpdb->query($wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = REPLACE(meta_value, '$session_id', '') WHERE meta_key = 'post_title' AND post_id = $postid"));
sleep(5);
$wpdb->query($wpdb->prepare("UPDATE ea_appointments SET pending = '' WHERE pending LIKE '%$session_id%'"));
}
UPDATE THe lines of code which i get the error in is here:
$(document).ready(function() {
$("input[name=return]").val("http://lectiotutoring.co.za/payment-success/");
$("input[name=cancel_return]").val(cancelurl);
});
function processpaypal(){
$("#spinner").css("display","block");
$("#stepone").css("display","none");
'<input type="button" id="stepone" onclick="processpaypal()" value="Process Payment">';