Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -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' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user