예제 #1
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;
    }
예제 #2
0
    /**
     * Adds the postlock form in users profile
     *
     * @param object $profileuser
     */
    function profile_subscription_details($profileuser)
    {
        if (!is_admin() && !current_user_can('edit_users')) {
            return;
        }
        if (wpuf_get_option('charge_posting', 'wpuf_payment') != 'yes') {
            return;
        }
        $userdata = get_userdata($profileuser->ID);
        //wp 3.3 fix
        $packs = WPUF_Subscription::init()->get_subscriptions();
        $user_sub = WPUF_Subscription::get_user_pack($userdata->ID);
        $pack_id = isset($user_sub['pack_id']) ? $user_sub['pack_id'] : '';
        ?>
        <div class="wpuf-user-subscription">
            <h3><?php 
        _e('WPUF Subscription', 'wpuf');
        ?>
</h3>
            <a class="btn button-primary wpuf-assing-pack-btn wpuf-add-pack" href="#"><?php 
        _e('Assign Package', 'wpuf');
        ?>
</a>
            <a class="btn button-primary wpuf-assing-pack-btn wpuf-cancel-pack" style="display:none;" href="#"><?php 
        _e('Show Package', 'wpuf');
        ?>
</a>
            <table class="form-table wpuf-pack-dropdown" disabled="disabled" style="display: none;">
                <tr>
                    <th><label for="wpuf_sub_pack"><?php 
        _e('Pack:', 'wpuf');
        ?>
 </label></th>
                    <td>
                        <select name="pack_id" id="wpuf_sub_pack">
                        <option value="-1"><?php 
        _e('--Select--', 'wpuf');
        ?>
</option>
                        <?php 
        $this->packdropdown_without_recurring($packs, $pack_id);
        //WPUF_Subscription::init()->packdropdown( $packs, $selected = '' );
        ?>
                        </select>
                    </td>
                </tr>

            </table>
            <?php 
        if (!isset($user_sub['pack_id'])) {
            return;
        }
        $pack = WPUF_Subscription::get_subscription($user_sub['pack_id']);
        $details_meta = WPUF_Subscription::init()->get_details_meta_value();
        $billing_amount = intval($pack->meta_value['billing_amount']) > 0 ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __('Free', 'wpuf');
        if ($billing_amount && $pack->meta_value['recurring_pay'] == 'yes') {
            $recurring_des = sprintf('For each %s %s', $pack->meta_value['billing_cycle_number'], $pack->meta_value['cycle_period'], $pack->meta_value['trial_duration_type']);
            $recurring_des .= !empty($pack->meta_value['billing_limit']) ? sprintf(', for %s installments', $pack->meta_value['billing_limit']) : '';
            $recurring_des = $recurring_des;
        } else {
            $recurring_des = '';
        }
        ?>

            <div class="wpuf-user-sub-info">
                <h3><?php 
        _e('Subscription Details', 'wpuf');
        ?>
</h3>
                <div class="wpuf-text">
                    <div><strong><?php 
        _e('Subcription Name: ', 'wpuf');
        ?>
</strong><?php 
        echo $pack->post_title;
        ?>
</div>
                    <div>
                        <strong><?php 
        _e('Package billing details: ');
        ?>
</strong>
                        <div class="wpuf-pricing-wrap">
                            <div class="wpuf-sub-amount">
                                <?php 
        echo $billing_amount;
        ?>
                                <?php 
        echo $recurring_des;
        ?>

                            </div>
                        </div>
                    </div>

                    <strong><?php 
        _e('Remaining post: ', 'wpuf');
        ?>
</strong>
                    <table class="form-table">

                        <?php 
        foreach ($user_sub['posts'] as $key => $value) {
            ?>
                             <tr>
                                 <th><label><?php 
            echo $key;
            ?>
</label></th>
                                 <td><input type="text" value="<?php 
            echo $value;
            ?>
" name="<?php 
            echo $key;
            ?>
" ></td>
                             </tr>
                            <?php 
        }
        ?>



                    <?php 
        if ($user_sub['recurring'] != 'yes') {
            if (!empty($user_sub['expire'])) {
                $expire = $user_sub['expire'] == 'unlimited' ? ucfirst('unlimited') : wpuf_date2mysql($user_sub['expire']);
                ?>
                            <tr>
                                <th><label><?php 
                echo _e('Expire date:');
                ?>
</label></th>
                                <td><input type="text" class="wpuf-date-picker" name="expire" value="<?php 
                echo wpuf_get_date($expire);
                ?>
"></td>
                            </tr>
                            <?php 
            }
        }
        ?>
                    </table>
                </div>
            </div>
        </div>
            <?php 
    }
