Example #1
0
/**
 * rennder user package info
 * @param Integer $user_ID the user_ID want to render
 *
 * @package AE Package
 * @category payment
 * 
 * @since 1.0
 * @author Dakachi
 */
function ae_user_package_info($user_ID)
{
    if (!$user_ID) {
        return;
    }
    global $ae_post_factory;
    $ae_pack = $ae_post_factory->get('pack');
    $packs = $ae_pack->fetch();
    $orders = AE_Payment::get_current_order($user_ID);
    $package_data = AE_Package::get_package_data($user_ID);
    foreach ($packs as $package) {
        $number_of_post = $package->et_number_posts;
        $sku = $package->sku;
        $text = '';
        if (isset($package_data[$sku]) && $package_data[$sku]['qty'] > 0) {
            $order = get_post($orders[$sku]);
            if (!$order || is_wp_error($order) || !in_array($order->post_status, array('publish', 'pending'))) {
                continue;
            }
            /**
             * print text when company has job left in package
             */
            ?>
        <p>
        <?php 
            $number_of_post = $package_data[$sku]['qty'];
            if ($order->post_status == 'publish') {
                printf(__("You purchased package <strong>%s</strong> and have %d post/s left.", 'aecore-payments-backend'), $package->post_title, $number_of_post);
            }
            if ($order->post_status == 'pending') {
                printf(__("You purchased package <strong>%s</strong> and have %d post/s left. Your posted post is pending until payment.", 'aecore-payments-backend'), $package->post_title, $number_of_post);
            }
            ?>
        </p>
    
    <?php 
        }
    }
}
 /**
  * check user use package or use freepackage
  * @param  string $package_id The pacakge sku to identify package
  * @param  object $ad Current purchase post
  * @return array 
  *         'url' => string process-payment-url base on type free/usePackage,
  *         'success' => bool
  * @author Dakachi
  */
 public static function package_or_free($package_id, $ad)
 {
     $instance = self::get_instance();
     $response = array('success' => false);
     $use_package = AE_Package::check_use_package($package_id);
     $package = $instance->get($package_id);
     if ($use_package) {
         et_write_session('ad_id', $ad->ID);
         $response['success'] = true;
         $response['url'] = et_get_page_link('process-payment', array('paymentType' => 'usePackage'));
         return $response;
     }
     if ($package->et_price == 0) {
         et_write_session('ad_id', $ad->ID);
         $response['success'] = true;
         $response['url'] = et_get_page_link('process-payment', array('paymentType' => 'free'));
         return $response;
     }
     return $response;
 }
