PATH:
home
/
letacommog
/
laindinois
/
wp-content
/
plugins
/
wiloke-listing-tools
/
app
/
Framework
/
Payment
/
Stripe
<?php namespace WilokeListingTools\Framework\Payment\Stripe; use Exception; use Stripe\Subscription; use WilokeListingTools\Framework\Payment\AbstractSuspend; use WilokeListingTools\Framework\Payment\Billable; use WilokeListingTools\Framework\Payment\Checkout; use WilokeListingTools\Framework\Payment\Receipt; use WilokeListingTools\Framework\Payment\StripePayment; use WilokeListingTools\Framework\Store\Session; use WilokeListingTools\Frontend\User; use WilokeListingTools\Models\PaymentMetaModel; use WilokeListingTools\Models\PaymentModel; class StripeChangePlan extends StripePayment { protected $newPaymentID; protected $userID; private $currentAgreementID; private $token; private $email; public function __construct( $userID, $currentPaymentID, $newPlanID, $currentPlanID, $listingType, $token = '', $email = '') { $this->userID = $userID; $this->currentPaymentID = $currentPaymentID; $this->newPlanID = $newPlanID; $this->listingType = $listingType; $this->currentPlanID = $currentPlanID; $this->token = $token; $this->email = $email; } private function suspendCurrentPlan() { $this->setPaymentID($this->currentPaymentID); return $this->suspend(); } private function reactivate($subscriptionID, $paymentID) { if (empty($subscriptionID)) { $subscriptionID = PaymentMetaModel::get($this->currentPaymentID, wilokeListingToolsRepository()->get('payment:stripeSubscriptionID')); } if (empty($subscriptionID)) { return false; } try { $oSubscription = Subscription::retrieve($subscriptionID); $oSubscription->coupon = null; // <= It's very important, We will get rid of Free Forever Coupon From this plan $oSubscription->save(); PaymentModel::updatePaymentStatus('active', $paymentID); return true; } catch (Exception $oE) { return false; } } private function maybeReactivatePlan() { $this->newPaymentID = PaymentModel::getLastSuspendedByPlan($this->newPlanID, $this->userID); if (empty($this->newPaymentID)) { return false; } $subscriptionID = PaymentMetaModel::get($this->newPaymentID, wilokeListingToolsRepository()->get('payment:stripeSubscriptionID')); if (empty($subscriptionID)) { return false; } return $this->reactivate($subscriptionID, $this->newPaymentID); } private function changedPlan() { /* * UserPlanController@changeUserPlan */ do_action('wiloke-listing-tools/on-changed-user-plan', [ 'userID' => User::getCurrentUserID(), 'paymentID' => $this->newPaymentID, 'oldPaymentID' => $this->currentPaymentID, 'oldPlanID' => $this->currentPlanID, 'listingType' => $this->listingType, 'planID' => $this->newPlanID, 'gateway' => 'stripe', 'billingType' => wilokeListingToolsRepository()->get('payment:billingTypes', true)->sub('recurring') ]); } public function execute() { $this->setApiContext(); $isPassedSuspended = $this->suspendCurrentPlan(); if (!$isPassedSuspended) { return [ 'success' => false, 'msg' => esc_html__('We could not suspend the current plan', 'wiloke-listing-tools') ]; } $isReactivated = $this->maybeReactivatePlan(); // If we could not renew the plan, We will create new one if (!$isReactivated) { new Billable([ 'gateway' => $this->gateway, 'planID' => $this->newPlanID, 'listingType' => $this->listingType ]); $aReceiptInfo = [ 'planID' => $this->newPlanID, 'userID' => User::getCurrentUserID(), 'couponCode' => '', 'isNonRecurringPayment' => false ]; if (!empty($this->token)) { $aReceiptInfo['aRequested'] = [ 'token' => $this->token, 'email' => $this->email, ]; } $oReceipt = new Receipt($aReceiptInfo); $oReceipt->setupPlan(); $oPaymentMethod = new StripeRecurringPaymentMethod(); /* * Set sessions that needed for change plan * * @var newPlanID * @var listingType * @var currentPlanID */ $this->setSessions(); $oCheckout = new Checkout(); $aCheckAcceptPaymentStatus = $oCheckout->begin($oReceipt, $oPaymentMethod); if ($aCheckAcceptPaymentStatus['status'] == 'success') { $this->newPaymentID = $aCheckAcceptPaymentStatus['paymentID']; $this->changedPlan(); return [ 'status' => 'success', 'msg' => esc_html__('Congratulations! Your plan has been updated successfully.', 'wiloke-listing-tools') ]; } else { $status = $this->reactivate($this->currentAgreementID, $this->currentPaymentID); if (!$status) { return [ 'status' => 'error', 'msg' => esc_html__('We could not upgrade to the new plan. We changed the current plan to Suspend status. Please log into your Stripe and reactivate it manually.', 'wiloke-listing-tools') ]; } else { return [ 'status' => 'error', 'suspendedOldPlan' => true, 'msg' => esc_html__('We could not upgrade to the new plan.', 'wiloke-listing-tools') ]; } } } else { $this->changedPlan(); return [ 'status' => 'success', 'msg' => sprintf(esc_html__('Congratulations! The %s has been reactivated successfully.', 'wiloke-listing-tools'), get_the_title($this->newPlanID)) ]; } } }
[+]
..
[-] StripeChangePlan.php
[edit]
[-] StripeNonRecurringCreatedPaymentHook.php
[edit]
[-] StripeUpdatePlan.php
[edit]
[-] StripeRecurringCreatedPaymentHook.php
[edit]
[-] WebhookLog.php
[edit]
[-] StripeRecurringPrepareInvoiceFormat.php
[edit]
[-] StripeSuspendPlan.php
[edit]
[-] StripeWebhook.php
[edit]
[-] StripeNonRecurringIPreparenvoiceFormat.php
[edit]
[-] StripeProceededNonRecurringPaymentHook.php
[edit]
[-] StripeSCARecurringPaymentMethod.php
[edit]
[-] StripeConfiguration.php
[edit]
[-] StripeCancelRecurringPayment.php
[edit]
[-] StripeRefundNonRecurringPayment.php
[edit]
[-] Webhook.php
[edit]
[-] StripeTax.php
[edit]
[-] StripeWebhookInterface.php
[edit]
[-] StripeRecurringPaymentMethod.php
[edit]
[-] StripeProceededRecurringPayment.php
[edit]
[-] StripeSCANonRecurringPaymentMethod.php
[edit]
[-] StripeNonRecurringPaymentMethod.php
[edit]