예제 #3
0
    /**
     * Adds the postlock form in users profile
     *
     * @param object $profileuser
     */
    function profile_subscription_details($profileuser)
    {
        if (!current_user_can('edit_users')) {
            return;
        }
        if (wpuf_get_option('charge_posting', 'wpuf_payment') != 'yes') {
            return;
        }
        $userdata = get_userdata($profileuser->ID);
        //wp 3.3 fix
        $packs = WPUF_Subscription::init()->get_subscriptions();
        $user_sub = WPUF_Subscription::get_user_pack($userdata->ID);
        $pack_id = isset($user_sub['pack_id']) ? $user_sub['pack_id'] : '';
        ?>
        <div class="wpuf-user-subscription">
            <h3><?php 
        _e('WPUF Subscription', 'wpuf');
        ?>
</h3>
            <?php 
        if (isset($user_sub['pack_id'])) {
            $pack = WPUF_Subscription::get_subscription($user_sub['pack_id']);
            $details_meta = WPUF_Subscription::init()->get_details_meta_value();
            $billing_amount = intval($pack->meta_value['billing_amount']) > 0 ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __('Free', 'wpuf');
            if ($billing_amount && $pack->meta_value['recurring_pay'] == 'yes') {
                $recurring_des = sprintf('For each %s %s', $pack->meta_value['billing_cycle_number'], $pack->meta_value['cycle_period'], $pack->meta_value['trial_duration_type']);
                $recurring_des .= !empty($pack->meta_value['billing_limit']) ? sprintf(', for %s installments', $pack->meta_value['billing_limit']) : '';
                $recurring_des = $recurring_des;
            } else {
                $recurring_des = '';
            }
            ?>
                <div class="wpuf-user-sub-info">
                    <h3><?php 
            _e('Subscription Details', 'wpuf');
            ?>
</h3>
                    <?php 
            if (isset($user_sub['recurring']) && $user_sub['recurring'] == 'yes') {
                ?>
                        <div class="updated">
                            <p><?php 
                _e('This user is using recurring subscription pack', 'wpuf');
                ?>
</p>
                        </div>
                    <?php 
            }
            ?>
                    <div class="wpuf-text">
                        <div><strong><?php 
            _e('Subcription Name: ', 'wpuf');
            ?>
</strong><?php 
            echo $pack->post_title;
            ?>
</div>
                        <div>
                            <strong><?php 
            _e('Package billing details: ');
            ?>
</strong>
                            <div class="wpuf-pricing-wrap">
                                <div class="wpuf-sub-amount">
                                    <?php 
            echo $billing_amount;
            ?>
                                    <?php 
            echo $recurring_des;
            ?>

                                </div>
                            </div>
                        </div>

                        <strong><?php 
            _e('Remaining post: ', 'wpuf');
            ?>
</strong>
                        <table class="form-table">

                            <?php 
            foreach ($user_sub['posts'] as $key => $value) {
                ?>
                                 <tr>
                                     <th><label><?php 
                echo $key;
                ?>
</label></th>
                                     <td><input type="text" value="<?php 
                echo $value;
                ?>
" name="<?php 
                echo $key;
                ?>
" ></td>
                                 </tr>
                                <?php 
            }
            ?>
                        <?php 
            if ($user_sub['recurring'] != 'yes') {
                if (!empty($user_sub['expire'])) {
                    $expire = $user_sub['expire'] == 'unlimited' ? ucfirst('unlimited') : wpuf_date2mysql($user_sub['expire']);
                    ?>
                                <tr>
                                    <th><label><?php 
                    echo _e('Expire date:');
                    ?>
</label></th>
                                    <td><input type="text" class="wpuf-date-picker" name="expire" value="<?php 
                    echo wpuf_get_date($expire);
                    ?>
"></td>
                                </tr>
                                <?php 
                }
            }
            ?>
                            <?php 
            $is_post_exp_selected = isset($user_sub['_enable_post_expiration']) ? 'checked' : '';
            $_post_expiration_time = explode(' ', isset($user_sub['_post_expiration_time']) ? $user_sub['_post_expiration_time'] : ' ');
            $time_value = isset($_post_expiration_time[0]) && !empty($_post_expiration_time[0]) ? $_post_expiration_time[0] : '1';
            $time_type = isset($_post_expiration_time[1]) && !empty($_post_expiration_time[1]) ? $_post_expiration_time[1] : 'day';
            ?>
                            <tr>
                                <th><label><?php 
            echo _e('Post Expiration Enabled');
            ?>
</label></th>
                                <td><input type="checkbox" name="is_post_expiration_enabled" value="on" <?php 
            echo $is_post_exp_selected;
            ?>
></td>
                            </tr>
                            <tr>
                                <?php 
            $timeType_array = array('year' => 100, 'month' => 12, 'day' => 30);
            ?>
                                <th><?php 
            _e('Post Expiration Time', 'wpuf');
            ?>
</th>
                                <td>
                                    <select name="post_expiration_settings[expiration_time_value]" id="wpuf-expiration_time_value">
                                        <?php 
            for ($i = 1; $i <= $timeType_array[$time_type]; $i++) {
                ?>
                                            <option value="<?php 
                echo $i;
                ?>
" <?php 
                echo $i == $time_value ? 'selected' : '';
                ?>
><?php 
                echo $i;
                ?>
</option>
                                        <?php 
            }
            ?>
                                    </select>
                                    <select name="post_expiration_settings[expiration_time_type]" id="wpuf-expiration_time_type">
                                        <?php 
            foreach ($timeType_array as $each_time_type => $each_time_type_val) {
                ?>
                                            <option value="<?php 
                echo $each_time_type;
                ?>
" <?php 
                echo $each_time_type == $time_type ? 'selected' : '';
                ?>
><?php 
                echo ucfirst($each_time_type);
                ?>
</option>
                                        <?php 
            }
            ?>
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            <?php 
        }
        ?>
            <?php 
        if (!isset($user_sub['recurring']) || $user_sub['recurring'] != 'yes') {
            ?>
            <a class="btn button-primary wpuf-assing-pack-btn wpuf-add-pack" href="#"><?php 
            _e('Assign Package', 'wpuf');
            ?>
</a>
            <a class="btn button-primary wpuf-assing-pack-btn wpuf-cancel-pack" style="display:none;" href="#"><?php 
            _e('Show Package', 'wpuf');
            ?>
</a>
            <table class="form-table wpuf-pack-dropdown" disabled="disabled" style="display: none;">
                <tr>
                    <th><label for="wpuf_sub_pack"><?php 
            _e('Pack:', 'wpuf');
            ?>
 </label></th>
                    <td>
                        <select name="pack_id" id="wpuf_sub_pack">
                            <option value="-1"><?php 
            _e('--Select--', 'wpuf');
            ?>
</option>
                            <?php 
            $this->packdropdown_without_recurring($packs, $pack_id);
            //WPUF_Subscription::init()->packdropdown( $packs, $selected = '' );
            ?>
                        </select>
                    </td>
                </tr>
            </table>
            <?php 
        }
        ?>
            <?php 
        if (!empty($user_sub)) {
            ?>
                <a class="btn button-primary wpuf-delete-pack-btn" href="javascript:" data-userid = "<?php 
            echo $userdata->ID;
            ?>
"><?php 
            _e('Delete Package', 'wpuf');
            ?>
</a>
            <?php 
        }
        ?>
        </div>
        <?php 
    }
