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 #2
0
 /**
  * catch action ae_process_payment_action and update post data after payment success
  *
  * @param $payment_return
  * @param $data
  *
  * @return array $payment_return
  *
  * @since 1.0
  * @author dakachi <*****@*****.**>
  */
 function process_payment($payment_return, $data)
 {
     global $ae_post_factory;
     // process user order after pay
     do_action('ae_select_process_payment', $payment_return, $data);
     $this->member_payment_process($payment_return, $data);
     //  if not exist post id
     if (!isset($data['ad_id']) || !$data['ad_id']) {
         return $payment_return;
     }
     $options = AE_Options::get_instance();
     $ad_id = $data['ad_id'];
     extract($data);
     if (!$payment_return['ACK']) {
         return;
     }
     $post = get_post($ad_id);
     /**
      * get object by post type and convert
      */
     $post_obj = $ae_post_factory->get($post->post_type);
     $ad = $post_obj->convert($post);
     if ($payment_type != 'usePackage') {
         /**
          * update seller package quantity
          */
         AE_Package::update_package_data($ad->et_payment_package, $ad->post_author);
         if (!is_super_admin()) {
             $post_data = array('ID' => $ad_id, 'post_status' => 'pending');
         } else {
             $post_data = array('ID' => $ad_id, 'post_status' => 'publish');
         }
     }
     // disable pending and auto publish post
     /** @var string $payment_type */
     if (!$options->use_pending && 'cash' != $payment_type) {
         $post_data['post_status'] = 'publish';
     }
     // when buy new package will got and order
     if (isset($data['order_id'])) {
         // update post order id
         update_post_meta($ad_id, 'et_ad_order', $data['order_id']);
     }
     // Change Status Publish places that posted by Admin
     if (is_super_admin()) {
         wp_update_post(array('ID' => $ad_id, 'post_status' => 'publish'));
     }
     switch ($payment_type) {
         case 'cash':
             wp_update_post($post_data);
             // update unpaid payment
             update_post_meta($ad_id, 'et_paid', 0);
             return $payment_return;
         case 'free':
             wp_update_post($post_data);
             // update free payment
             update_post_meta($ad_id, 'et_paid', 2);
             return $payment_return;
         case 'usePackage':
             return $payment_return;
         default:
             // code...
             break;
     }
     /**
      * payment succeed
      */
     if ('PENDING' != strtoupper($payment_return['payment_status'])) {
         wp_update_post($post_data);
         // paid
         update_post_meta($ad_id, 'et_paid', 1);
     } else {
         /**
          * in some case the payment will be pending
          */
         wp_update_post(array('ID' => $ad_id, 'post_status' => 'pending'));
         // unpaid
         update_post_meta($ad_id, 'et_paid', 0);
     }
     return $payment_return;
 }