Beispiel #1
0
 /**
  * Redirect to payment page or add free subscription after user registration
  *
  * @since 2.2
  *
  * @param  int $user_id
  * @return void
  */
 function after_registration($user_id)
 {
     if (!isset($_POST['wpuf_sub']) || $_POST['wpuf_sub'] != 'yes') {
         return $user_id;
     }
     if (!isset($_POST['pack_id']) || empty($_POST['pack_id'])) {
         return $user_id;
     }
     $pack_id = isset($_POST['pack_id']) ? intval($_POST['pack_id']) : 0;
     $pack = $this->get_subscription($pack_id);
     $billing_amount = $pack->meta_value['billing_amount'] >= 0 && !empty($pack->meta_value['billing_amount']) ? $pack->meta_value['billing_amount'] : false;
     if ($billing_amount === false) {
         $this->new_subscription($user_id, $pack_id, null, false, 'free');
         WPUF_Subscription::add_used_free_pack($user_id, $pack_id);
     } else {
         $pay_page = intval(wpuf_get_option('payment_page', 'wpuf_payment'));
         $redirect = add_query_arg(array('action' => 'wpuf_pay', 'type' => 'pack', 'pack_id' => (int) $pack_id), get_permalink($pay_page));
     }
 }
Beispiel #2
0
    /**
     * Show the payment page
     *
     * @param  string $content
     * @return string
     */
    function payment_page($content)
    {
        global $post;
        $pay_page = intval(wpuf_get_option('payment_page', 'wpuf_payment'));
        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'wpuf_pay' && $pay_page == 0) {
            _e('Please select your payment page from admin panel', 'wpuf');
            return;
        }
        if ($post->ID == $pay_page && isset($_REQUEST['action']) && $_REQUEST['action'] == 'wpuf_pay') {
            if (!is_user_logged_in()) {
                //return __( 'You are not logged in', 'wpuf' );
            }
            $type = $_REQUEST['type'] == 'post' ? 'post' : 'pack';
            $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
            $pack_id = isset($_REQUEST['pack_id']) ? intval($_REQUEST['pack_id']) : 0;
            $is_free = false;
            if ($pack_id) {
                $pack_detail = WPUF_Subscription::get_subscription($pack_id);
                if (empty($pack_detail->meta_value['billing_amount']) || $pack_detail->meta_value['billing_amount'] <= 0) {
                    $is_free = true;
                }
            }
            $gateways = $this->get_active_gateways();
            if (isset($_REQUEST['wpuf_payment_submit'])) {
                $selected_gateway = $_REQUEST['wpuf_payment_method'];
            } else {
                $selected_gateway = 'paypal';
            }
            ob_start();
            if (is_user_logged_in()) {
                $current_user = wp_get_current_user();
            } else {
                $user_id = isset($_GET['user_id']) ? $_GET['user_id'] : 0;
                $current_user = get_userdata($user_id);
            }
            if ($pack_id && $is_free) {
                $wpuf_subscription = WPUF_Subscription::init();
                if (!WPUF_Subscription::has_used_free_pack($current_user->ID, $pack_id)) {
                    $wpuf_subscription->new_subscription($current_user->ID, $pack_id, null, false, 'free');
                    WPUF_Subscription::add_used_free_pack($current_user->ID, $pack_id);
                    $message = apply_filters('wpuf_fp_activated_msg', __('Your free package has been activated. Enjoy!'), 'wpuf');
                } else {
                    $message = apply_filters('wpuf_fp_activated_error', __('You already have activated a free package previously.'), 'wpuf');
                }
                ?>
                    <div class="wpuf-info"><?php 
                echo $message;
                ?>
</div>
                <?php 
            } else {
                ?>
                <?php 
                if (count($gateways)) {
                    ?>
                    <form id="wpuf-payment-gateway" action="<?php 
                    echo $_SERVER["REQUEST_URI"];
                    ?>
" method="POST">

                        <?php 
                    if ($pack_id) {
                        $pack = WPUF_Subscription::init()->get_subscription($pack_id);
                        $details_meta = WPUF_Subscription::init()->get_details_meta_value();
                        if (is_user_logged_in()) {
                            ?>
                            <input type="hidden" name="user_id" value="<?php 
                            echo $current_user->ID;
                            ?>
">
                        <?php 
                        }
                        ?>

                        <div class="wpuf-coupon-info-wrap">
                            <div class="wpuf-coupon-info">
                                <div class="wpuf-pack-info">
                                    <h3>
                                        <?php 
                        _e('Pricing & Plans', 'wpuf');
                        ?>

                                        <a href="<?php 
                        echo wpuf_get_subscription_page_url();
                        ?>
"><?php 
                        _e('Change Pack', 'wpuf');
                        ?>
</a>
                                    </h3>

                                    <div class="wpuf-pack-inner">
                                        <?php 
                        _e('Selected Pack', 'wpuf');
                        ?>
: <strong><?php 
                        echo $pack->post_title;
                        ?>
</strong>
                                    </div>
                                </div>
                            </div>

                            <div class="wpuf-copon-wrap"  style="display:none;">
                                <div class="wpuf-coupon-error" style="color: red;"></div>
                                <input type="text" name="coupon_code" size="20" class="wpuf-coupon-field">
                                <input type="hidden" name="coupon_id" size="20" class="wpuf-coupon-id-field">
                                <div>
                                    <a href="#" data-pack_id="<?php 
                        echo $pack_id;
                        ?>
" class="wpuf-apply-coupon"><?php 
                        _e('Apply Coupon', 'wpuf');
                        ?>
</a>
                                    <a href="#" data-pack_id="<?php 
                        echo $pack_id;
                        ?>
" class="wpuf-copon-cancel"><?php 
                        _e('Cancel', 'wpuf');
                        ?>
</a>
                                </div>
                            </div>
                            <a href="#" class="wpuf-copon-show"><?php 
                        _e('Have a discount code?', 'wpuf');
                        ?>
</a>
                        </div>
                        <?php 
                    }
                    ?>
                        <?php 
                    wp_nonce_field('wpuf_payment_gateway');
                    ?>

                        <?php 
                    do_action('wpuf_before_payment_gateway');
                    ?>

                        <p>
                            <label for="wpuf-payment-method"><?php 
                    _e('Choose Your Payment Method', 'wpuf');
                    ?>
</label><br />

                            <ul class="wpuf-payment-gateways">
                                <?php 
                    foreach ($gateways as $gateway_id => $gateway) {
                        ?>
                                    <li class="wpuf-gateway-<?php 
                        echo $gateway_id;
                        ?>
">
                                        <label>
                                            <input name="wpuf_payment_method" type="radio" value="<?php 
                        echo esc_attr($gateway_id);
                        ?>
" <?php 
                        checked($selected_gateway, $gateway_id);
                        ?>
>
                                            <?php 
                        echo $gateway['label'];
                        if (!empty($gateway['icon'])) {
                            printf(' <img src="%s" alt="image">', $gateway['icon']);
                        }
                        ?>
                                        </label>

                                        <div class="wpuf-payment-instruction" style="display: none;">
                                            <div class="wpuf-instruction"><?php 
                        echo wpuf_get_option('gate_instruct_' . $gateway_id, 'wpuf_payment');
                        ?>
</div>

                                            <?php 
                        do_action('wpuf_gateway_form_' . $gateway_id, $type, $post_id, $pack_id);
                        ?>
                                        </div>
                                    </li>
                                <?php 
                    }
                    ?>
                            </ul>

                        </p>
                        <?php 
                    do_action('wpuf_after_payment_gateway');
                    ?>
                        <p>
                            <input type="hidden" name="type" value="<?php 
                    echo $type;
                    ?>
" />
                            <input type="hidden" name="action" value="wpuf_pay" />
                            <?php 
                    if ($post_id) {
                        ?>
                                <input type="hidden" name="post_id" value="<?php 
                        echo $post_id;
                        ?>
" />
                            <?php 
                    }
                    ?>

                            <?php 
                    if ($pack_id) {
                        ?>
                                <input type="hidden" name="pack_id" value="<?php 
                        echo $pack_id;
                        ?>
" />
                            <?php 
                    }
                    ?>
                            <input type="submit" name="wpuf_payment_submit" value="<?php 
                    _e('Proceed', 'wpuf');
                    ?>
"/>
                        </p>
                    </form>
                <?php 
                } else {
                    ?>
                    <?php 
                    _e('No Payment gateway found', 'wpuf');
                    ?>
                <?php 
                }
                ?>

                <?php 
            }
            return ob_get_clean();
        }
        return $content;
    }
    function payment_page($content)
    {
        global $post;
        $pay_page = intval(wpuf_get_option('payment_page', 'wpuf_payment'));
        if ($post->ID == $pay_page && isset($_REQUEST['action']) && $_REQUEST['action'] == 'wpuf_pay') {
            if (!is_user_logged_in()) {
                return __('You are not logged in', 'wpuf');
            }
            $type = $_REQUEST['type'] == 'post' ? 'post' : 'pack';
            $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
            $pack_id = isset($_REQUEST['pack_id']) ? intval($_REQUEST['pack_id']) : 0;
            $is_free = false;
            if ($pack_id) {
                $pack_detail = WPUF_Subscription::get_subscription($pack_id);
                if ($pack_detail->cost == '0') {
                    $is_free = true;
                }
            }
            $gateways = $this->get_active_gateways();
            if (isset($_REQUEST['wpuf_payment_submit'])) {
                $selected_gateway = $_REQUEST['wpuf_payment_method'];
            } else {
                $selected_gateway = 'paypal';
            }
            ob_start();
            if ($pack_id && $is_free) {
                $current_user = wp_get_current_user();
                $wpuf_subscription = WPUF_Subscription::init();
                if (!WPUF_Subscription::has_used_free_pack($current_user->ID, $pack_id)) {
                    $wpuf_subscription->new_subscription($current_user->ID, $pack_id);
                    WPUF_Subscription::add_used_free_pack($current_user->ID, $pack_id);
                    $message = apply_filters('wpuf_fp_activated_msg', __('Your free package has been activated. Enjoy!'), 'wpuf');
                } else {
                    $message = apply_filters('wpuf_fp_activated_error', __('You already have activated a free package previously.'), 'wpuf');
                }
                ?>
                    <div class="wpuf-info"><?php 
                echo $message;
                ?>
</div>
                <?php 
            } else {
                ?>
                <?php 
                if (count($gateways)) {
                    ?>
                    <form id="wpuf-payment-gateway" action="<?php 
                    echo $_SERVER["REQUEST_URI"];
                    ?>
" method="POST">
                        <?php 
                    wp_nonce_field('wpuf_payment_gateway');
                    ?>
                        <?php 
                    do_action('wpuf_before_payment_gateway');
                    ?>
                        <p>
                            <label for="wpuf-payment-method"><?php 
                    _e('Choose Your Payment Method', 'wpuf');
                    ?>
</label><br />

                            <ul class="wpuf-payment-gateways">
                                <?php 
                    foreach ($gateways as $gateway_id => $gateway) {
                        ?>
                                    <li class="wpuf-gateway-<?php 
                        echo $gateway_id;
                        ?>
">
                                        <label>
                                            <input name="wpuf_payment_method" type="radio" value="<?php 
                        echo esc_attr($gateway_id);
                        ?>
" <?php 
                        checked($selected_gateway, $gateway_id);
                        ?>
>
                                            <?php 
                        echo $gateway['label'];
                        if (!empty($gateway['icon'])) {
                            printf(' <img src="%s" alt="image">', $gateway['icon']);
                        }
                        ?>
                                        </label>

                                        <div class="wpuf-payment-instruction" style="display: none;">
                                            <div class="wpuf-instruction"><?php 
                        echo wpuf_get_option('gate_instruct_' . $gateway_id, 'wpuf_payment');
                        ?>
</div>

                                            <?php 
                        do_action('wpuf_gateway_form_' . $gateway_id, $type, $post_id, $pack_id);
                        ?>
                                        </div>
                                    </li>
                                <?php 
                    }
                    ?>
                            </ul>

                        </p>
                        <?php 
                    do_action('wpuf_after_payment_gateway');
                    ?>
                        <p>
                            <input type="hidden" name="type" value="<?php 
                    echo $type;
                    ?>
" />
                            <input type="hidden" name="action" value="wpuf_pay" />
                            <?php 
                    if ($post_id) {
                        ?>
                                <input type="hidden" name="post_id" value="<?php 
                        echo $post_id;
                        ?>
" />
                            <?php 
                    }
                    ?>

                            <?php 
                    if ($pack_id) {
                        ?>
                                <input type="hidden" name="pack_id" value="<?php 
                        echo $pack_id;
                        ?>
" />
                            <?php 
                    }
                    ?>
                            <input type="submit" name="wpuf_payment_submit" value="<?php 
                    _e('Proceed', 'wpuf');
                    ?>
"/>
                        </p>
                    </form>
                <?php 
                } else {
                    ?>
                    <?php 
                    _e('No Payment gateway found', 'wpuf');
                    ?>
                <?php 
                }
                ?>

                <?php 
            }
            return ob_get_clean();
        }
        return $content;
    }