Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -37,6 +37,8 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$_SESSION['cart'] = array();
|
||||
\IPS\Request::i()->setCookie( 'currency', \IPS\Request::i()->currency );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=subscriptions&controller=subscriptions', 'front', 'nexus_subscriptions' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +59,12 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
|
||||
/* Create the table */
|
||||
$table = new \IPS\nexus\Subscription\Table( \IPS\Http\Url::internal( 'app=nexus&module=subscriptions&controller=subscriptions', 'front', 'nexus_subscriptions' ) );
|
||||
$table->activeSubscription = \IPS\nexus\Subscription::loadByMember( \IPS\Member::loggedIn(), FALSE );
|
||||
$current = \IPS\nexus\Subscription::loadByMember( \IPS\Member::loggedIn(), FALSE );
|
||||
|
||||
if ( $current AND ( !$current->purchase OR !$current->purchase->cancelled OR $current->purchase->can_reactivate ) )
|
||||
{
|
||||
$table->activeSubscription = $current;
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->purchased ) and $table->activeSubscription )
|
||||
{
|
||||
@@ -118,12 +125,15 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
|
||||
/* Fetch purchase */
|
||||
$purchase = NULL;
|
||||
foreach ( \IPS\nexus\extensions\nexus\Item\Subscription::getPurchases( \IPS\nexus\Customer::loggedIn(), $subscription->package->id ) as $row )
|
||||
if( $subscription )
|
||||
{
|
||||
if ( $row->active and ! $row->cancelled )
|
||||
foreach ( \IPS\nexus\extensions\nexus\Item\Subscription::getPurchases( \IPS\nexus\Customer::loggedIn(), $subscription->package->id ) as $row )
|
||||
{
|
||||
$purchase = $row;
|
||||
break;
|
||||
if ( $row->active and ! $row->cancelled )
|
||||
{
|
||||
$purchase = $row;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,8 +172,8 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
/* CSRF Check */
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Already purchased a subscription? */
|
||||
if ( \IPS\nexus\Subscription::loadByMember( \IPS\nexus\Customer::loggedIn(), FALSE ) )
|
||||
/* Already purchased a subscription which was not cancelled? */
|
||||
if ( $current = \IPS\nexus\Subscription::loadByMember( \IPS\nexus\Customer::loggedIn(), FALSE ) AND ( $current->purchase AND !$current->cancelled AND ( !$current->purchase->cancelled OR $current->purchase->can_reactivate ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'nexus_subs_already_got_package', '2X379/6', 403, '' );
|
||||
}
|
||||
@@ -235,7 +245,7 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
\IPS\Output::i()->error( 'nexus_no_subs_subs', '2X379/8', 404, '' );
|
||||
}
|
||||
$purchase = NULL;
|
||||
foreach ( \IPS\nexus\extensions\nexus\Item\Subscription::getPurchases( \IPS\nexus\Customer::loggedIn(), $subscription->package->id ) as $row )
|
||||
foreach ( \IPS\nexus\extensions\nexus\Item\Subscription::getPurchases( \IPS\nexus\Customer::loggedIn(), $subscription->package->id, TRUE, TRUE ) as $row )
|
||||
{
|
||||
if ( $row->can_reactivate )
|
||||
{
|
||||
@@ -256,9 +266,10 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
$purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $purchase->id, 'name' => $purchase->name, 'info' => 'change_renewals', 'to' => array( 'cost' => $purchase->renewals->cost->amount, 'currency' => $purchase->renewals->cost->currency, 'term' => $purchase->renewals->getTerm() ) ) );
|
||||
|
||||
/* Either send to renewal invoice or just back to subscriptions list */
|
||||
if ( !$purchase->active and $purchase->canRenewUntil() !== FALSE )
|
||||
if ( !$purchase->active and $cycles = $purchase->canRenewUntil( NULL, TRUE ) AND $cycles !== FALSE )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $purchase->url()->setQueryString( 'do', 'renew' )->csrf() );
|
||||
$url = $cycles === 1 ? $purchase->url()->setQueryString( 'do', 'renew' )->csrf() : $purchase->url()->setQueryString( 'do', 'renew' );
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -266,4 +277,45 @@ class _subscriptions extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel an expired subscription so that we can purchase another subscription
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
/* CSRF Check */
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'nexus_no_subs_package', '2X379/8', 404, '' );
|
||||
}
|
||||
try
|
||||
{
|
||||
$subscription = \IPS\nexus\Subscription::loadByMemberAndPurchase( \IPS\Member::loggedIn(), $purchase, FALSE );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'nexus_no_subs_subs', '2X379/9', 404, '' );
|
||||
}
|
||||
|
||||
if( !$subscription->canCancel() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'no_module_permission', '1X379/A', 403, '' );
|
||||
}
|
||||
|
||||
foreach ( \IPS\nexus\extensions\nexus\Item\Subscription::getPurchases( \IPS\nexus\Customer::loggedIn(), $subscription->package->id, TRUE, TRUE ) as $row )
|
||||
{
|
||||
$row->cancelled = TRUE;
|
||||
$row->save();
|
||||
}
|
||||
$subscription->cancelled = TRUE;
|
||||
$subscription->save();
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=subscriptions&controller=subscriptions', 'front', 'nexus_subscriptions' ), 'cancelled' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user