PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; 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\Routing\Controller; use WilokeListingTools\Framework\Store\Session; use WilokeListingTools\Frontend\User; use WilokeListingTools\Models\PaymentMetaModel; use WilokeListingTools\Models\PaymentModel; use WilokeListingTools\Models\UserModel; class UserPlanController extends Controller { public function __construct() { add_filter('get_avatar', [$this, 'wilcityAvatar'], 1, 5); // Firebase //Update UserModel $aBillingTypes = wilokeListingToolsRepository()->get('payment:billingTypes', false); foreach ($aBillingTypes as $billingType) { add_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-completed', [$this, 'updateUserPlan'], 5); add_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-refunded', [$this, 'deleteUserPlan'], 5); } add_action('wilcity/wiloke-listing-tools/RecurringPayment/stripe/payment-completed', [$this, 'setStripeCustomerID']); add_action( 'wilcity/wiloke-listing-tools/NonRecurringPayment/payment-dispute', [$this, 'lockAddListingBecausePaymentDispute'], 10 ); add_action('wilcity/wiloke-listing-tools/updated-plan-relationship', [$this, 'updateRemainingItems'], 10, 2); add_action('wilcity/wiloke-listing-tools/added-plan-relationship', [$this, 'updateRemainingItems'], 10, 2); add_action('wilcity/wiloke-listing-tools/deleted-plan-relationship', [$this, 'updateRemainingItems'], 10, 2); // add_action('init', [$this, 'fixUserPlanIssue']); } public function setStripeCustomerID($aInfo) { if (!isset($aInfo['stripeCustomerID']) || empty($aInfo['stripeCustomerID'])) { FileSystem::logError('We could not set stripe customer id'); } UserModel::setStripeID($aInfo['stripeCustomerID'], $aInfo['userID']); FileSystem::logSuccess('Inserted Stripe Customer ID. Stripe Customer:'.$aInfo['stripeCustomerID'].' UserID'. $aInfo['userID']); } private function lockedAddListing($userID, $aDetails) { SetSettings::setUserMeta($userID, 'locked_addlisting', $aDetails['reason']); unset($aDetails['reason']); SetSettings::setUserMeta($userID, 'locked_addlisting_reason', $aDetails); FileSystem::logSuccess('Payment: Locked Add Listing. Details: '.json_encode($aDetails)); } public function lockAddListingBecausePaymentDispute($aInfo) { $userID = PaymentModel::getField('userID', $aInfo['paymentID']); $aData['reason'] = 'payment_dispute'; $aData['paymentID'] = $aInfo['paymentID']; $this->lockedAddListing($userID, $aData); } /** * @param $aInfo * @param bool $mustUpdate * * @return bool */ public function updateRemainingItems($aInfo, $logIfError = false) { if (!isset($aInfo['userID']) || empty($aInfo['userID'])) { if ($logIfError) { FileSystem::logError('We could not update remaining items because the user id was emptied', __CLASS__, __METHOD__); } return false; } if (!isset($aInfo['planID']) || empty($aInfo['planID'])) { if ($logIfError) { FileSystem::logError('We could not update remaining items because the user plan was emptied', __CLASS__, __METHOD__); } return false; } $instUserModel = new UserModel(); $instUserModel->updateRemainingItemsUserPlan($aInfo['planID'], $aInfo['userID'], $logIfError); } public function deleteUserPlan($aInfo) { if (!isset($aInfo['paymentID']) || empty($aInfo['paymentID'])) { FileSystem::logError('The payment id is required', __CLASS__, __METHOD__); return false; } $aPaymentMetaInfo = PaymentMetaModel::getPaymentInfo($aInfo['paymentID']); if (!isset($aPaymentMetaInfo['category']) || !in_array($aPaymentMetaInfo['category'], [ 'addlisting', 'paidClaim' ]) ) { return false; } $instUserModel = new UserModel(); $userID = PaymentModel::getField('userID', $aInfo['paymentID']); $instUserModel->setUserID($userID) ->setPaymentID($aInfo['paymentID']) ->setPlanID(PaymentModel::getField('planID', $aInfo['paymentID'])); $status = $instUserModel->removeUserPlan(); } public function updateUserPlan($aInfo) { if ($aInfo['status'] !== 'succeeded' && $aInfo['status'] !== 'active') { return false; } if (!isset($aInfo['paymentID']) || empty($aInfo['paymentID'])) { FileSystem::logError('The payment id is required', __CLASS__, __METHOD__); return false; } $aPaymentMetaInfo = PaymentMetaModel::getPaymentInfo($aInfo['paymentID']); if (!isset($aPaymentMetaInfo['category']) || !in_array($aPaymentMetaInfo['category'], [ 'addlisting', 'paidClaim' ]) ) { return false; } if (!isset($aPaymentMetaInfo['postID']) || empty($aPaymentMetaInfo['postID'])) { FileSystem::logError('The post ID id is required', __CLASS__, __METHOD__); return false; } $userID = PaymentModel::getField('userID', $aInfo['paymentID']); $aPaymentInfo = PaymentModel::getPaymentInfo($aInfo['paymentID']); if (empty($aPaymentInfo)) { FileSystem::logError(sprintf( 'The payment %s does not exist', __CLASS__, __METHOD__, $aInfo['paymentID'] )); return false; } $instUserModel = new UserModel(); $aPostIDs = explode(',', $aPaymentMetaInfo['postID']); $postType = get_post_type($aPostIDs[0]); $instUserModel->setUserID($userID) ->setBillingType($aPaymentInfo['billingType']) ->setGateway($aPaymentInfo['gateway']) ->setPaymentID($aPaymentInfo['ID']) ->setPlanID($aPaymentInfo['planID']) ->setPostType($postType) ; if (!GetWilokeSubmission::isNonRecurringPayment($aPaymentInfo['billingType'])) { $instUserModel->setNextBillingDateGMT($aInfo['nextBillingDateGMT']); } $isPassed = $this->middleware(['validateBeforeSetUserPlan'], [ 'instUserModel' => $instUserModel, 'billingType' => $aInfo['billingType'], 'isBoolean' => true ]); if (!$isPassed) { FileSystem::logError( 'We could not update user plan because the info wont passed validation. '.json_encode($aInfo), __CLASS__, __METHOD__ ); return false; } $status = $instUserModel->setUserPlan(); if (!$status) { FileSystem::logError('We could not set User Plan', __CLASS__, __METHOD__); return false; } FileSystem::logSuccess('Update User Plan - UserID: '.$userID.' Payment Info: '.json_encode($aPaymentInfo)); } public function fixUserPlanIssue() { if (!is_user_logged_in()) { return false; } $userID = get_current_user_id(); $fixKey = 'fixed_user_plan_v2_'.$userID; if (GetSettings::getOptions($fixKey)) { return false; } $aAllPlans = UserModel::getAllPlans($userID); if (empty($aAllPlans)) { SetSettings::setOptions($fixKey, true); return false; } SetSettings::setUserMeta($userID, 'backup_userplan', $aAllPlans); $aRebuildPlans = []; foreach ($aAllPlans as $planType => $aPlans) { foreach ($aPlans as $planID => $aPlanInfo) { if (!isset($aPlanInfo['postType']) || empty($aPlanInfo['postType'])) { continue; } $aRebuildPlans[get_post_type($planID)][$planID] = $aPlanInfo; // $aRebuildPlans[$aPlanInfo['postType'].'_plan'][$planID] = $aPlanInfo; } } if (!empty($aRebuildPlans)) { SetSettings::setUserMeta($userID, wilokeListingToolsRepository()->get('user:userPlans'), $aRebuildPlans); } SetSettings::setOptions($fixKey, true); } public function wilcityAvatar($avatar, $id_or_email, $size, $default, $alt) { if (is_object($id_or_email)) { if (!empty($id_or_email->user_id)) { $id = (int)$id_or_email->user_id; } } else if (!is_numeric($id_or_email)) { $user = get_user_by('email', $id_or_email); if (!empty($user)) { $id = $user->user_id; } } else { $id = $id_or_email; } if (isset($id)) { $url = GetSettings::getUserMeta($id, 'avatar'); if (!empty($url)) { $avatar = "<img alt='{$alt}' src='{$url}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; } } return $avatar; } }
[+]
..
[-] 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]