Exemple #1
0
/**
 * AJAX Function renders payment form in [adverts_add] third step.
 * 
 * This function renders a proper payment form based on $_REQUEST['gateway'] value
 * and echos it to the browser as a JSON code.
 * 
 * @since 0.1
 * @return void 
 */
function adext_payments_ajax_render()
{
    $gateway_name = adverts_request('gateway');
    $gateway = adext_payment_gateway_get($gateway_name);
    $listing_id = adverts_request("listing_id");
    $response = null;
    $data = array();
    $data["page_id"] = adverts_request("page_id");
    $data["listing_id"] = adverts_request("listing_id");
    $data["object_id"] = adverts_request("object_id");
    $data["payment_for"] = "post";
    $data["gateway_name"] = $gateway_name;
    $data["bind"] = array();
    foreach (adverts_request('form', array()) as $item) {
        $data["bind"][$item["name"]] = $item["value"];
    }
    $form = new Adverts_Form();
    $form->load($gateway["form"]["payment_form"]);
    $form->bind($data["bind"]);
    if (isset($data["bind"]) && !empty($data["bind"])) {
        $isValid = $form->validate();
        if ($isValid) {
            $pricing = get_post($data["listing_id"]);
            $price = get_post_meta($listing_id, "adverts_price", true);
            $payment_data = array('post_title' => $form->get_value("adverts_person"), 'post_content' => '', 'post_status' => 'pending', 'post_type' => 'adverts-payment');
            $meta = array("pricing" => array("post_title" => $pricing->post_title, "visible" => get_post_meta($pricing->ID, "adverts_visible", true)));
            $payment_id = wp_insert_post($payment_data);
            update_post_meta($payment_id, 'adverts_person', $form->get_value('adverts_person'));
            update_post_meta($payment_id, 'adverts_email', $form->get_value('adverts_email'));
            update_post_meta($payment_id, '_adverts_user_ip', adverts_get_ip());
            update_post_meta($payment_id, '_adverts_user_id', wp_get_current_user()->ID);
            update_post_meta($payment_id, '_adverts_object_id', $data["object_id"]);
            update_post_meta($payment_id, '_adverts_pricing_id', $data["listing_id"]);
            update_post_meta($payment_id, '_adverts_payment_gateway', $data["gateway_name"]);
            update_post_meta($payment_id, '_adverts_payment_for', $data["payment_for"]);
            update_post_meta($payment_id, '_adverts_payment_paid', "0");
            update_post_meta($payment_id, '_adverts_payment_total', $price);
            update_post_meta($payment_id, '_adverts_payment_meta', $meta);
            $data["price"] = $price;
            $data["form"] = $form->get_values();
            $data["payment_id"] = $payment_id;
            $data = apply_filters("adverts_payments_order_create", $data);
            $response = call_user_func($gateway["callback"]["render"], $data);
        }
    }
    if ($response === null) {
        ob_start();
        include ADVERTS_PATH . 'templates/form.php';
        $html_form = ob_get_clean();
        $response = array("result" => 0, "html" => $html_form, "execute" => null);
    }
    echo json_encode($response);
    exit;
}
Exemple #2
0
_e('Total', 'adverts');
?>
</strong>
        </div>
        <div class="adverts-grid-col adverts-col-35">
            <strong><?php 
echo adverts_price($price);
?>
</strong>
        </div>
    </div>        
            
</div>

