Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

@@ -54,6 +54,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
if ( !$billingAgreement->canceled and $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
{
$billingAgreement->canceled = TRUE;
$billingAgreement->next_cycle = NULL;
$billingAgreement->save();
}
}
@@ -60,6 +60,11 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
{
$requireBillingOptions['domain'] = 'nexus_require_billing_domain';
}
if ( \IPS\Settings::i()->nexus_subs_enabled and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscription_packages' )->first() )
{
$requireBillingOptions['subscriptions'] = 'nexus_require_billing_subscriptions';
}
$requireBillingOptions['other'] = 'nexus_require_billing_other';
@@ -138,6 +138,11 @@ class _gateways extends \IPS\Node\Controller
$values = $obj->formatFormValues( $values );
$obj->settings = json_encode( $settings );
$obj->countries = $values['countries'];
if( isset( $values['validationfile'] ) )
{
$obj->validationfile = $values['validationfile'];
}
$obj->save();
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $name );
@@ -560,7 +560,11 @@ class _shipping extends \IPS\Dispatcher\Controller
$shipment->delete();
/* Log */
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'deleted' => TRUE ) );
try
{
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'deleted' => TRUE ) );
}
catch ( \OutOfRangeException $e ) {}
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
@@ -53,14 +53,14 @@ class _shippingrates extends \IPS\Node\Controller
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'ship_rates_' . \IPS\Request::i()->type, array(
'ship_rates_go_back' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=shippingrates&do=form&id=' . \IPS\Request::i()->id ),
'ship_rates_save_anyway' => \IPS\Http\Url::internal( $this->url ),
'ship_rates_save_anyway' => $this->url,
) );
}
/**
* Redirect after save
*
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
* @param \IPS\Node\Model|NULL $old A clone of the node as it was before or NULL if this is a creation
* @param \IPS\Node\Model $new The node now
* @param string $lastUsedTab The tab last used in the form
* @return void
@@ -63,13 +63,13 @@ class _income extends \IPS\Dispatcher\Controller
{
foreach ( $currencies as $currency )
{
$tabs[ 'members_' . $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income_by_member', NULL, array( 'sprintf' => array( $currency ) ) );
$tabs[ 'members_' . $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income_by_member', FALSE, array( 'sprintf' => array( $currency ) ) );
}
}
foreach ( $currencies as $currency )
{
$tabs[ $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income_by_method', NULL, array( 'sprintf' => array( $currency ) ) );
$tabs[ $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income_by_method', FALSE, array( 'sprintf' => array( $currency ) ) );
}
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'totals';
@@ -54,7 +54,7 @@ class _markets extends \IPS\Dispatcher\Controller
$tabs['count'] = 'nexus_report_count';
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
$tabs[ $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income', NULL, array( 'sprintf' => array( $currency ) ) );
$tabs[ $currency ] = \IPS\Member::loggedIn()->language()->addToStack( 'nexus_report_income', FALSE, array( 'sprintf' => array( $currency ) ) );
}
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'count';
@@ -277,6 +277,7 @@ class _packages extends \IPS\Node\Controller
{
if ( isset( $changes['renew_options'] ) )
{
\IPS\Output::i()->bypassCsrfKeyCheck = TRUE;
$matrix = new \IPS\Helpers\Form\Matrix( 'matrix', 'continue' );
$matrix->manageable = FALSE;
@@ -432,10 +433,15 @@ class _packages extends \IPS\Node\Controller
'processing'=> 1,
'ba' => isset( \IPS\Request::i()->ba ) ? \IPS\Request::i()->ba : 0
) )->csrf(),
function( $offset ) use ( $package, $changes )
function( $data ) use ( $package, $changes )
{
$offset = \intval( $offset );
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'package', $package->id ), 'ps_id', array( $offset, 1 ) );
if( !\is_array( $data ) )
{
$data['offset'] = 0;
$data['lastId'] = 0;
}
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_id>? and ps_app=? and ps_type=? and ps_item_id=?", $data['lastId'], 'nexus', 'package', $package->id ), 'ps_id', 1 );
try
{
@@ -444,7 +450,7 @@ class _packages extends \IPS\Node\Controller
$package->updatePurchase( $purchase, $changes, \IPS\Request::i()->ba );
return array( ++$offset, \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $offset );
return array( [ 'offset' => ++$data['offset'], 'lastId' => $purchase->id ], \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $data['offset'] );
}
catch ( \UnderflowException $e )
{
@@ -145,30 +145,6 @@ class _subscribers extends \IPS\Dispatcher\Controller
\IPS\Output::i()->output = (string) $table;
}
/**
* Remove a manually added member
*
* @return void
*/
protected function remove()
{
\IPS\Session::i()->csrfCheck();
try
{
$sub = \IPS\nexus\Subscription::load( \IPS\Request::i()->id );
$package = \IPS\nexus\Subscription\Package::load( $sub->package_id );
$customer = \IPS\nexus\Customer::load( $sub->member_id );
$package->removeMember( $customer );
\IPS\Output::i()->redirect( $customer->acpUrl(), 'nexus_sub_member_removed' );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'nexus_sub_no_invoice', '2X378/1', 404, '' );
}
}
/**
* Find an purchase and redirect to it.
*
@@ -309,24 +309,53 @@ class _subscriptions extends \IPS\Node\Controller
{
if ( $val instanceof \IPS\Member )
{
try
$sub = \IPS\nexus\Subscription::loadByMember( $val, false );
/* We have cannot have duplicate active subscriptions, so error out */
if( $sub !== NULL )
{
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
$sub = \IPS\nexus\Subscription::loadByMemberAndPackage( $val, $package, TRUE );
/* We have cannot have duplicate active subscriptions, so error out */
throw new \InvalidArgumentException('nexus_subs_add_member_already_subscribed');
}
catch( \OutOfRangeException $e )
{
/* Nothing found, so that's all lovely and good */
throw new \InvalidArgumentException( 'nexus_subs_add_member_already_subscribed' );
}
}
}, NULL, NULL, 'nexus_subs_member_to_add' ) );
$package = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id );
if( $term = $package->renewalTerm() )
{
$newOption = json_decode( $package->renew_options, TRUE );
$costs = array();
foreach ( $newOption['cost'] as $data )
{
$costs[] = new \IPS\nexus\Money( $data['amount'], $data['currency'] );
}
switch ( $newOption['unit'] )
{
case 'd':
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_days', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
break;
case 'm':
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_months', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
break;
case 'y':
$term = \IPS\Member::loggedIn()->language()->addToStack('renew_years', FALSE, array( 'pluralize' => array( $newOption['term'] ) ) );
break;
}
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_free_period', NULL, TRUE, [
'options' => [
0 => 'nexus_subs_forever',
1 => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_until_renew', FALSE, [ 'sprintf' => [ $newOption['term'], $term, \IPS\Member::loggedIn()->language()->formatList( $costs, \IPS\Member::loggedIn()->language()->get('or_list_format') ), $term ] ] )
]
] ) );
}
if ( $values = $form->values() )
{
$sub = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id )->addMember( $values['nexus_subs_member_to_add'] );
$customer = \IPS\nexus\Customer::load( $values['nexus_subs_member_to_add']->member_id );
$sub = \IPS\nexus\Subscription\Package::load( \IPS\Request::i()->id )->addMember( $customer, TRUE, (bool) $values['nexus_subs_free_period'] );
$sub->added_manually = 1;
$sub->save();
@@ -334,7 +363,7 @@ class _subscriptions extends \IPS\Node\Controller
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('nexus_subs_add_member');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'subscription', 'nexus' )->addMemberMessage( $form );
\IPS\Output::i()->output = $form;
}
/**
@@ -349,14 +378,20 @@ class _subscriptions extends \IPS\Node\Controller
{
$groups[ $group->g_id ] = $group->name;
}
$form = new \IPS\Helpers\Form;
$form->addHeader('subscription_basic_settings');
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_enabled', \IPS\Settings::i()->nexus_subs_enabled, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_enabled' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_register', \IPS\Settings::i()->nexus_subs_register, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_register' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_subs_register', (int) \IPS\Settings::i()->nexus_subs_register, FALSE, [
'options' => [
0 => 'nexus_subs_register_none',
1 => 'nexus_subs_register_reg',
2 => 'nexus_subs_register_always'
]
], NULL, NULL, NULL, 'nexus_subs_register' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_subs_show_public', \IPS\Settings::i()->nexus_subs_show_public, FALSE, array(), NULL, NULL, NULL, 'nexus_subs_show_public' ) );
$form->add( new \IPS\Helpers\Form\Interval( 'nexus_subs_invoice_grace', \IPS\Settings::i()->nexus_subs_invoice_grace ?: 0, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'min' => NULL ), NULL, NULL, NULL, 'nexus_subs_invoice_grace' ) );
$form->add( new \IPS\Helpers\Form\Interval( 'nexus_subs_invoice_grace', \IPS\Settings::i()->nexus_subs_invoice_grace ?: 0, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS ), NULL, NULL, NULL, 'nexus_subs_invoice_grace' ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_subs_exclude_groups', explode( ',', \IPS\Settings::i()->nexus_subs_exclude_groups ), FALSE, array( 'options' => $groups, 'multiple' => TRUE ) ) );
@@ -392,7 +427,7 @@ class _subscriptions extends \IPS\Node\Controller
}
$values['nexus_subs_exclude_groups'] = implode( ',', $values['nexus_subs_exclude_groups'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplog__nexus_subs_settings' );
@@ -472,6 +507,7 @@ class _subscriptions extends \IPS\Node\Controller
{
if ( isset( $changes['renew_options'] ) )
{
\IPS\Output::i()->bypassCsrfKeyCheck = TRUE;
$matrix = new \IPS\Helpers\Form\Matrix( 'matrix', 'continue' );
$matrix->manageable = FALSE;
@@ -606,10 +642,15 @@ class _subscriptions extends \IPS\Node\Controller
'processing'=> 1,
'ba' => isset( \IPS\Request::i()->ba ) ? \IPS\Request::i()->ba : 0
) )->csrf(),
function( $offset ) use ( $package, $changes )
function( $data ) use ( $package, $changes )
{
$offset = \intval( $offset );
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'subscription', $package->id ), 'ps_id', array( $offset, 1 ) );
if( !\is_array( $data ) )
{
$data['offset'] = 0;
$data['lastId'] = 0;
}
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_id>? and ps_app=? and ps_type=? and ps_item_id=?", $data['lastId'], 'nexus', 'subscription', $package->id ), 'ps_id', 1 );
try
{
@@ -617,8 +658,8 @@ class _subscriptions extends \IPS\Node\Controller
$total = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( "ps_app=? and ps_type=? and ps_item_id=?", 'nexus', 'subscription', $package->id ) )->first();
$package->updatePurchase( $purchase, $changes, \IPS\Request::i()->ba );
return array( ++$offset, \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $offset );
return array( [ 'offset' => ++$data['offset'], 'lastId' => $purchase->id ], \IPS\Member::loggedIn()->language()->get('processing'), 100 / $total * $data['offset'] );
}
catch ( \UnderflowException $e )
{
@@ -622,7 +622,8 @@ class _checkout extends \IPS\Dispatcher\Controller
'spamData' => array( 'code' => $spamCode, 'action' => $spamAction ),
'guestTransactionKey' => \IPS\Request::i()->cookie['guestTransactionKey'],
'pbr' => $postBeforeRegister ? $postBeforeRegister['secret'] : NULL,
'referred_by' => isset( \IPS\Request::i()->cookie['referred_by'] ) ? \IPS\Request::i()->cookie['referred_by'] : NULL
'referred_by' => isset( \IPS\Request::i()->cookie['referred_by'] ) ? \IPS\Request::i()->cookie['referred_by'] : NULL,
'agreed_terms' => ( bool ) $values['reg_agreed_terms']
);
}
}
@@ -751,19 +752,6 @@ class _checkout extends \IPS\Dispatcher\Controller
{
if ( $success = $login->authenticate() )
{
/* Verify it's okay for this member to be buying those items */
try
{
foreach ( $this->invoice->items as $item )
{
$item->memberCanPurchase( $success->member );
}
}
catch ( \DomainException $e )
{
\IPS\Output::i()->error( $e->getMessage(), '1X196/B', 403, '' );
}
/* Process the login */
if ( $success->mfa() )
{
@@ -1168,10 +1156,23 @@ class _checkout extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( 'err_no_methods', '5X196/8', 500, '' );
}
/* Verify stock level one last time. It's possible someone added an item to their cart, then someone else did and checked out and the stock level is now 0. */
foreach ( $this->invoice->items as $item )
{
if( $item->appKey == 'nexus' AND $item->typeKey == 'package' )
/* Verify whether we're allowed to purchase this */
if( \IPS\Member::loggedIn()->member_id )
{
try
{
$item->memberCanPurchase( \IPS\Member::loggedIn() );
}
catch ( \DomainException $e )
{
\IPS\Output::i()->error( $e->getMessage(), '2X196/H', 403, '' );
}
}
/* Verify stock level one last time. It's possible someone added an item to their cart, then someone else did and checked out and the stock level is now 0. */
if( $item instanceof IPS\nexus\extensions\nexus\Item\Package )
{
$package = \IPS\nexus\Package::load( $item->id );
$data = $package->optionValuesStockAndPrice( $package->optionValues( $item->details ) );
@@ -1352,10 +1353,15 @@ class _checkout extends \IPS\Dispatcher\Controller
{
$paymentMethodOptions[ $k ] = $v->_title;
}
if ( $canUseAccountCredit and isset( \IPS\nexus\Customer::loggedIn()->cm_credits[ $this->invoice->currency ] ) and \IPS\nexus\Customer::loggedIn()->cm_credits[ $this->invoice->currency ]->amount->isGreaterThanZero() )
{
$paymentMethodOptions[0] = \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_with_amount', FALSE, array( 'sprintf' => array( \IPS\nexus\Customer::loggedIn()->cm_credits[ $this->invoice->currency ] ) ) );
$paymentMethodsToggles[0][] = 'paymentMethodSubmit';
$credit = \IPS\nexus\Customer::loggedIn()->cm_credits[ $this->invoice->currency ]->amount;
if( $credit >= $amountToPay->amount or ( $amountToPay->amount->subtract( $credit ) > new \IPS\Math\Number( '0.50' ) ) )
{
$paymentMethodOptions[0] = \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_with_amount', FALSE, array( 'sprintf' => array( \IPS\nexus\Customer::loggedIn()->cm_credits[ $this->invoice->currency ] ) ) );
$paymentMethodsToggles[0][] = 'paymentMethodSubmit';
}
}
if ( !$paymentMethodOptions )
@@ -1616,7 +1622,13 @@ class _checkout extends \IPS\Dispatcher\Controller
/* Check if there's anything still to pay */
if ( $this->invoice->amountToPay()->amount->isZero() )
{
{
/* Only mark paid if the invoice itself was worth zero */
if( $this->invoice->total->amount->isZero() )
{
$this->invoice->markPaid();
}
/* Redirect */
$destination = $this->invoice->return_uri ?: $this->invoice->url();
if ( \IPS\Member::loggedIn()->member_id )
@@ -1924,4 +1936,18 @@ class _checkout extends \IPS\Dispatcher\Controller
}
);
}
/**
* Virtual Stripe/Apple Domain Verification File
*
* @return void
*/
protected function appleVerification()
{
if( $file = \IPS\nexus\Gateway::getStripeAppleVerificationFile() )
{
\IPS\Output::i()->sendOutput( $file->contents(), 200, 'text/plain' );
}
\IPS\Output::i()->error( 'node_error', '2X196/5', 403, '' );
}
}
@@ -61,6 +61,9 @@ class _invoices extends \IPS\Dispatcher\Controller
{
\IPS\Output::i()->error( 'no_module_permission_guest', '2X215/6', 404, '' );
}
/* Do not cache this guest view invoice */
\IPS\Output::i()->pageCaching = FALSE;
}
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=invoices', 'front', 'clientsinvoices' ), \IPS\Member::loggedIn()->language()->addToStack('client_invoices') );
@@ -243,7 +243,6 @@ class _product extends \IPS\Content\Controller
'sku' => $package->id,
'offers' => array(
'@type' => 'Offer',
'availability' => ( $package->stock > 0 OR $package->stock == -1 ) ? 'http://schema.org/InStock' : 'http://schema.org/OutOfStock',
'price' => $price->amountAsString(),
'priceCurrency' => $price->currency,
'seller' => array(
@@ -253,6 +252,19 @@ class _product extends \IPS\Content\Controller
),
);
/* Stock status */
if( $package->physical )
{
if( $package->stockLevel() === 0 )
{
\IPS\Output::i()->jsonLd['package']['offers']['availability'] = 'http://schema.org/OutOfStock';
}
else
{
\IPS\Output::i()->jsonLd['package']['offers']['availability'] = 'http://schema.org/InStock';
}
}
if( $package->image )
{
\IPS\Output::i()->jsonLd['package']['image'] = (string) $package->image;
@@ -535,6 +547,21 @@ class _product extends \IPS\Content\Controller
{
$term = ( isset( \IPS\Request::i()->renewal_term ) and isset( $renewOptions[ \IPS\Request::i()->renewal_term ] ) ) ? $renewOptions[ \IPS\Request::i()->renewal_term ] : array_shift( $renewOptions );
switch( $term['unit'] )
{
case 'd':
$initialTerm = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('renew_days'), array( $term['term'] ) );
break;
case 'm':
$initialTerm = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('renew_months'), array( $term['term'] ) );
break;
case 'y':
$initialTerm = \IPS\Member::loggedIn()->language()->pluralize( \IPS\Member::loggedIn()->language()->get('renew_years'), array( $term['term'] ) );
break;
}
$return['initialTerm'] = sprintf( \IPS\Member::loggedIn()->language()->get('package_initial_term_title'), $initialTerm );
if ( $term['add'] )
{
$data['price']->amount = $data['price']->amount->add( new \IPS\Math\Number( number_format( $term['cost'][ $memberCurrency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $memberCurrency ), '.', '' ) ) );
@@ -267,7 +267,6 @@ class _store extends \IPS\Dispatcher\Controller
'sku' => $package->id,
'offers' => array(
'@type' => 'Offer',
'availability' => ( $package->stock > 0 OR $package->stock == -1 ) ? 'http://schema.org/InStock' : 'http://schema.org/OutOfStock',
'price' => $price->amountAsString(),
'priceCurrency' => $price->currency,
'seller' => array(
@@ -277,6 +276,19 @@ class _store extends \IPS\Dispatcher\Controller
),
);
/* Stock levels */
if( $package->physical )
{
if( $package->stockLevel() === 0 )
{
\IPS\Output::i()->jsonLd['package' . $package->id ]['offers']['availability'] = 'http://schema.org/OutOfStock';
}
else
{
\IPS\Output::i()->jsonLd['package' . $package->id ]['offers']['availability'] = 'http://schema.org/InStock';
}
}
if( $package->image )
{
\IPS\Output::i()->jsonLd['package' . $package->id ]['image'] = (string) $package->image;
@@ -38,7 +38,14 @@ 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' ) );
$url = \IPS\Http\Url::internal( 'app=nexus&module=subscriptions&controller=subscriptions', 'front', 'nexus_subscriptions' );
if( isset( \IPS\Request::i()->register ) )
{
$url = $url->setQueryString( 'register', (int) \IPS\Request::i()->register );
}
\IPS\Output::i()->redirect( $url );
}
}
@@ -57,11 +64,14 @@ class _subscriptions extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( 'nexus_no_subs', '2X379/1', 404, '' );
}
/* Send no-cache headers for this page, required for guest sign-ups */
\IPS\Output::i()->pageCaching = FALSE;
/* Create the table */
$table = new \IPS\nexus\Subscription\Table( \IPS\Http\Url::internal( 'app=nexus&module=subscriptions&controller=subscriptions', 'front', 'nexus_subscriptions' ) );
$current = \IPS\nexus\Subscription::loadByMember( \IPS\Member::loggedIn(), FALSE );
if ( $current AND ( !$current->purchase OR !$current->purchase->cancelled OR $current->purchase->can_reactivate ) )
if ( $current )
{
$table->activeSubscription = $current;
}
@@ -113,23 +123,22 @@ class _subscriptions extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( 'node_error', '2X379/7', 403, '' );
}
try
{
$subscription = \IPS\nexus\Subscription::loadActiveByMember( \IPS\Member::loggedIn() );
$subscription = \IPS\nexus\Subscription::loadByMember( \IPS\Member::loggedIn(), FALSE );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'nexus_no_subs_subs', '2X379/3', 404, '' );
}
/* Fetch purchase */
$purchase = NULL;
if( $subscription )
{
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->active and ! $row->cancelled )
if ( !$row->cancelled OR ( $row->cancelled AND $row->can_reactivate ) )
{
$purchase = $row;
break;
@@ -141,6 +150,12 @@ class _subscriptions extends \IPS\Dispatcher\Controller
{
\IPS\Output::i()->error( 'nexus_sub_no_purchase', '2X379/4', 404, '' );
}
/* We cannot process changes if an active Billing Agreement is in place */
if( $purchase->billing_agreement and !$purchase->billing_agreement->canceled )
{
\IPS\Output::i()->error( 'nexus_sub_no_change_ba', '2X379/B', 404, '' );
}
/* Right, that's all the "I'll tamper with the URLs for a laugh" stuff out of the way... */
$upgradeCost = $newPackage->costToUpgrade( $subscription->package, \IPS\nexus\Customer::loggedIn() );
@@ -171,9 +186,12 @@ class _subscriptions extends \IPS\Dispatcher\Controller
{
/* CSRF Check */
\IPS\Session::i()->csrfCheck();
/* Send no-cache headers for this page, required for guest sign-ups */
\IPS\Output::i()->pageCaching = 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 ) ) )
/* Already purchased a subscription */
if ( $current = \IPS\nexus\Subscription::loadByMember( \IPS\nexus\Customer::loggedIn(), FALSE ) AND ( $current->purchase AND ( !$current->purchase->cancelled OR $current->purchase->can_reactivate ) ) )
{
\IPS\Output::i()->error( 'nexus_subs_already_got_package', '2X379/6', 403, '' );
}
@@ -276,46 +294,4 @@ class _subscriptions extends \IPS\Dispatcher\Controller
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=subscriptions&controller=subscriptions', 'front', 'nexus_subscriptions' ) );
}
}
/**
* 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' );
}
}