예제 #4
0
 /**
  * Send payment handler to the gateway
  *
  * This function sends the payment handler mechanism to the selected
  * gateway. If 'paypal' is selected, then a particular action is being
  * called. A  listener function can be invoked for that gateway to handle
  * the request and send it to the gateway.
  *
  * Need to use `wpuf_gateway_{$gateway_name}
  */
 function send_to_gateway()
 {
     if (isset($_POST['wpuf_payment_submit']) && $_POST['action'] == 'wpuf_pay' && wp_verify_nonce($_POST['_wpnonce'], 'wpuf_payment_gateway')) {
         $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
         $pack_id = isset($_REQUEST['pack_id']) ? intval($_REQUEST['pack_id']) : 0;
         $gateway = $_POST['wpuf_payment_method'];
         $type = $_POST['type'];
         $userdata = wp_get_current_user();
         switch ($type) {
             case 'post':
                 $post = get_post($post_id);
                 $amount = wpuf_get_option('cost_per_post');
                 $item_number = get_post_meta($post_id, 'wpuf_order_id', true);
                 $item_name = $post->post_title;
                 break;
             case 'pack':
                 $subscription = new WPUF_Subscription();
                 $pack = $subscription->get_subscription($pack_id);
                 $amount = $pack->cost;
                 $item_name = $pack->name;
                 $item_number = $pack->id;
                 break;
         }
         $payment_vars = array('currency' => wpuf_get_option('currency'), 'price' => $amount, 'item_number' => $item_number, 'item_name' => $item_name, 'type' => $type, 'user_info' => array('id' => $userdata->ID, 'email' => $userdata->user_email, 'first_name' => $userdata->first_name, 'last_name' => $userdata->last_name), 'date' => date('Y-m-d H:i:s'), 'post_data' => $_POST);
         do_action('wpuf_gateway_' . $gateway, $payment_vars);
     }
 }