<?php 
$gateways = adext_payment_gateway_get();
if (empty($gateways)) {
    ?>
<div class="adverts-flash-error">
    <span><?php 
    _e("No Payment Gateways Enabled!", "adverts");
    ?>
</span>
</div>
<?php 
} else {
    ?>

<br/>

<ul class="adverts-tabs adverts-payment-data" data-page-id="<?php 
Exemple #3
0
/**
 * Renders Payments History List and Edit Page.
 * 
 * The page is rendered in wp-admin / Classifieds / Payments History panel
 * 
 * @global wpdb $wpdb
 * @global wp_locale $wp_locale
 * 
 * @since 0.1
 * @return void
 */
function adext_payments_page_history()
{
    global $wpdb, $wp_locale;
    wp_enqueue_style('adverts-admin');
    $flash = Adverts_Flash::instance();
    if (adverts_request("add")) {
        // Do nothing currently users cannot add pricing manually.
    } elseif (adverts_request("edit")) {
        // Display payment edit page.
        $payment = get_post(adverts_request("edit"));
        $form = new Adverts_Form();
        $form->load(Adverts::instance()->get("form_payments_history"));
        $form->bind(Adverts_Post::to_array($payment));
        $gateway_name = get_post_meta($payment->ID, '_adverts_payment_gateway', true);
        $gateway = adext_payment_gateway_get($gateway_name);
        if (!$gateway) {
            $msg = sprintf(__("Payment Method [%s] assigned to this Payment does not exist or was disabled.", "adverts"), $gateway_name);
            $flash->add_error($msg);
        }
        if (isset($_POST) && !empty($_POST)) {
            $form->bind(stripslashes_deep($_POST));
            $valid = $form->validate();
            if ($valid) {
                $status_new = $form->get_value("post_status");
                $status_old = $payment->post_status;
                $post_id = Adverts_Post::save($form, $payment);
                if (is_numeric($post_id) && $post_id > 0 && $status_old != $status_new) {
                    do_action("adverts_payment_" . $status_new, $payment);
                    $text = __('<strong>%1$s</strong> changed payment status to <strong>%2$s</strong>', 'adverts');
                    $message = sprintf($text, wp_get_current_user()->user_login, $status_new);
                    adext_payments_log($post_id, $message);
                    $payment = get_post($post_id);
                }
                if (is_wp_error($post_id)) {
                    $flash->add_error($post_id->get_error_message());
                } elseif ($post_id === 0) {
                    $flash->add_error(__("There was an error while saving pricing in database.", "adverts"));
                } else {
                    $flash->add_info(__("Payment updated.", "adverts"));
                }
            } else {
                $flash->add_error(__("There are errors in your form.", "adverts"));
            }
        }
        include ADVERTS_PATH . 'addons/payments/admin/payment-history-edit.php';
    } elseif (adverts_request('delete')) {
        // Delete Payment
        $post = get_post(adverts_request('delete'));
        $i = 0;
        if (!$post || $post->post_type != 'adverts-payment') {
            wp_die(__('Adverts Payment with given ID does not exist.', 'adverts'));
        }
        foreach (get_children($post) as $child) {
            wp_delete_attachment($child->ID, true);
            $i++;
        }
        $flash->add_info(sprintf(_n("1 Payment deleted.", "%s Payments deleted.", $i, "adverts"), $i));
        wp_delete_post($post->ID, true);
        wp_redirect(remove_query_arg(array('delete', 'noheader', 'pg')));
        exit;
    } elseif (adverts_request('filter_action')) {
        // Apply filters and return to payments history list
        $url = remove_query_arg(array('delete', 'noheader', 'pg'));
        $url = add_query_arg(array('month' => adverts_request('month')), $url);
        wp_redirect($url);
        exit;
    } elseif (adverts_request('action') || adverts_request('action2')) {
        // Apply bulk actions and return to payments history list
        $action = adverts_request('action');
        if (empty($action)) {
            $action = adverts_request('action2');
        }
        $item = adverts_request('item');
        foreach ($item as $id) {
            if ($action == "delete") {
                foreach (get_children($id) as $child) {
                    wp_delete_attachment($child->ID, true);
                }
                wp_delete_post($id, true);
                $flash->add_info(__("Payments deleted.", "adverts"));
            } elseif (stripos($action, "set-status-") === 0) {
                $status_old = get_post_status($id);
                $status_new = str_replace("set-status-", "", $action);
                $status_obj = get_post_status_object($status_new);
                if ($status_old != $status_new) {
                    wp_update_post(array("ID" => $id, "post_status" => $status_new));
                    do_action("adverts_payment_" . $status_new, $payment);
                }
                $flash->add_info(sprintf(__("Status for selected Payments was changed to: %s"), $status_obj->label));
            }
        }
        wp_redirect(remove_query_arg(array('delete', 'noheader', 'pg')));
        exit;
    } else {
        // Display Payments History
        $status_list = array("pending" => 0, "completed" => 0, "failed" => 0, "refunded" => 0);
        foreach ($status_list as $k => $v) {
            $sql = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = %s AND post_type = 'adverts-payment'";
            $status_list[$k] = (int) $wpdb->get_var($wpdb->prepare($sql, $k));
        }
        $sql = "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM {$wpdb->posts} WHERE post_type = %s ORDER BY post_date DESC";
        $months_list = $wpdb->get_results($wpdb->prepare($sql, 'adverts-payment'));
        $months = array();
        foreach ($months_list as $m) {
            $months[] = array("value" => $m->year . "-" . $m->month, "label" => sprintf(__('%1$s %2$d'), $wp_locale->get_month($m->month), $m->year));
        }
        $month = adverts_request("month", "");
        $filter = adverts_request("status", "");
        $loop_params = array('post_type' => 'adverts-payment', 'posts_per_page' => 20, 'paged' => adverts_request('pg', 1));
        if ($filter) {
            $loop_params['post_status'] = $filter;
        }
        if ($month == "this-month") {
            $before = date('Y-m-d H:i:s', strtotime('last day of this month', current_time('timestamp')));
            $after = date('Y-m-d H:i:s', strtotime('first day of this month', current_time('timestamp')));
            $loop_params['date_query'] = array(array('before' => $before, 'after' => $after, 'inclusive' => true));
        } elseif ($month == "last-month") {
            $before = date('Y-m-d H:i:s', strtotime('last day of last month', current_time('timestamp')));
            $after = date('Y-m-d H:i:s', strtotime('first day of last month', current_time('timestamp')));
            $loop_params['date_query'] = array(array('before' => $before, 'after' => $after, 'inclusive' => true));
        } elseif (!empty($month)) {
            $time = strtotime($month . "-10");
            $before = date('Y-m-d', strtotime('last day of this month', $time));
            $after = date('Y-m-d H:i:s', strtotime('first day of this month', $time));
            $loop_params['date_query'] = array(array('before' => '', 'after' => '', 'inclusive' => true));
        }
        $loop = new WP_Query($loop_params);
        include ADVERTS_PATH . 'addons/payments/admin/payment-history-list.php';
    }
}
Exemple #4
0
/**
 * Switch shortcode_adverts_add action to $gateway_name
 * 
 * Function checks if adverts-notify-id param is sent via GET or POST if so
 * then the function will try to get payment gateway for this payment object and
 * switch action to gateway_name.
 * 
 * In other words the function will trigger "adverts_action_$gateway_name" filter 
 * execution.
 * 
 * @see shortcode_adverts_add()
 * @since 1.0
 * 
 * @param string $action
 * @return string
 */
function adext_payments_add_action_notify($action)
{
    if ($action != "" || !adverts_request("adverts-notify-id")) {
        return $action;
    }
    $payment = get_post(adverts_request("adverts-notify-id"));
    if (!$payment) {
        return $action;
    }
    $gateway_name = get_post_meta($payment->ID, "_adverts_payment_gateway", true);
    $gateway = adext_payment_gateway_get($gateway_name);
    return $gateway_name;
}