Example #3
0
 /**
  * ajax callback sync post details
  * - update
  * - insert
  * - delete
  */
 function post_sync()
 {
     $request = $_REQUEST;
     global $ae_post_factory, $user_ID;
     if (!AE_Users::is_activate($user_ID)) {
         wp_send_json(array('success' => false, 'msg' => __("Your account is pending. You have to activate your account to continue this step.", 'projects-backend')));
     }
     if (check_existing_post_name($request['post_title']) && $request['method'] != 'update') {
         wp_send_json(array('success' => false, 'msg' => __("Current title name already exists", 'projects-backend')));
     }
     // prevent freelancer submit project
     if (!fre_share_role() && ae_user_role() == FREELANCER) {
         wp_send_json(array('success' => false, 'msg' => __("You need an employer account to post a project.", 'projects-backend')));
     }
     // unset package data when edit place if user can edit others post
     if (isset($request['ID']) && !isset($request['renew'])) {
         unset($request['et_payment_package']);
     }
     if (isset($request['archive'])) {
         $request['post_status'] = 'archive';
     }
     if (isset($request['publish'])) {
         $request['post_status'] = 'publish';
     }
     if (isset($request['delete'])) {
         $request['post_status'] = 'trash';
     }
     if (isset($request['disputed'])) {
         $request['post_status'] = 'disputed';
     }
     if (isset($request['close_disput'])) {
         $request['post_status'] = get_post_meta($request['ID'], 'post_status_before_disput', true);
     }
     if (isset($request['project_type'])) {
         unset($request['project_type']);
     }
     $place = $ae_post_factory->get($this->post_type);
     // sync place
     $result = $place->sync($request);
     if (!is_wp_error($result)) {
         // update place carousels
         if (isset($request['et_carousels'])) {
             // loop request carousel id
             foreach ($request['et_carousels'] as $key => $value) {
                 $att = get_post($value);
                 // just admin and the owner can add carousel
                 if (current_user_can('manage_options') || $att->post_author == $user_ID) {
                     wp_update_post(array('ID' => $value, 'post_parent' => $result->ID));
                 }
             }
         }
         /**
          * check payment package and check free or use package to send redirect link
          */
         if (isset($request['et_payment_package'])) {
             // check seller use package or not
             $check = AE_Package::package_or_free($request['et_payment_package'], $result);
             // check use package or free to return url
             if ($check['success']) {
                 $result->redirect_url = $check['url'];
             }
             $result->response = $check;
             // check seller have reached limit free plan
             $check = AE_Package::limit_free_plan($request['et_payment_package']);
             if ($check['success']) {
                 // false user have reached maximum free plan
                 $response['success'] = false;
                 $response['msg'] = $check['msg'];
                 // send response to client
                 wp_send_json($response);
             }
         }
         // check payment package
         /**
          * check disable plan and submit place to view details
          */
         if ($this->disable_plan && $request['method'] == 'create') {
             if (ICL_LANGUAGE_CODE != 'en') {
                 $redirect = apply_filters('wpml_permalink', $result->permalink, ICL_LANGUAGE_CODE);
             } else {
                 $redirect = $result->permalink;
             }
             // disable plan, free to post place
             $response = array('success' => true, 'data' => array('ID' => $result->ID, 'redirect_url' => $redirect), 'msg' => __("Submit place successfull.", 'projects-backend'));
             // send response
             wp_send_json($response);
         }
         // send json data to client
         wp_send_json(array('success' => true, 'data' => $result, 'msg' => __("Update project successful!", 'projects-backend')));
     } else {
         // update false
         wp_send_json(array('success' => false, 'data' => $result, 'msg' => $result->get_error_message()));
     }
 }
 function do_checkout(ET_Order $order)
 {
     global $ae_post_factory, $user_ID;
     /**
      * check session
      */
     $session = et_read_session();
     $ad_id = isset($session['ad_id']) ? $session['ad_id'] : '';
     if ($ad_id) {
         $post = get_post($ad_id);
         // ad id existed
         /**
          * get object by post type and convert
          */
         $post_obj = $ae_post_factory->get($post->post_type);
         $ad = $post_obj->convert($post);
         if (!is_wp_error($ad)) {
             /**
              * check user is available to use selected package
              */
             $available = AE_Package::check_use_package($ad->et_payment_package, $ad->post_author);
             if ($available) {
                 // process order data
                 $payment_return = array('ACK' => true, 'payment_type' => 'usePackage');
                 /**
                  * get user current order for package
                  */
                 $current_order = AE_Payment::get_current_order($ad->post_author, $ad->et_payment_package);
                 $order = get_post($current_order);
                 if (!$order || is_wp_error($order)) {
                     return array('ACK' => false, 'payment_type' => 'usePackage', 'msg' => __("Invalid Order or Package", ET_DOMAIN));
                 }
                 $ad_data = array();
                 $ad_data['ID'] = $ad->ID;
                 /**
                  * update ad order
                  */
                 $ad_data['et_ad_order'] = $current_order;
                 $ad_data['post_status'] = 'pending';
                 if ($order->post_status == 'publish') {
                     $options = AE_Options::get_instance();
                     $ad_data['et_paid'] = 1;
                     if (!$options->use_pending) {
                         $ad_data['post_status'] = 'publish';
                     }
                 } else {
                     $ad_data['et_paid'] = 0;
                 }
                 $ad_data['change_status'] = 'change_status';
                 $ad_data['method'] = 'update';
                 /**
                  * sync Ad data
                  */
                 $return = wp_update_post($ad_data);
                 // update post paid status
                 update_post_meta($ad->ID, 'et_paid', $ad_data['et_paid']);
                 // update post package order id
                 update_post_meta($ad->ID, 'et_ad_order', $ad_data['et_ad_order']);
                 /**
                  * update seller package quantity
                  */
                 AE_Package::update_package_data($ad->et_payment_package, $ad->post_author);
                 return $payment_return;
             }
         }
     }
     return array('ACK' => false, 'payment_type' => 'usePackage', 'msg' => __("Invalid Ad ID", ET_DOMAIN));
 }
