Exemplo n.º 1
0
function leyka_currency_choice_action()
{
    check_ajax_referer('leyka_payment_form', '_leyka_ajax_nonce');
    if (empty($_POST['currency'])) {
        die('-1');
    }
    $curr_currency = trim($_POST['currency']);
    $pm_selected = trim($_POST['current_pm']);
    $currently_active_pmethods = leyka_get_pm_list(true, $curr_currency);
    $curr_pm_is_active = false;
    foreach ($currently_active_pmethods as $pm) {
        if ($pm->id == $pm_selected) {
            $curr_pm_is_active = true;
            $pm_selected = $pm;
            break;
        }
    }
    if (!$curr_pm_is_active) {
        $pm_selected = reset($currently_active_pmethods);
    }
    leyka_setup_current_pm($pm_selected, $curr_currency);
    echo leyka_pf_get_hidden_fields((int) $_POST['campaign']);
    ?>

    <!-- pm selector -->
    <div id="pm-selector" class="form-part">
        <ul class="leyka-pm-selector">
            <?php 
    foreach ($currently_active_pmethods as $pm) {
        ?>
                <li>
                    <label class="radio">
                        <input type="radio" name="leyka_payment_method" value="<?php 
        echo esc_attr($pm->full_id);
        ?>
" <?php 
        checked($pm_selected->id, $pm->id);
        ?>
 data-pm_id="<?php 
        echo esc_attr($pm->id);
        ?>
">
                        <?php 
        echo $pm->label;
        ?>
                    </label>
                </li>
            <?php 
    }
    ?>
        </ul>
    </div>

    <!-- changeable area -->
    <div id="leyka-pm-data" class="changeable-fields form-part">

        <div class="leyka-pm-fields">

            <div class='leyka-user-data'>
                <!-- field for GA -->
                <input type="hidden" name="leyka_ga_payment_method" value="<?php 
    echo esc_attr($curr_pm->label);
    ?>
" />
                <?php 
    echo leyka_pf_get_name_field();
    echo leyka_pf_get_email_field();
    echo leyka_pf_get_pm_fields();
    ?>
            </div>

            <?php 
    echo leyka_pf_get_agree_field();
    echo leyka_pf_get_submit_field();
    $icons = leyka_pf_get_pm_icons();
    if ($icons) {
        $list = array();
        foreach ($icons as $i) {
            $list[] = "<li>{$i}</li>";
        }
        echo "<ul class='leyka-pm-icons cf'>";
        echo implode('', $list);
        echo "</ul>";
    }
    ?>
        </div>
        <?php 
    echo "<div class='leyka-pm-desc'>" . apply_filters('leyka_the_content', leyka_pf_get_pm_description()) . "</div>";
    ?>

    </div>
    <?php 
    die;
}
function get_leyka_payment_form_template_html($campaign = null, $template = null)
{
    global $post;
    ob_start();
    if (!$campaign) {
        $campaign = new Leyka_Campaign($post);
    } elseif (is_int($campaign) || is_a($campaign, 'WP_Post')) {
        $campaign = new Leyka_Campaign($campaign);
    } elseif (!is_a($campaign, 'Leyka_Campaign')) {
        return false;
    }
    if ($campaign->is_finished) {
        ?>


    <div id="leyka-campaign-finished"><?php 
        echo __('The fundraising campaign has been finished. Thank you for your support!', 'leyka');
        ?>
</div>

<?php 
    } else {
        $pm_list = leyka_get_pm_list(true);
        $curr_pm = $pm_list ? leyka_get_pm_by_id(reset($pm_list)->full_id, true) : false;
        if (!$curr_pm) {
            ?>


        <div class="<?php 
            echo apply_filters('leyka_no_pm_error_classes', 'leyka-nopm-error');
            ?>
">
            <?php 
            echo is_user_logged_in() ? str_replace('%s', admin_url('admin.php?page=leyka_settings&stage=payment#leyka_pm_available-wrapper'), __('There are no payment methods selected to donate! Please, <a href="%s">set them up</a>.', 'leyka')) : __('Dear donor, we are very sorry, but we had not setted up the donations module yet :( Please try to donate later.', 'leyka');
            ?>

        </div>

        <?php 
        } else {
            $template = leyka_get_current_template_data($campaign, $template);
            if ($template && isset($template['file'])) {
                include $template['file'];
            }
        }
    }
    // Campaign finished
    $out = ob_get_contents();
    ob_end_clean();
    return $out;
}
Exemplo n.º 3
0
function leyka_min_payment_settings_complete()
{
    $pm_list = leyka_get_pm_list(true);
    if (!$pm_list) {
        return false;
    }
    $gateway_options_valid = array();
    // Array of already validated gateways
    foreach (leyka_options()->opt('pm_available') as $pm_full_id) {
        // Full ID is "gateway_id-pm_id"
        $pm = leyka_get_pm_by_id($pm_full_id, true);
        $pm_full_id = explode('-', $pm_full_id);
        $gateway = leyka_get_gateway_by_id(reset($pm_full_id));
        if (!$pm || !$gateway) {
            return false;
        }
        foreach ($pm->get_pm_options_names() as $option_name) {
            if (!leyka_options()->is_valid($option_name)) {
                return false;
            }
        }
        if (empty($gateway_options_valid[$gateway->id])) {
            foreach ($gateway->get_options_names() as $option_name) {
                if (!leyka_options()->is_valid($option_name)) {
                    return false;
                }
            }
            $gateway_options_valid[$gateway->id] = true;
        }
    }
    return true;
}
Exemplo n.º 4
0
<?php

/**
 * Copy paste whole payment form template - to alter class in favour if MDL
 * be careful on updates
 **/
if (!defined('LEYKA_VERSION')) {
    return;
}
global $leyka_current_pm;
$active_pm = apply_filters('leyka_form_pm_order', leyka_get_pm_list(true));
$agree_link = home_url();
leyka_pf_submission_errors();
?>

<div id="leyka-payment-form" class="leyka-custom-template" data-template="toggles">
<?php 
$counter = 0;
foreach ($active_pm as $i => $pm) {
    leyka_setup_current_pm($pm);
    $counter++;
    ?>
<div class="leyka-payment-option toggle <?php 
    if ($counter == 1) {
        echo 'toggled';
    }
    ?>
 <?php 
    echo esc_attr($pm->full_id);
    ?>
">
function leyka_is_min_payment_settings_complete()
{
    $pm_list = leyka_get_pm_list(true);
    if (!$pm_list) {
        return false;
    }
    $gateway_options_valid = array();
    // Array of already validated gateways
    foreach ($pm_list as $pm) {
        /** @var $pm Leyka_Payment_Method */
        $gateway = leyka_get_gateway_by_id($pm->gateway_id);
        if (!$pm || !$gateway) {
            continue;
        }
        $min_settings_complete = true;
        foreach ($pm->get_pm_options_names() as $option_name) {
            if (!leyka_options()->is_valid($option_name)) {
                $min_settings_complete = false;
                break;
            }
        }
        if (!isset($gateway_options_valid[$gateway->id])) {
            foreach ($gateway->get_options_names() as $option_name) {
                if (!leyka_options()->is_valid($option_name)) {
                    $gateway_options_valid[$gateway->id] = false;
                    break;
                }
            }
            if (!isset($gateway_options_valid[$gateway->id])) {
                $gateway_options_valid[$gateway->id] = true;
            }
        }
        if ($min_settings_complete && !empty($gateway_options_valid[$gateway->id])) {
            return true;
        }
    }
    return false;
}