Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,30 +12,58 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\core\AdminNotification;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\nexus\Form\Money;
|
||||
use IPS\nexus\Gateway;
|
||||
use IPS\nexus\Payout;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payouts
|
||||
*/
|
||||
class _payouts extends \IPS\Dispatcher\Controller
|
||||
class payouts extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -44,48 +72,48 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* Redirect to settings if we haven't set it up */
|
||||
if ( !\IPS\Settings::i()->nexus_payout )
|
||||
if ( !Settings::i()->nexus_payout )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' ) );
|
||||
}
|
||||
|
||||
/* Build table */
|
||||
$table = \IPS\nexus\Payout::table( array(), \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
$table = Payout::table( array(), Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_payouts');
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'payouts_settings' ) )
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__nexus_payments_payouts');
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'payouts_settings' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
Output::i()->sidebar['actions'] = array(
|
||||
'settings' => array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'account_credit_settings',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' )
|
||||
'link' => Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' )
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( \IPS\Db::i()->select( 'po_gateway', 'nexus_payouts', array( 'po_status=?', \IPS\nexus\Payout::STATUS_PENDING ), NULL, NULL, 'po_gateway' ) as $gateway )
|
||||
foreach ( Db::i()->select( 'po_gateway', 'nexus_payouts', array( 'po_status=?', Payout::STATUS_PENDING ), NULL, NULL, 'po_gateway' ) as $gateway )
|
||||
{
|
||||
$classname = \IPS\nexus\Gateway::payoutGateways()[ $gateway ];
|
||||
$classname = Gateway::payoutGateways()[ $gateway ];
|
||||
if ( class_exists( $classname ) and method_exists( $classname, 'massProcess' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'][] = [
|
||||
Output::i()->sidebar['actions'][] = [
|
||||
'icon' => 'check',
|
||||
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_mass_payout', TRUE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'payout__admin_' . $gateway ) ) ) ),
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=massprocess&gateway=' . $gateway )->csrf(),
|
||||
'title' => Member::loggedIn()->language()->addToStack( 'account_credit_mass_payout', TRUE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( 'payout__admin_' . $gateway ) ) ) ),
|
||||
'link' => Url::internal( 'app=nexus&module=payments&controller=payouts&do=massprocess&gateway=' . $gateway )->csrf(),
|
||||
'data' => [
|
||||
'confirm' => '',
|
||||
'confirmMessage' => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_title' ),
|
||||
'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_text' )
|
||||
'confirmMessage' => Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_title' ),
|
||||
'confirmSubMessage' => Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_text' )
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
Output::i()->output = (string) $table;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,20 +121,20 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
protected function view() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/2', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/2', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sidebar['actions'] = $payout->buttons( 'v' );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'payout_number', FALSE, array( 'sprintf' => array( $payout->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('payouts')->view( $payout );
|
||||
Output::i()->sidebar['actions'] = $payout->buttons( 'v' );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'payout_number', FALSE, array( 'sprintf' => array( $payout->id ) ) );
|
||||
Output::i()->output = Theme::i()->getTemplate('payouts')->view( $payout );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,48 +142,48 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function process()
|
||||
protected function process() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/3', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/3', 404, '' );
|
||||
}
|
||||
|
||||
if ( $payout->status !== $payout::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/4', 403, '' );
|
||||
Output::i()->error( 'err_payout_not_pending', '1X200/4', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$payout->process();
|
||||
$payout->status = $payout->process();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X200/1', 500, '' );
|
||||
Output::i()->error( $e->getMessage(), '1X200/1', 500, '' );
|
||||
}
|
||||
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->processed_by = Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'processed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
/* If the payout was actually completed, notify the user */
|
||||
if( $payout->status == \IPS\nexus\Payout::STATUS_COMPLETE )
|
||||
if( $payout->status == Payout::STATUS_COMPLETE )
|
||||
{
|
||||
$payout->markCompleted();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use task if the payout is pending */
|
||||
$task = \IPS\Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task = Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task->enabled = TRUE;
|
||||
$task->save();
|
||||
}
|
||||
@@ -168,38 +196,39 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function massprocess()
|
||||
protected function massprocess() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
\IPS\Request::i()->confirmedDelete( 'nexus_payout_confirm_title', 'nexus_payout_confirm_text', 'nexus_payout_proceed' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
Request::i()->confirmedDelete( 'nexus_payout_confirm_title', 'nexus_payout_confirm_text', 'nexus_payout_proceed' );
|
||||
|
||||
$classname = \IPS\nexus\Gateway::payoutGateways()[ \IPS\Request::i()->gateway ];
|
||||
$classname = Gateway::payoutGateways()[ Request::i()->gateway ];
|
||||
if ( !class_exists( $classname ) or !method_exists( $classname, 'massProcess' ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '2X200/8', 403, '' );
|
||||
Output::i()->error( 'generic_error', '2X200/8', 403, '' );
|
||||
}
|
||||
|
||||
$payouts = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_payouts', array( 'po_status=? AND po_gateway=?', \IPS\nexus\Payout::STATUS_PENDING, \IPS\Request::i()->gateway ) ), $classname );
|
||||
$payouts = new ActiveRecordIterator( Db::i()->select( '*', 'nexus_payouts', array( 'po_status=? AND po_gateway=?', Payout::STATUS_PENDING, Request::i()->gateway ) ), $classname );
|
||||
|
||||
try
|
||||
{
|
||||
$classname::massProcess( $payouts );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X200/9', 403, '' );
|
||||
Output::i()->error( $e->getMessage(), '1X200/9', 403, '' );
|
||||
}
|
||||
|
||||
$pending = 0;
|
||||
foreach ( $payouts as $payout )
|
||||
{
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
/* @var Payout $payout */
|
||||
$payout->processed_by = Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'processed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
/* Only do this if the payout is actually complete! */
|
||||
if( $payout->status == \IPS\nexus\Payout::STATUS_COMPLETE )
|
||||
if( $payout->status == Payout::STATUS_COMPLETE )
|
||||
{
|
||||
$payout->markCompleted();
|
||||
continue;
|
||||
@@ -211,12 +240,12 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
/* Use task if there are incomplete payouts */
|
||||
if( $pending )
|
||||
{
|
||||
$task = \IPS\Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task = Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task->enabled = TRUE;
|
||||
$task->save();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,33 +253,33 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cancel()
|
||||
protected function cancel() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/6', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/6', 404, '' );
|
||||
}
|
||||
|
||||
if ( $payout->status !== $payout::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/5', 403, '' );
|
||||
Output::i()->error( 'err_payout_not_pending', '1X200/5', 403, '' );
|
||||
}
|
||||
|
||||
$payout->status = $payout::STATUS_CANCELED;
|
||||
$payout->completed = new \IPS\DateTime;
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->completed = new DateTime;
|
||||
$payout->processed_by = Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_cancelled', array( $payout->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__payout_cancelled', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'cancel', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
if ( \IPS\Request::i()->prompt )
|
||||
if ( Request::i()->prompt )
|
||||
{
|
||||
$credits = $payout->member->cm_credits;
|
||||
$credits[ $payout->amount->currency ]->amount = $credits[ $payout->amount->currency ]->amount->add( $payout->amount->amount );
|
||||
@@ -266,27 +295,27 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/7', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/7', 404, '' );
|
||||
}
|
||||
|
||||
$payout->delete();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_deleted', array( $payout->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__payout_deleted', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'dismissed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,18 +323,19 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
protected function settings() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_settings' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_settings' );
|
||||
|
||||
$options = array();
|
||||
$toggles = array();
|
||||
$fields = array();
|
||||
foreach ( \IPS\nexus\Gateway::payoutGateways() as $key => $class )
|
||||
foreach ( Gateway::payoutGateways() as $key => $class )
|
||||
{
|
||||
$options[ $key ] = 'payout__admin_' . $key;
|
||||
$toggles[ $key ] = array( 'form_header_payout_settings' );
|
||||
|
||||
|
||||
/* @var Payout $class */
|
||||
foreach ( $class::settings() as $field )
|
||||
{
|
||||
if ( !$field->htmlId )
|
||||
@@ -319,41 +349,41 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups( TRUE, FALSE ) as $group )
|
||||
foreach ( Group::groups( TRUE, FALSE ) as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
$settings = \IPS\Settings::i()->nexus_payout ? json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) : array();
|
||||
$settings = \is_array( $settings ) ? array_keys( $settings ) : array();
|
||||
$settings = Settings::i()->nexus_payout ? json_decode( Settings::i()->nexus_payout, TRUE ) : array();
|
||||
$settings = is_array( $settings ) ? array_keys( $settings ) : array();
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addMessage('payout_description');
|
||||
$form = new Form;
|
||||
$form->addMessage('payout_description', 'ipsMessage--transparent');
|
||||
$form->addHeader('commission_settings');
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_no_commission', explode( ',', \IPS\Settings::i()->nexus_no_commission ), FALSE, array( 'multiple' => TRUE, 'options' => $groups ) ) );
|
||||
$form->add( new CheckboxSet( 'nexus_no_commission', explode( ',', Settings::i()->nexus_no_commission ), FALSE, array( 'multiple' => TRUE, 'options' => $groups ) ) );
|
||||
$form->addHeader('withdrawal_methods');
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_payout', $settings, FALSE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
$form->add( new CheckboxSet( 'nexus_payout', $settings, FALSE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
foreach ( $fields as $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
$form->addHeader('payout_settings');
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_payout_min', ( \IPS\Settings::i()->nexus_payout_min AND \IPS\Settings::i()->nexus_payout_min != '*' ) ? json_decode( \IPS\Settings::i()->nexus_payout_min, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_payout_min' ) );
|
||||
$form->add( new Money( 'nexus_payout_min', ( Settings::i()->nexus_payout_min AND Settings::i()->nexus_payout_min != '*' ) ? json_decode( Settings::i()->nexus_payout_min, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_payout_min' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'nexus_payout_maximum', NULL, FALSE, array( 'getHtml' => function( $element ) {
|
||||
$amount = new \IPS\nexus\Form\Money( 'nexus_payout_maximum[2]', ( \IPS\Settings::i()->nexus_payout_max AND \IPS\Settings::i()->nexus_payout_max != '*' ) ? json_decode( \IPS\Settings::i()->nexus_payout_max, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction', 'unlimitedTogglesOff' => array( 'payout_max_limited' ) ), NULL, NULL, NULL, 'nexus_payout_max' );
|
||||
$period = \IPS\Settings::i()->nexus_payout_max_period ? json_decode( \IPS\Settings::i()->nexus_payout_max_period, TRUE ) : array( 1, 'day' );
|
||||
$form->add( new Custom( 'nexus_payout_maximum', NULL, FALSE, array( 'getHtml' => function( $element ) {
|
||||
$amount = new Money( 'nexus_payout_maximum[2]', ( Settings::i()->nexus_payout_max AND Settings::i()->nexus_payout_max != '*' ) ? json_decode( Settings::i()->nexus_payout_max, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction', 'unlimitedTogglesOff' => array( 'payout_max_limited' ) ), NULL, NULL, NULL, 'nexus_payout_max' );
|
||||
$period = Settings::i()->nexus_payout_max_period ? json_decode( Settings::i()->nexus_payout_max_period, TRUE ) : array( 1, 'day' );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'payouts' )->maximumLimits( $amount->html(), (int) $period[0], $period[1] );
|
||||
return Theme::i()->getTemplate( 'payouts' )->maximumLimits( $amount->html(), (int) $period[0], $period[1] );
|
||||
} ), NULL, NULL, NULL, 'nexus_payout_maximum' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_payout_approve', \IPS\Settings::i()->nexus_payout_approve, FALSE, array(), NULL, NULL, NULL, 'nexus_payout_approve' ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_payout_unlimited_times', \IPS\Settings::i()->nexus_payout_unlimited_times, TRUE ) );
|
||||
$form->add( new YesNo( 'nexus_payout_approve', Settings::i()->nexus_payout_approve, FALSE, array(), NULL, NULL, NULL, 'nexus_payout_approve' ) );
|
||||
$form->add( new YesNo( 'nexus_payout_unlimited_times', Settings::i()->nexus_payout_unlimited_times, TRUE ) );
|
||||
|
||||
$form->addHeader('topup_settings');
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'allow_topups', \IPS\Settings::i()->nexus_min_topup, FALSE, array( 'togglesOn' => array( 'nexus_min_topup', 'nexus_max_credit' ) ) ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_min_topup', \IPS\Settings::i()->nexus_min_topup ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_min_topup' ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_max_credit', \IPS\Settings::i()->nexus_max_credit ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_max_credit' ) );
|
||||
$form->add( new YesNo( 'allow_topups', Settings::i()->nexus_min_topup, FALSE, array( 'togglesOn' => array( 'nexus_min_topup', 'nexus_max_credit' ) ) ) );
|
||||
$form->add( new Money( 'nexus_min_topup', Settings::i()->nexus_min_topup ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_min_topup' ) );
|
||||
$form->add( new Money( 'nexus_max_credit', Settings::i()->nexus_max_credit ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_max_credit' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -378,8 +408,8 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
$values['nexus_payout'] = json_encode( $payoutSettings );
|
||||
$values['nexus_payout_min'] = \is_array( $values['nexus_payout_min'] ) ? json_encode( $values['nexus_payout_min'] ) : '*';
|
||||
$values['nexus_payout_max'] = ( \is_array( $values['nexus_payout_maximum'][2] ) AND ( !isset( $values['nexus_payout_maximum'][2]['__unlimited'] ) OR !$values['nexus_payout_maximum'][2]['__unlimited'] ) ) ? json_encode( $values['nexus_payout_maximum'][2] ) : '*';
|
||||
$values['nexus_payout_min'] = is_array( $values['nexus_payout_min'] ) ? json_encode( $values['nexus_payout_min'] ) : '*';
|
||||
$values['nexus_payout_max'] = ( is_array( $values['nexus_payout_maximum'][2] ) AND ( !isset( $values['nexus_payout_maximum'][2]['__unlimited'] ) OR !$values['nexus_payout_maximum'][2]['__unlimited'] ) ) ? json_encode( $values['nexus_payout_maximum'][2] ) : '*';
|
||||
$values['nexus_payout_max_period'] = ( $values['nexus_payout_max'] == '*' ) ? NULL : json_encode( array( $values['nexus_payout_maximum'][0], $values['nexus_payout_maximum'][1] ) );
|
||||
|
||||
if ( $values['allow_topups'] )
|
||||
@@ -397,51 +427,51 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
$values['nexus_no_commission'] = implode( ',', $values['nexus_no_commission'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplogs__payout_settings' );
|
||||
Session::i()->log( 'acplogs__payout_settings' );
|
||||
|
||||
/* Remove any ACP notifications related to Payout Settings */
|
||||
foreach( \IPS\nexus\Gateway::payoutGateways() as $key => $class )
|
||||
foreach( Gateway::payoutGateways() as $key => $class )
|
||||
{
|
||||
\IPS\core\AdminNotification::remove( 'nexus', 'ConfigurationError', "po{$key}" );
|
||||
AdminNotification::remove( 'nexus', 'ConfigurationError', "po{$key}" );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts'), 'saved' );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts'), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('account_credit_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('account_credit_settings');
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Payout $payout The payout
|
||||
* @param Payout $payout The payout
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Payout $payout )
|
||||
protected function _redirect( Payout $payout ) : void
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
if ( isset( Request::i()->r ) )
|
||||
{
|
||||
switch ( mb_substr( \IPS\Request::i()->r, 0, 1 ) )
|
||||
switch ( mb_substr( Request::i()->r, 0, 1 ) )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $payout->acpUrl() );
|
||||
Output::i()->redirect( $payout->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $payout->member->acpUrl() );
|
||||
Output::i()->redirect( $payout->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', \IPS\Request::i()->filter ) );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', Request::i()->filter ) );
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=notifications') );
|
||||
Output::i()->redirect( Url::internal('app=core&module=overview&controller=notifications') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $payout->acpUrl() );
|
||||
Output::i()->redirect( $payout->acpUrl() );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user