PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; use Stripe\Util\Set; use WC_Order; use WilokeListingTools\Controllers\Retrieve\AjaxRetrieve; use WilokeListingTools\Framework\Helpers\FileSystem; use WilokeListingTools\Framework\Helpers\General; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\GetWilokeSubmission; use WilokeListingTools\Framework\Helpers\SetSettings; use WilokeListingTools\Framework\Helpers\Time; use WilokeListingTools\Framework\Payment\PaymentGatewayStaticFactory; use WilokeListingTools\Framework\Payment\PayPal\PayPalExecuteNonRecurringPayment; use WilokeListingTools\Framework\Payment\PayPal\PayPalExecutePromotionPayment; use WilokeListingTools\Framework\Payment\Receipt\ReceiptStaticFactory; use WilokeListingTools\Framework\Payment\WooCommerce\WooCommerceNonRecurringPaymentMethod; use WilokeListingTools\Framework\Routing\Controller; use WilokeListingTools\Framework\Store\Session; use WilokeListingTools\Frontend\User; use WilokeListingTools\Models\PaymentMetaModel; use WilokeListingTools\Models\PaymentModel; use WilokeListingTools\Models\PromotionModel; class PromotionController extends Controller { protected $aPromotionPlans; protected $aWoocommercePlans; protected $expirationHookName = 'expiration_promotion'; private $belongsToPromotionKey = 'belongs_to_promotion'; private $category = 'promotion'; protected $logFileName = 'promotion-success.log'; private $oReceipt; private $isNonRecurringPayment = true; private $gateway; private $aSelectedPlans; private $aSelectedPlanKeys; public function __construct() { add_action('wp_ajax_wilcity_fetch_promotion_plans', [$this, 'fetchPromotions']); add_action('wp_ajax_wilcity_get_payment_gateways', [$this, 'getPaymentGateways']); add_action('wp_ajax_wilcity_boost_listing', [$this, 'boostListing']); add_action('updated_post_meta', [$this, 'updatedListingPromotionMeta'], 999, 4); add_action('added_post_meta', [$this, 'updatedListingPromotionMeta'], 999, 4); add_action('post_updated', [$this, 'updatePromotion'], 10, 3); add_action('save_post_promotion', [$this, 'handleAfterPromotionSaved'], 10, 3); add_action('before_delete_post', [$this, 'deletePromotion'], 100); $aPromotionPlans = GetSettings::getOptions('promotion_plans'); if (!empty($aPromotionPlans)) { foreach ($aPromotionPlans as $aPlanSetting) { $position = GetSettings::generateSavingPromotionDurationKey($aPlanSetting); add_action($this->generateScheduleKey($position), [ $this, 'deletePromotionValue' ], 10, 2); } } add_action('wilcity/single-listing/sidebar-promotion', [$this, 'printOnSingleListing'], 10, 2); add_action('wp_ajax_wilcity_fetch_listing_promotions', [$this, 'fetchPromotionDetails']); add_action('wilcity/wiloke-listing-tools/inserted-payment', [$this, 'createPromotion']); $aBillingTypes = wilokeListingToolsRepository()->get('payment:billingTypes', false); foreach ($aBillingTypes as $billingType) { add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-completed', [$this, 'updatePromotionAfterPaymentCompleted'], 15 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-refunded', [$this, 'removePromotionAfterPaymentRefunded'], 15 ); } add_action('init', [$this, 'paymentExecution'], 1); add_action('woocommerce_checkout_order_processed', [$this, 'purchasePromotionPlansThroughWooCommerce'], 5, 1); } public function paymentExecution() { if ( !isset($_GET['category']) || !in_array($_GET['category'], ['promotion']) || !isset($_GET['token']) || empty($_GET['token']) || Session::getSession('waiting_for_paypal_execution') !== 'yes' ) { return false; } $oPayPalMethod = new PayPalExecutePromotionPayment(new PayPalExecuteNonRecurringPayment()); if (!$oPayPalMethod) { return false; } if ($oPayPalMethod->verify()) { $aResponse = $oPayPalMethod->execute(); if ($aResponse['status'] == 'error') { Session::setSession('payment_error', $aResponse['msg']); FileSystem::logError($aResponse['msg'], __CLASS__, __METHOD__); } } } public function fetchPromotionDetails() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aData = isset($_GET['postID']) ? $_GET : $_POST; if (!isset($aData['postID']) || empty($aData['postID'])) { $oRetrieve->error([ 'msg' => esc_html__('The post id is required.', 'wiloke-listing-tools'), ]); } $aRawPromotions = PromotionModel::getListingPromotions($aData['postID']); if (empty($aRawPromotions)) { $oRetrieve->error([ 'msg' => esc_html__('There are no promotions.', 'wiloke-listing-tools'), ]); } $aPromotions = []; $aRawPromotionPlans = GetSettings::getPromotionPlans(); $aPromotionPlans = []; foreach ($aRawPromotionPlans as $promotionKey => $aPlan) { $aPromotionPlans[$promotionKey] = $aPlan; } foreach ($aRawPromotions as $aPromotion) { $position = str_replace('wilcity_promote_', '', $aPromotion['meta_key']); $aPromotions[] = [ 'name' => $aPromotionPlans[$position]['name'], 'position' => $position, 'preview' => $aPromotionPlans[$position]['preview'], 'expiryOn' => date_i18n(get_option('date_format'), $aPromotion['meta_value']) ]; } $oRetrieve->success($aPromotions); } public function printOnSingleListing($post, $aSidebarSetting) { $aSidebarSetting = wp_parse_args($aSidebarSetting, [ 'name' => '', 'conditional' => '', 'promotionID' => '', 'style' => 'slider' ]); $belongsTo = GetSettings::getPostMeta($post->ID, 'belongs_to'); if (!empty($belongsTo) && !GetSettings::isPlanAvailableInListing($post->ID, 'toggle_promotion')) { return ''; } $aPromotionSettings = GetSettings::getPromotionSetting($aSidebarSetting['promotionID']); if (!is_array($aPromotionSettings)) { return $aPromotionSettings; } if ($aPromotionSettings['name']) { unset($aPromotionSettings['name']); } $aSidebarSetting = array_merge($aSidebarSetting, $aPromotionSettings); $aSidebarSetting['orderby'] = 'rand'; $aSidebarSetting['order'] = 'DESC'; $aSidebarSetting['postType'] = General::getPostTypeKeys(false, false); $aSidebarSetting['aAdditionalArgs']['meta_query'] = [ [ 'key' => GetSettings::generateListingPromotionMetaKey($aSidebarSetting, true), 'compare' => 'EXISTS', ] ]; $aAtts = [ 'atts' => $aSidebarSetting ]; echo wilcitySidebarRelatedListings($aAtts); } public function deletePromotion($postID) { if (get_post_type($postID) != 'promotion') { return false; } $listingID = GetSettings::getPostMeta($postID, 'listing_id'); if (empty($listingID)) { return false; } SetSettings::deletePostMeta($listingID, $this->belongsToPromotionKey); } private function focusUpdatePromotionStatus($postID, $status) { global $wpdb; $wpdb->update( $wpdb->posts, [ 'post_status' => $status ], [ 'ID' => $postID ], [ '%s' ], [ '%s' ] ); } public function updateChangedPaymentStatus($aData) { if ($aData['newStatus'] !== 'pending') { $aBoostPostData = PaymentMetaModel::get($aData['paymentID'], 'boost_post_data'); SetSettings::deletePostMeta($aBoostPostData['postID'], 'promotion_wait_for_bank_transfer'); } else { $aBoostPostData = PaymentMetaModel::get($aData['paymentID'], 'boost_post_data'); SetSettings::setPostMeta( $aBoostPostData['postID'], 'promotion_wait_for_bank_transfer', $aData['paymentID'] ); } } public function deleteWaitForBankTransferStatus($aData) { if (PaymentMetaModel::get($aData['paymentID'], 'packageType') !== 'promotion') { return false; } } public function updatePromotionPageStatusToPublish($aData) { $promotionPageID = PaymentMetaModel::get($aData['paymentID'], 'promotion_page_id'); if (empty($promotionPageID)) { return false; } wp_update_post([ 'ID' => $promotionPageID, 'post_status' => 'draft' ]); wp_update_post([ 'ID' => $promotionPageID, 'post_status' => 'publish' ]); } public function deletePromotionValue($listingID, $position) { SetSettings::deletePostMeta($listingID, 'promote_'.$position); if (strpos($position, 'top_of_search') !== false) { $this->updateMenuOrder($listingID, $position, false); } $promotionID = GetSettings::getPostMeta($listingID, $this->belongsToPromotionKey); if (empty($promotionID)) { return false; } $aRawPromotionPlans = GetSettings::getOptions('promotion_plans'); $isExpiredAll = true; $now = current_time('timestamp'); foreach ($aRawPromotionPlans as $aPlanSetting) { $val = GetSettings::getPostMeta($promotionID, 'promote_'.$aPlanSetting['position']); if (!empty($val)) { $val = abs($val); if ($val > $now) { $isExpiredAll = false; } } } if ($isExpiredAll) { $this->focusUpdatePromotionStatus($promotionID, 'draft'); } } private function deleteAllPlansOfListing($listingID) { $aRawPromotionPlans = GetSettings::getOptions('promotion_plans'); foreach ($aRawPromotionPlans as $aPlanSetting) { if (strpos($aPlanSetting['position'], 'top_of_search') !== false) { $this->updateMenuOrder($listingID, $aPlanSetting['position'], false); } $aPromotionPlans = $this->getPromotionPlans(); $aPlanKeys = array_keys($aPromotionPlans); foreach ($aPlanKeys as $position) { $this->clearExpirationPromotion($position, $listingID); if (strpos($position, 'top_of_search') !== false) { $promotionExists = GetSettings::getPostMeta($listingID, 'promote_'.$position); if (!empty($promotionExists)) { $this->updateMenuOrder($listingID, $position, false); } } SetSettings::deletePostMeta($listingID, 'promote_'.$position); } } SetSettings::deletePostMeta($listingID, $this->belongsToPromotionKey); } /* * Generate Key where stores promotion duration to Listing ID * * @since 1.2.0 */ private function generateListingPromoteKey($aPromotion) { return 'promote_'.GetSettings::generateSavingPromotionDurationKey($aPromotion); } private function generateScheduleKey($position) { return 'trigger_promote_'.$position.'_expired'; } protected function getPromotionPlans() { $this->aPromotionPlans = GetSettings::getPromotionPlans(); return $this->aPromotionPlans; } protected function getPromotionPlanKeys() { return is_array($this->getPromotionPlans()) ? array_keys($this->aPromotionPlans) : []; } public function getPromotionField($field) { $this->getPromotionPlans(); return isset($this->aPromotionPlans[$field]) ? $this->aPromotionPlans[$field] : false; } /* * Updating Listing Order * * @since 1.0 */ private function updateMenuOrder($listingID, $promotionKey, $isPlus = true) { $promotionKey = str_replace('wilcity_promote_', '', $promotionKey); $aTopOfSearchSettings = $this->getPromotionField($promotionKey); if ($aTopOfSearchSettings) { $menuOrder = get_post_field('menu_order', $listingID); if ($isPlus) { $menuOrder = abs($menuOrder) + abs($aTopOfSearchSettings['menu_order']); } else { $menuOrder = abs($menuOrder) - abs($aTopOfSearchSettings['menu_order']); } global $wpdb; $wpdb->update( $wpdb->posts, [ 'menu_order' => $menuOrder ], [ 'ID' => $listingID ], [ '%d' ], [ '%d' ] ); } } /** * Set a expiry promotion cron job * * $position This var contains promotion ID already * @return null * @since 1.2.0 */ public function updatedListingPromotionMeta($metaID, $objectID, $metaKey, $metaValue) { if ((get_post_type($objectID) !== 'promotion')) { return false; } if (strpos($metaKey, 'wilcity_promote_') !== false) { if (isset($_GET['action']) && $_GET['action'] == 'edit') { $listingID = abs($_POST['wilcity_listing_id']); } else { $listingID = GetSettings::getPostMeta($objectID, 'listing_id'); } if (empty($listingID) || get_post_status($objectID) != 'publish') { return false; } $position = str_replace('wilcity_promote_', '', $metaKey); $this->clearExpirationPromotion($position, $listingID); if (is_numeric($metaValue) && !empty($metaValue)) { wp_clear_scheduled_hook($this->generateScheduleKey($position), [$listingID, $position]); wp_schedule_single_event($metaValue, $this->generateScheduleKey($position), [ $listingID, $position ]); update_post_meta($listingID, $metaKey, $metaValue); if (strpos($metaKey, 'top_of_search') !== false) { $this->updateMenuOrder($listingID, $metaKey, true); } } } else if ($metaKey == 'wilcity_listing_id') { SetSettings::setPostMeta($metaValue, $this->belongsToPromotionKey, $objectID); } } public function handleAfterPromotionSaved($promotionID, $post, $update) { if ($update) { // updatePromotion handled it return false; } if ($post->post_status !== 'publish') { return false; } $listingID = GetSettings::getPostMeta($promotionID, 'listing_id'); if (empty($listingID)) { return false; } $this->updateListingPromotion($listingID, $promotionID, false); } public function updatePromotion($postID, $oPostAfter, $oPostBefore) { if ($oPostAfter->post_type !== 'promotion') { return false; } // Processing this update under Promotion if (isset($_GET['action']) && $_GET['action'] == 'edit') { $listingID = abs($_POST['wilcity_listing_id']); $isAdmin = true; } else { $listingID = GetSettings::getPostMeta($postID, 'listing_id'); $isAdmin = false; } if (empty($listingID)) { return false; } $aPromotionPlans = $this->getPromotionPlans(); if (empty($aPromotionPlans)) { return false; } // FileSystem::filePutContents('promotion.txt', $listingID); // FileSystem::logPayment('promotion.txt', json_encode($aPromotionPlans)); // FileSystem::logPayment('promotion.txt', json_encode($oPostAfter)); $focusUpdate = GetSettings::getPostMeta($postID, 'focus_update_listing'); $isFocusReSetupPromotion = $focusUpdate === 'yes'; if ($oPostAfter->post_status == 'publish') { $currentListingID = GetSettings::getPostMeta($postID, 'listing_id'); if (!empty($currentListingID) && $listingID != $currentListingID) { $this->deleteAllPlansOfListing($currentListingID); $isFocusReSetupPromotion = true; } SetSettings::setPostMeta($listingID, $this->belongsToPromotionKey, $postID); if (($oPostAfter->post_status != $oPostBefore->post_status) || $isFocusReSetupPromotion) { $aPromotionKeys = $this->getPromotionPlanKeys(); if ($aPromotionKeys) { foreach ($aPromotionKeys as $position) { $metakey = 'promote_'.$position; FileSystem::filePutContents('promotion.txt', $isAdmin); if ($isAdmin) { $promotionKey = 'wilcity_promote_'.$position; if (isset($_POST[$promotionKey])) { SetSettings::setPostMeta($postID, $metakey, $_POST[$promotionKey]); } } else { $val = GetSettings::getPostMeta($postID, $metakey); if (!empty($val)) { SetSettings::deletePostMeta($postID, $metakey); SetSettings::setPostMeta($postID, $metakey, $val); } } } } } do_action('wiloke/promotion/approved', $listingID); } else { $this->deleteAllPlansOfListing($listingID); } SetSettings::deletePostMeta($postID, 'focus_update_listing'); } protected function getWooCommercePlanSettings($productID) { $aPromotionPlans = $this->getPromotionPlans(); foreach ($aPromotionPlans as $aPromotion) { if ($aPromotion['productAssociation'] == $productID) { return $aPromotion; } } } protected function getWooCommercePlans() { if (!empty($this->aWoocommercePlans)) { return $this->aWoocommercePlans; } $aPromotionPlans = $this->getPromotionPlans(); foreach ($aPromotionPlans as $aPromotion) { $this->aWoocommercePlans[] = $aPromotion['productAssociation']; } return $this->aWoocommercePlans; } public function cancelPostPromotion($aInfo) { $aBoostPostData = PaymentMetaModel::get($aInfo['paymentID'], 'boost_post_data'); if (empty($aBoostPostData)) { return true; } $this->decreasePostPromotion($aBoostPostData); } protected function clearExpirationPromotion($position, $postID) { wp_clear_scheduled_hook($this->generateScheduleKey($position), [$postID, $position]); wp_clear_scheduled_hook($this->generateScheduleKey($position), ["$postID", "$position"]); } public function decreasePostPromotion($aBoostPostData) { foreach ($aBoostPostData['plans'] as $aInfo) { $this->clearExpirationPromotion($aInfo['position'], $aBoostPostData['postID']); SetSettings::deletePostMeta($aBoostPostData['postID'], $aInfo['position']); } } private function updateListingPromotion($listingID, $promotionID, $isAdmin = false) { $currentListingID = GetSettings::getPostMeta($promotionID, 'listing_id'); if (!empty($currentListingID) && $listingID != $currentListingID) { $this->deleteAllPlansOfListing($currentListingID); } SetSettings::setPostMeta($listingID, $this->belongsToPromotionKey, $promotionID); $aPromotionKeys = $this->getPromotionPlanKeys(); if ($aPromotionKeys) { foreach ($aPromotionKeys as $position) { $metakey = 'promote_'.$position; if ($isAdmin) { $promotionKey = 'wilcity_promote_'.$position; if (isset($_POST[$promotionKey])) { SetSettings::setPostMeta($promotionID, $metakey, $_POST[$promotionKey]); } } else { $val = GetSettings::getPostMeta($promotionID, $metakey); if (!empty($val)) { SetSettings::setPostMeta($promotionID, $metakey, $val); } } } } do_action('wiloke/promotion/approved', $listingID); } public function updatePostPromotion($aBoostPostData) { $promotionID = GetSettings::getPostMeta($aBoostPostData['postID'], $this->belongsToPromotionKey); if (empty($promotionID)) { $promotionID = wp_insert_post([ 'post_title' => 'Promote '.get_the_title($aBoostPostData['postID']), 'post_type' => 'promotion', 'post_status' => 'draft', 'post_author' => $aBoostPostData['userID'] ]); } $aPaymentMetaInfo = PaymentMetaModel::getPaymentInfo($aBoostPostData['postID']); SetSettings::setPostMeta($promotionID, 'listing_id', $aBoostPostData['postID']); foreach ($aPaymentMetaInfo['aSelectedPlans'] as $aInfo) { SetSettings::setPostMeta( $promotionID, $this->generateListingPromoteKey($aInfo), strtotime('+ '.$aInfo['duration'].' days') ); } wp_update_post([ 'ID' => $promotionID, 'post_status' => 'publish' ]); SetSettings::setPostMeta($promotionID, 'focus_update_listing', 'yes'); return $promotionID; } private function isPromotionProduct($productID) { $aPromotionPlans = $this->getPromotionPlans(); // If $planID is not empty, which means it's Add Listing Plan Submission foreach ($aPromotionPlans as $aPromotionPlan) { if ($aPromotionPlan['productAssociation'] == $productID) { $this->aSelectedPlans[] = $aPromotionPlan; $this->aSelectedPlanKeys[] = GetSettings::generateSavingPromotionDurationKey($aPromotionPlan); return true; } } return false; } public function purchasePromotionPlansThroughWooCommerce($orderID) { $oOrder = new WC_Order($orderID); $aItems = $oOrder->get_items(); $aPromotionProductIDs = []; foreach ($aItems as $aItem) { $productID = $aItem['product_id']; if ($this->isPromotionProduct($productID)) { $aPromotionProductIDs[] = $productID; } } $oRetrieve = new RetrieveController(new AjaxRetrieve()); if (!empty($aPromotionProductIDs)) { $this->gateway = 'woocommerce'; $postID = Session::getPaymentObjectID(); $aMiddleware = ['isGatewaySupported', 'isPublishedPost']; $aStatus = $this->middleware($aMiddleware, [ 'postID' => $postID, 'gateway' => $this->gateway, 'isBoolean' => true ]); if ($aStatus['status'] == 'error') { return $oRetrieve->error($aStatus); } $this->oReceipt = ReceiptStaticFactory::get($this->category, [ 'userID' => User::getCurrentUserID(), 'couponCode' => isset($aData['couponCode']) ? $aData['couponCode'] : '', 'productID' => $aPromotionProductIDs, 'orderID' => $orderID, 'aRequested' => $_REQUEST, 'aSelectedPlanKeys' => $this->aSelectedPlanKeys, 'planName' => sprintf( esc_html__('Promote %s', 'wiloke-listing-tools'), get_the_title($postID) ), 'gateway' => $this->gateway, 'aProductIDs' => $aPromotionProductIDs ]); $this->oReceipt->setupPlan(); $aResponse = $this->createSession(); $oRetrieve = new RetrieveController(new AjaxRetrieve()); if ($aResponse['status'] != 'success') { return $oRetrieve->error($aResponse); } } } public function createPromotion($aInfo) { if (!isset($aInfo['category']) || $aInfo['category'] != $this->category) { return false; } $promotionID = GetSettings::getPostMeta($aInfo['postID'], $this->belongsToPromotionKey); if (empty($promotionID)) { $promotionID = wp_insert_post([ 'post_title' => 'Promote '.get_the_title($aInfo['postID']), 'post_type' => 'promotion', 'post_status' => 'draft', 'post_author' => $aInfo['userID'] ]); } else { wp_update_post( [ 'ID' => $promotionID, 'post_status' => 'draft' ] ); } SetSettings::setPostMeta($promotionID, 'listing_id', $aInfo['postID']); foreach ($aInfo['aSelectedPlans'] as $aPlan) { SetSettings::setPostMeta( $promotionID, $this->generateListingPromoteKey($aPlan), strtotime('+ '.$aPlan['duration'].' days') ); } PaymentMetaModel::setPromotionID($aInfo['paymentID'], $promotionID); Session::setSession('promotionID', $promotionID); do_action('wiloke/promotion/submitted', $aInfo['userID'], $aInfo['postID'], $promotionID); } public function updatePromotionAfterPaymentCompleted($aInfo) { if (!isset($aInfo['category']) || $aInfo['category'] != $this->category) { return false; } $promotionID = PaymentMetaModel::getPromotionID($aInfo['paymentID']); if (empty($promotionID)) { FileSystem::logError('We could not found promotion id of the following payment id'.$aInfo['paymentID']); return false; } $prevStatus = get_post_status($promotionID); wp_update_post([ 'ID' => $promotionID, 'post_status' => 'publish' ]); SetSettings::setPostMeta($promotionID, 'focus_update_listing', 'yes'); do_action('wilcity/wiloke-listing-tools/app/PromotionController/updatePromotionAfterPaymentCompleted', $promotionID, $prevStatus, $aInfo); return $promotionID; } public function removePromotionAfterPaymentRefunded($aInfo) { if (!isset($aInfo['category']) || $aInfo['category'] != $this->category) { return false; } $promotionID = PaymentMetaModel::getPromotionID($aInfo['paymentID']); if (!empty($promotionID)) { wp_update_post([ 'ID' => $promotionID, 'post_status' => 'trash' ]); } } /** * Using Stripe API v3: It's required in EU * * @see https://stripe.com/docs/payments/checkout/server#create-one-time-payments * @since 1.1.7.6 */ public function createSession() { $aPaymentMethod = PaymentGatewayStaticFactory::get($this->gateway, $this->isNonRecurringPayment); if ($aPaymentMethod['status'] == 'success') { return $aPaymentMethod['oPaymentMethod']->proceedPayment($this->oReceipt); } return $aPaymentMethod; } public function boostListing() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $this->gateway = isset($_POST['gateway']) && !empty($_POST['gateway']) ? $_POST['gateway'] : 'woocommerce'; $aMiddleware = ['isGatewaySupported', 'isSetupThankyouCancelUrl', 'isPublishedPost']; $status = $this->middleware($aMiddleware, [ 'postID' => $_POST['postID'], 'gateway' => $this->gateway, 'isBoolean' => true ]); if (!$status) { return $oRetrieve->error(['msg' => 'You can promote a published listing only', 'wiloke-listing-tools']); } $noPlanMsg = esc_html__('You have to select 1 plan at least', 'wiloke-listing-tools'); if (!isset($_POST['aPlans']) || empty($_POST['aPlans'])) { wp_send_json_error([ 'msg' => $noPlanMsg ]); } $aSelectedPlanKeys = []; $aSelectedPlans = []; $aPlans = []; if (is_array($_POST['aPlans'])) { $aPlans = $_POST['aPlans']; } else { if (\WilokeListingTools\Framework\Helpers\Validation::isValidJson($_POST['aPlans'])) { $aPlans = \WilokeListingTools\Framework\Helpers\Validation::getJsonDecoded(); } } if (empty($aPlans)) { wp_send_json_error([ 'msg' => $noPlanMsg ]); } foreach ($aPlans as $aPlan) { if (isset($aPlan['value']) && $aPlan['value'] == 'yes') { $aSelectedPlanKeys[] = GetSettings::generateSavingPromotionDurationKey($aPlan); $aSelectedPlans[] = $aPlan; } } if (empty($aSelectedPlanKeys)) { return $oRetrieve->error([ 'msg' => $noPlanMsg ]); } Session::setPaymentObjectID($_POST['postID']); if ($this->gateway == 'woocommerce') { $aProductIDs = []; foreach ($aSelectedPlans as $aPlan) { if (in_array(GetSettings::generateSavingPromotionDurationKey($aPlan), $aSelectedPlanKeys)) { $aProductIDs[] = $aPlan['productAssociation']; } } if (empty($aProductIDs)) { return $oRetrieve->error( [ 'msg' => esc_html__('The product id is required', 'wiloke-listing-tools') ] ); } /* * @WooCommerceController:removeProductFromCart */ do_action('wiloke-listing-tools/before-redirecting-to-cart', $aProductIDs); return $oRetrieve->success([ 'productIDs' => $aProductIDs, 'cartUrl' => wc_get_cart_url() ]); } else { $planName = sprintf( esc_html__('Promotion - %s', 'wiloke-listing-tools'), get_the_title($_POST['postID']) ); $this->oReceipt = ReceiptStaticFactory::get($this->category, [ 'userID' => User::getCurrentUserID(), 'aSelectedPlanKeys' => $aSelectedPlanKeys, 'planName' => $planName, 'gateway' => $this->gateway, 'couponCode' => '' ]); $aStatus = $this->oReceipt->setupPlan(); if ($aStatus['status'] == 'error') { return $oRetrieve->error($aStatus['msg']); } $aResponse = $this->createSession(); if ($aResponse['status'] == 'error') { return $oRetrieve->error($aResponse); } return $oRetrieve->success($aResponse); } } public function getPaymentGateways() { $oRetrieve = new RetrieveController(new AjaxRetrieve()); $aPromotions = GetSettings::getOptions('promotion_plans'); if (empty($aPromotions)) { $oRetrieve->error(['msg' => esc_html__('There is no promotion plan', 'wiloke-listing-tools')]); } foreach ($aPromotions as $aPromotion) { if (isset($aPromotion['productAssociation']) && !empty($aPromotion['productAssociation'])) { $oRetrieve->error([ 'msg' => esc_html__('It is using WooCommerce Payment Gateway', 'wiloke-listing-tools'), 'doNotShowMessage' => true ]); } } $gateways = GetWilokeSubmission::getField('payment_gateways'); if (empty($gateways)) { $oRetrieve->error([ 'msg' => esc_html__('You do not have any gateways. Please go to Wiloke Submission to set one.') ]); } $aGatewayKeys = explode(',', $gateways); $aGatewayNames = GetWilokeSubmission::getGatewaysWithName(); $aGateways = []; foreach ($aGatewayKeys as $gateway) { $aGateways[$gateway] = $aGatewayNames[$gateway]; } $oRetrieve->success($aGateways); } public function fetchPromotions() { $aPromotions = GetSettings::getPromotionPlans(); $currency = GetWilokeSubmission::getField('currency_code'); $symbol = GetWilokeSubmission::getSymbol($currency); $position = GetWilokeSubmission::getField('currency_position'); $promotionID = GetSettings::getPostMeta($_GET['postID'], $this->belongsToPromotionKey); if (!empty($promotionID) && get_post_status($promotionID) === 'publish') { $now = current_time('timestamp'); $order = 0; foreach ($aPromotions as $key => $aPlanSetting) { // Listing Sidebar without id won't display if ($aPlanSetting['position'] == 'listing_sidebar' && empty($aPlanSetting['id'])) { continue; } $aReturnPromotions[$order] = $aPlanSetting; $promotionExpiry = GetSettings::getPostMeta($promotionID, 'promote_'.$key); if (!empty($promotionExpiry)) { $promotionExpiry = abs($promotionExpiry); if ($now < $promotionExpiry) { $aReturnPromotions[$order]['isUsing'] = 'yes'; $convertHumanReadAble = Time::toDateFormat($promotionExpiry).' '.Time::toTimeFormat($promotionExpiry); $aReturnPromotions[$order]['expiry'] = sprintf( esc_html__('Your Promotion will expiry on: %s', 'wiloke-listing-tools'), $convertHumanReadAble ); } } $order++; } } else { $aReturnPromotions = array_values($aPromotions); foreach ($aReturnPromotions as $key => $aPlanSetting) { // Listing Sidebar without id won't display if ($aPlanSetting['position'] == 'listing_sidebar' && empty($aPlanSetting['id'])) { unset($aReturnPromotions[$key]); } } } $taxRate = 0; if (GetWilokeSubmission::isTax()) { $taxRate = GetWilokeSubmission::getTaxRate(); } wp_send_json_success( [ 'plans' => $aReturnPromotions, 'position' => $position, 'symbol' => $symbol, 'taxRate' => $taxRate, 'taxTitle' => GetWilokeSubmission::getTaxTitle() ] ); } }
[+]
..
[-] WebhookController.php
[edit]
[-] SetCoupon.php
[edit]
[-] TermController.php
[edit]
[-] PostController.php
[edit]
[-] SetMyPosts.php
[edit]
[-] NotificationsController.php
[edit]
[-] AjaxUploadImgController.php
[edit]
[-] TaxonomiesControllers.php
[edit]
[-] FavoriteStatisticController.php
[edit]
[-] BelongsToCustomTaxonomies.php
[edit]
[-] DashboardController.php
[edit]
[-] ModifyQueryController.php
[edit]
[-] SetCustomGroup.php
[edit]
[+]
Map
[-] TraitHostedBy.php
[edit]
[-] SearchFormController.php
[edit]
[-] InsertFeaturedImg.php
[edit]
[-] PaymentGatewaysController.php
[edit]
[-] PaymentController.php
[edit]
[-] DokanController.php
[edit]
[-] SchemaController.php
[edit]
[-] UserController.php
[edit]
[-] BelongsToLocation.php
[edit]
[-] WooCommerceBookingController.php
[edit]
[-] IsMyPaymentID.php
[edit]
[-] StripeController.php
[edit]
[-] ContactFormController.php
[edit]
[-] AddListingButtonController.php
[edit]
[-] Validation.php
[edit]
[-] GalleryController.php
[edit]
[-] SetListingRelationship.php
[edit]
[-] AddListingController.php
[edit]
[-] MergingSettingValues.php
[edit]
[-] GoogleReCaptchaController.php
[edit]
[-] CouponController.php
[edit]
[-] InvoiceController.php
[edit]
[-] SingleJsonSkeleton.php
[edit]
[-] SingleController.php
[edit]
[-] InsertImg.php
[edit]
[-] EmailController.php
[edit]
[-] BelongsToCategories.php
[edit]
[-] ReviewController.php
[edit]
[-] SetSinglePrice.php
[edit]
[-] PrintSidebarItems.php
[edit]
[-] SetPlanRelationship.php
[edit]
[-] BookingComController.php
[edit]
[-] WooCommerceController.php
[edit]
[-] FacebookLoginController.php
[edit]
[-] EventController.php
[edit]
[-] SetRestaurantMenu.php
[edit]
[-] SetProductsToListing.php
[edit]
[-] UserPlanController.php
[edit]
[-] FollowController.php
[edit]
[+]
Retrieve
[-] SetGeneral.php
[edit]
[-] VerifyPurchaseCode.php
[edit]
[-] PlanRelationshipController.php
[edit]
[-] FreePlanController.php
[edit]
[-] AddBookingComBannerCreator.php
[edit]
[-] ReportController.php
[edit]
[-] RetrieveController.php
[edit]
[-] SetCustomButton.php
[edit]
[-] GetWilokeToolSettings.php
[edit]
[-] PaymentMetaController.php
[edit]
[-] RegisterLoginController.php
[edit]
[-] TermsAndPolicyController.php
[edit]
[-] AppleLoginController.php
[edit]
[-] ChangePlanStatusController.php
[edit]
[-] NextBillingPaymentController.php
[edit]
[-] AddListingPaymentController.php
[edit]
[-] PromotionController.php
[edit]
[-] PrintAddListingSettings.php
[edit]
[-] PayPalExecuteAddListingPayment.php
[edit]
[-] ClaimController.php
[edit]
[-] ViewStatisticController.php
[edit]
[-] SessionController.php
[edit]
[-] SharesStatisticController.php
[edit]
[-] TraitSetEventData.php
[edit]
[-] PrintAddListingFields.php
[edit]
[-] GuardController.php
[edit]
[+]
TransformAddListingData
[-] MessageController.php
[edit]
[-] OptimizeScripts.php
[edit]
[-] InsertLogo.php
[edit]
[-] SetPostDuration.php
[edit]
[-] GridItemController.php
[edit]
[-] SetVideo.php
[edit]
[-] AddMorePhotosVideosController.php
[edit]
[-] TraitAddListingSettings.php
[edit]
[-] InsertGallery.php
[edit]
[-] BillingControllers.php
[edit]
[-] GetSingleImage.php
[edit]
[-] BelongsToTags.php
[edit]
[-] PermalinksController.php
[edit]
[-] RunUpdateDBToLatestVersionController.php
[edit]
[-] SetListingBelongsToPlanID.php
[edit]
[-] NoticeController.php
[edit]
[-] DirectBankTransferController.php
[edit]
[-] SetPriceRange.php
[edit]
[-] TagsBelongsToCatController.php
[edit]
[-] PayPalController.php
[edit]
[-] InsertAddress.php
[edit]
[-] MapListingController.php
[edit]
[-] ListingController.php
[edit]
[-] AuthorPageController.php
[edit]
[-] RestaurantMenuController.php
[edit]
[-] PaymentStatusController.php
[edit]
[-] SetSocialNetworks.php
[edit]
[-] SetCustomSections.php
[edit]
[-] TranslationController.php
[edit]
[-] IconController.php
[edit]
[-] SetGroupData.php
[edit]
[-] SetContactInfo.php
[edit]
[-] ProfileController.php
[edit]
[-] ShareController.php
[edit]
[-] InsertCoverImage.php
[edit]
[-] HandleSubmit.php
[edit]
[-] SetMyRoom.php
[edit]
[-] ModalController.php
[edit]