function jr_update_listing_after_payment($posted) { global $jr_log; $jr_log->write_log('Valid IPN response detected: ' . print_r($posted, true)); // Custom holds post ID if (!empty($posted['txn_type']) && !empty($posted['custom']) && is_numeric($posted['custom']) && $posted['custom'] > 0) { $accepted_types = array('cart', 'express_checkout', 'web_accept'); // Check transation is what we want if (!in_array(strtolower($posted['txn_type']), $accepted_types)) { exit; } $jr_order = new jr_order($posted['custom']); if ($jr_order->order_key !== $posted['item_number']) { exit; } if ($posted['test_ipn'] == 1 && $posted['payment_status'] == 'Pending') { $posted['payment_status'] = 'completed'; } // We are here so lets check status and do actions switch (strtolower($posted['payment_status'])) { case 'completed': // Payment was made so we can approve the job $jr_order->complete_order('IPN'); $payment_data = array(); $payment_data['payment_date'] = date("Y-m-d H:i:s"); $payment_data['payer_first_name'] = stripslashes(trim($_POST['first_name'])); $payment_data['payer_last_name'] = stripslashes(trim($_POST['last_name'])); $payment_data['payer_email'] = stripslashes(trim($_POST['payer_email'])); $payment_data['payment_type'] = 'PayPal'; $payment_data['approval_method'] = 'IPN'; $payment_data['payer_address'] = stripslashes(trim($_POST['residence_country'])); $payment_data['transaction_id'] = stripslashes(trim($_POST['txn_id'])); $jr_order->add_payment($payment_data); $jr_log->write_log('IPN Transaction Completed for Order #' . $posted['custom']); break; case 'denied': case 'expired': case 'failed': case 'voided': // In these cases the payment failed so we can trash the job $jr_order->cancel_order(); $jr_log->write_log('IPN Transaction Failed for Order #' . $posted['custom']); break; default: // Default if action not recognised $jr_log->write_log('IPN Transaction default action. Nothing done. Order #' . $posted['custom']); break; } } }
// jr_before_gateway_process($_POST['custom']); // do_action hook $jr_order = new jr_order($_POST['custom']); if ($jr_order->order_key == $_POST['item_number'] || $_POST['test_ipn'] == '1') { $newjobid = $jr_order->job_id; $jr_order->complete_order(__('Return URL', 'appthemes')); $jr_log->write_log('Publishing job submission (#' . $jr_order->job_id . ') via tpl-add-new-confirm.php'); $payment_data = array(); $payment_data['payment_date'] = date("Y-m-d H:i:s"); $payment_data['payer_first_name'] = stripslashes(trim($_POST['first_name'])); $payment_data['payer_last_name'] = stripslashes(trim($_POST['last_name'])); $payment_data['payer_email'] = stripslashes(trim($_POST['payer_email'])); $payment_data['payment_type'] = 'PayPal'; $payment_data['payer_address'] = stripslashes(trim($_POST['residence_country'])); $payment_data['transaction_id'] = stripslashes(trim($_POST['txn_id'])); $payment_data['approval_method'] = __('Return URL', 'appthemes'); $jr_order->add_payment($payment_data); // jr_after_gateway_process($newjobid); // do_action hook } } get_header(); ?> <div class="section"> <div class="section_content"> <?php // see if the job id is valid if ($newjobid) { ?>