Example #5
0
    protected function content($atts, $content = null)
    {
        $custom_css = $el_class = $title = $icon = $output = $s_content = $m_link = $payment_plan_feature = $payment_plan = '';
        extract(shortcode_atts(array('el_class' => '', 'payment_plan' => '', 'number_plan' => 4), $atts));
        /* ================  Render Shortcodes ================ */
        ob_start();
        ?>
        <!-- PRICING -->
        <?php 
        global $ae_post_factory;
        $ae_pack = AE_Package::get_instance();
        $ae_pack = $ae_post_factory->get('pack');
        $packs = $ae_pack->fetch();
        $pack_currency = ae_get_option('currency');
        $i = 0;
        $col = 'col-md-3 col-sm-6 col-xs-6';
        $class_width = '';
        if ($number_plan == 3) {
            $col = 'col-md-4 col-sm-4 col-xs-6';
            $class_width = 'width-880';
        }
        if ($number_plan == 2) {
            $col = 'col-md-6 col-sm-6 col-xs-6';
            $class_width = 'width-580';
        }
        ?>
        <div class="pricing-container">
            <div class="container  <?php 
        echo $class_width;
        ?>
 " >
            <div class="row">
            <?php 
        foreach ($packs as $key => $package) {
            $i++;
            if ($i > $number_plan) {
                break;
            }
            $pack = $ae_pack->convert($package);
            ?>
                <div class="<?php 
            echo $col;
            ?>
 pricing-item">
                    <div class="pricing <?php 
            echo $payment_plan_feature ? 'active' : '';
            ?>
 ">
                        <div class="pricing-number pricing-wrapper">
                            <h2 class="price">
                                <?php 
            if ($pack->et_price > 0) {
                ae_price($pack->et_price);
            } else {
                _e("FREE", ET_DOMAIN);
            }
            ?>
                            </h2>
                            <span>
                                <?php 
            echo $pack->backend_text;
            ?>
                            </span>
                        </div>
                        <div class="pricing-content">
                            <h3 class="pricing-title"><?php 
            echo $pack->post_title;
            ?>
</h3>
                            <div class="pricing-detail">
                                <?php 
            echo $pack->post_content;
            ?>
                            </div>
                            <div class="submit-price">
                                <a href="<?php 
            echo et_get_page_link(array('page_type' => 'submit-project'));
            ?>
" class="btn-sumary btn-price">
                                    <?php 
            if (!is_user_logged_in()) {
                _e('Sign Up', ET_DOMAIN);
            } else {
                _e("Submit Project", ET_DOMAIN);
            }
            ?>
                                </a>
                            </div>
                        </div> 
                    </div>
                </div>
                <?php 
        }
        ?>
            </div>
            </div>
        </div>
        <?php 
        $output = ob_get_clean();
        /* ================  Render Shortcodes ================ */
        return $output;
    }
<!-- Step 1 -->
<?php 
global $user_ID, $ae_post_factory;
$ae_pack = $ae_post_factory->get('pack');
$packs = $ae_pack->fetch('pack');
$package_data = AE_Package::get_package_data($user_ID);
// echo '<pre>';
// var_dump($package_data);
$orders = AE_Payment::get_current_order($user_ID);
?>

<div class="step-wrapper step-plan" id="step-plan">
	<a href="#" class="step-heading active">
    	<span class="number-step">1</span>
        <span class="text-heading-step"><?php 
_e('Select your pricing plan', ET_DOMAIN);
?>
</span>
        <i class="fa fa-caret-down"></i>
    </a>
    <div class="step-content-wrapper content">
    	<ul class="list-price">
        <?php 
foreach ($packs as $key => $package) {
    $number_of_post = $package->et_number_posts;
    $sku = $package->sku;
    $text = '';
    $order = false;
    if ($number_of_post > 1) {
        // get package current order
        if (isset($orders[$sku])) {
Example #7
0
 /** 
  * action process payment update seller order data
  * @param Array $payment_return The payment return data
  * @param Array $data Order data and payment type
  *
  * @since  1.0
  * @author  Dakachi
  *
  * @package AE Payment
  */
 public function member_payment_process($payment_return, $data)
 {
     extract($data);
     if (!$payment_return['ACK']) {
         return false;
     }
     if ($payment_type == 'free') {
         return false;
     }
     if ($payment_type == 'usePackage') {
         return false;
     }
     global $user_ID;
     $order_pay = $data['order']->get_order_data();
     // update user current order data associate with package
     self::update_current_order($order_pay['payer'], $order_pay['payment_package'], $data['order_id']);
     AE_Package::add_package_data($order_pay['payment_package'], $order_pay['payer']);
     /**
      * do action after process user order
      * @param $order_pay['payer'] the user id
      * @param $data The order data
      */
     do_action('ae_member_process_order', $order_pay['payer'], $order_pay);
 }
Example #8
0
function cash_upproved($post_ID, $post)
{
    if (current_user_can('manage_options')) {
        if ($post->post_type == 'order' && $post->post_status == 'publish') {
            $order = new AE_Order($post_ID);
            $order_pay = $order->get_order_data();
            if (isset($order_pay['payment']) && $order_pay['payment'] == 'cash') {
                $products = $order_pay['products'];
                $sku = $order_pay['payment_package'];
                $packs = AE_Package::get_instance();
                $pack = $packs->get_pack($sku, 'bid_plan');
                if (isset($pack->et_number_posts) && (int) $pack->et_number_posts > 0) {
                    update_credit_number($post->post_author, (int) $pack->et_number_posts);
                }
            }
        }
    }
}