예제 #5
0
 /**
  * @param $user_meta
  * @param $user_id
  * @param $pack_id
  * @param $recurring
  * @return mixed
  */
 public static function set_subscription_meta_to_user($user_meta, $user_id, $pack_id, $recurring)
 {
     $subscription = parent::get_subscription($pack_id);
     $user_meta['postnum_rollback_on_delete'] = isset($subscription->meta_value['postnum_rollback_on_delete']) ? $subscription->meta_value['postnum_rollback_on_delete'] : '';
     return $user_meta;
 }
    /**
     * Adds the postlock form in users profile
     *
     * @param object $profileuser
     */
    function profile_subscription_details($profileuser)
    {
        if (is_admin() && current_user_can('edit_users')) {
            if (wpuf_get_option('charge_posting', 'wpuf_payment') == 'yes') {
                $validity = isset($profileuser->wpuf_sub_validity) ? $profileuser->wpuf_sub_validity : date('Y-m-d G:i:s', time());
                $count = isset($profileuser->wpuf_sub_pcount) ? $profileuser->wpuf_sub_pcount : 0;
                if (isset($profileuser->wpuf_sub_pack)) {
                    $pack = WPUF_Subscription::get_subscription($profileuser->wpuf_sub_pack);
                    $pack = $pack->name;
                } else {
                    $pack = 'Free';
                }
                ?>

                <h3><?php 
                _e('WPUF Subscription', 'wpuf');
                ?>
</h3>

                <table class="form-table">
                    <tr>
                        <th><label for="wpuf_sub_pack"><?php 
                _e('Pack:', 'wpuf');
                ?>
 </label></th>
                        <td>
                            <input type="text" disabled="disabled" name="wpuf_sub_pack" id="wpuf_sub_pack" class="regular-text" value="<?php 
                echo $pack;
                ?>
" />
                        </td>
                    </tr>
                    <tr>
                        <th><label for="wpuf_sub_pcount"><?php 
                _e('Post Count:', 'wpuf');
                ?>
 </label></th>
                        <td>
                            <input type="text" name="wpuf_sub_pcount" id="wpuf_sub_pcount" class="regular-text" value="<?php 
                echo $count;
                ?>
" />
                        </td>
                    </tr>
                    <tr>
                        <th><label for="wpuf_sub_validity"><?php 
                _e('Validity:', 'wpuf');
                ?>
 </label></th>
                        <td>
                            <input type="text" name="wpuf_sub_validity" id="wpuf_sub_validity" class="regular-text" value="<?php 
                echo $validity;
                ?>
" />
                        </td>
                    </tr>
                </table>

            <?php 
            }
            ?>

            <?php 
        }
    }