Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,9 @@
/**
* @brief Account Credit
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 08 May 2014
* @version SVN_VERSION_NUMBER
@@ -38,13 +38,20 @@ class _credit extends \IPS\Dispatcher\Controller
if ( mb_strtolower( $_SERVER['REQUEST_METHOD'] ) == 'get' and \IPS\Settings::i()->nexus_https and \IPS\Request::i()->url()->data['scheme'] !== 'https' )
{
\IPS\Output::i()->redirect( new \IPS\Http\Url( preg_replace( '/^http:/', 'https:', \IPS\Request::i()->url() ) ) );
\IPS\Output::i()->redirect( \IPS\Request::i()->url()->setScheme('https') );
}
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'clients.css', 'nexus' ) );
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ), \IPS\Member::loggedIn()->language()->addToStack('client_credit') );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_credit');
\IPS\Output::i()->sidebar['enabled'] = FALSE;
if ( $output = \IPS\MFA\MFAHandler::accessToArea( 'nexus', 'AccountCredit', \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=credit', 'front', 'clientscredit', array(), \IPS\Settings::i()->nexus_https ) ) )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->credit( NULL, array(), NULL, FALSE, FALSE ) . $output;
return;
}
parent::execute();
}
@@ -86,7 +93,7 @@ class _credit extends \IPS\Dispatcher\Controller
{
foreach ( \IPS\nexus\Money::currencies() as $currency )
{
if ( isset( $balance[ $currency ] ) )
if ( isset( $balance[ $currency ] ) and $balance[ $currency ]->amount->isGreaterThanZero() )
{
$canWithdraw = TRUE;
}
@@ -110,8 +117,7 @@ class _credit extends \IPS\Dispatcher\Controller
foreach ( $account->cm_credits as $value )
{
$max = $maximumBalanceAmounts ? ( $maximumBalanceAmounts[ $value->currency ]['amount'] - $value->amount ) : NULL;
if ( is_null( $max ) or $max > 0 )
if ( $maximumBalanceAmounts === NULL or $value->amount->compare( new \IPS\Math\Number( number_format( $maximumBalanceAmounts[ $value->currency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $value->currency ), '.', '' ) ) ) === -1 )
{
$canTopup = TRUE;
}
@@ -132,11 +138,16 @@ class _credit extends \IPS\Dispatcher\Controller
{
$withdrawForm = NULL;
$withdrawOptions = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
if ( isset( $withdrawOptions['Stripe'] ) )
{
unset( $withdrawOptions['Stripe'] );
}
if ( count( $withdrawOptions ) )
{
$withdrawForm = new \IPS\Helpers\Form( 'withdraw', 'withdraw_credit' );
$minimumWithdrawalsAmounts = ( \IPS\Settings::i()->nexus_payout_min and \IPS\Settings::i()->nexus_payout_min !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_payout_min, TRUE ) : NULL;
$maximumWithdrawalsAmounts = ( \IPS\Settings::i()->nexus_payout_max and \IPS\Settings::i()->nexus_payout_max !== '*' ) ? json_decode( \IPS\Settings::i()->nexus_payout_max, TRUE ) : NULL;
$balance = array_filter( \IPS\nexus\Customer::loggedIn()->cm_credits, function( $val )
{
@@ -167,10 +178,42 @@ class _credit extends \IPS\Dispatcher\Controller
continue;
}
$min = $minimumWithdrawalsAmounts ? ( $minimumWithdrawalsAmounts[ $currency ]['amount'] ) : NULL;
$max = $balance[ $currency ]->amount;
$field = new \IPS\Helpers\Form\Number( 'withdraw_amount_' . $currency, $max, count( $currencyOptions ) ? NULL : TRUE, array( 'min' => $min, 'max' => $max, 'decimals' => TRUE ), count( $currencyOptions ) ? NULL : function( $val ) use ( $currency )
$min = $minimumWithdrawalsAmounts ? ( $minimumWithdrawalsAmounts[ $currency ]['amount'] ) : 0;
/* Default 'max' is our balance */
$max = (string) $balance[ $currency ]->amount;
/* Do we have a maximum withdrawl amount set up? */
if( $maximumWithdrawalsAmounts AND $maximumWithdrawalsAmounts[ $currency ] )
{
/* If our maximum withdrawl amount is less than our balance, then the max we can withdraw is that */
$upperLimit = $maximumWithdrawalsAmounts[ $currency ];
/* Determine our date cutoff */
$periodRestrictions = json_decode( \IPS\Settings::i()->nexus_payout_max_period, TRUE );
$interval = 'P' . (int) $periodRestrictions[0] . ( mb_strtoupper( mb_substr( $periodRestrictions[1], 0, 1 ) ) );
$date = \IPS\DateTime::create()->sub( new \DateInterval( $interval ) )->getTimestamp();
/* Get our (non-cancelled) payout requests since the date cutoff */
foreach( \IPS\Db::i()->select( '*', 'nexus_payouts', array( 'po_member=? AND po_date>? AND po_status NOT IN(?) AND po_currency=?', \IPS\nexus\Customer::loggedIn()->member_id, $date, 'canc', $currency ) ) as $request )
{
$upperLimit -= $request['po_amount'];
}
/* Do we need to reset the max? */
if( $upperLimit < $max )
{
$max = $upperLimit;
}
}
if( $max <= 0 )
{
\IPS\Member::loggedIn()->language()->words[ 'withdraw_amount_' . $currency . '_desc' ] = \IPS\Member::loggedIn()->language()->addToStack( 'max_withdrawl_exceeded' );
}
$field = new \IPS\Helpers\Form\Number( 'withdraw_amount_' . $currency, (string) $max, count( $currencyOptions ) ? NULL : TRUE, array( 'min' => $min, 'max' => (string) $max, 'decimals' => \IPS\nexus\Money::numberOfDecimalsForCurrency( $currency ), 'disabled' => ( $max <= 0 ) ), count( $currencyOptions ) ? NULL : function( $val ) use ( $currency )
{
if ( !$val and \IPS\Request::i()->withdraw_currency === $currency )
{
@@ -244,7 +287,7 @@ class _credit extends \IPS\Dispatcher\Controller
$payout->save();
$credits = \IPS\nexus\Customer::loggedIn()->cm_credits;
$credits[ $currency ]->amount -= $values[ 'withdraw_amount_' . $currency ];
$credits[ $currency ]->amount = $credits[ $currency ]->amount->subtract( new \IPS\Math\Number( number_format( $values[ 'withdraw_amount_' . $currency ], \IPS\nexus\Money::numberOfDecimalsForCurrency( $currency ), '.', '' ) ) );
\IPS\nexus\Customer::loggedIn()->cm_credits = $credits;
\IPS\nexus\Customer::loggedIn()->save();
@@ -300,10 +343,10 @@ class _credit extends \IPS\Dispatcher\Controller
foreach ( $account->cm_credits as $value )
{
$max = $maximumBalanceAmounts ? ( $maximumBalanceAmounts[ $value->currency ]['amount'] - $value->amount ) : NULL;
if ( is_null( $max ) or $max > 0 )
$max = $maximumBalanceAmounts ? ( ( new \IPS\Math\Number( number_format( $maximumBalanceAmounts[ $value->currency ]['amount'], \IPS\nexus\Money::numberOfDecimalsForCurrency( $value->currency ), '.', '' ) ) )->subtract( $value->amount ) ) : NULL;
if ( is_null( $max ) or $max->isGreaterThanZero() )
{
$maximums[ $account->member_id ][ $value->currency ] = $max;
$maximums[ $account->member_id ][ $value->currency ] = is_null( $max ) ? NULL : (string) $max;
}
}
}
@@ -346,7 +389,7 @@ class _credit extends \IPS\Dispatcher\Controller
{
$min = $minimumTopupAmounts ? ( $minimumTopupAmounts[ $currency ]['amount'] ) : 0.01;
$field = new \IPS\Helpers\Form\Number( 'topup_amount_' . $accountId . '_' . $currency, NULL, NULL, array( 'decimals' => TRUE ), function( $val ) use ( $currency, $accountOptions, $accountId, $data, $min, $maximum )
$field = new \IPS\Helpers\Form\Number( 'topup_amount_' . $accountId . '_' . $currency, NULL, NULL, array( 'decimals' => \IPS\nexus\Money::numberOfDecimalsForCurrency( $currency ) ), function( $val ) use ( $currency, $accountOptions, $accountId, $data, $min, $maximum )
{
if ( count( $accountOptions ) === 1 or \IPS\Request::i()->topup_account == $accountId )
{
@@ -375,6 +418,7 @@ class _credit extends \IPS\Dispatcher\Controller
if ( $values = $topupForm->values() )
{
$account = isset( $values['topup_account'] ) ? \IPS\nexus\Customer::load( $values['topup_account'] ) : \IPS\nexus\Customer::loggedIn();
if ( isset( $values[ 'topup_currency_' . $account->member_id ] ) )
{
@@ -422,7 +466,7 @@ class _credit extends \IPS\Dispatcher\Controller
$payout->save();
$credits = $payout->member->cm_credits;
$credits[ $payout->amount->currency ]->amount += $payout->amount->amount;
$credits[ $payout->amount->currency ]->amount = $credits[ $payout->amount->currency ]->amount->add( $payout->amount->amount );
$payout->member->cm_credits = $credits;
$payout->member->save();