Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -12,37 +12,58 @@
namespace IPS\nexus\modules\front\clients;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use IPS\Db;
use IPS\Dispatcher\Controller;
use IPS\Http\Url;
use IPS\Member;
use IPS\MFA\MFAHandler;
use IPS\nexus\Customer;
use IPS\nexus\Customer\BillingAgreement;
use IPS\nexus\Gateway\PayPal\Exception;
use IPS\Output;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use OutOfRangeException;
use function count;
use function defined;
use function in_array;
use function intval;
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;
}
/**
* Billing Agreements
*/
class _billingagreements extends \IPS\Dispatcher\Controller
class billingagreements extends Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
if ( !\IPS\Member::loggedIn()->member_id )
if ( !Member::loggedIn()->member_id )
{
\IPS\Output::i()->error( 'no_module_permission_guest', '2X321/1', 403, '' );
Output::i()->error( 'no_module_permission_guest', '2X321/1', 403, '' );
}
\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=billingagreements', 'front', 'clientsbillingagreements' ), \IPS\Member::loggedIn()->language()->addToStack('client_billing_agreements') );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('client_billing_agreements');
\IPS\Output::i()->sidebar['enabled'] = FALSE;
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'clients.css', 'nexus' ) );
Output::i()->breadcrumb[] = array( Url::internal( 'app=nexus&module=clients&controller=billingagreements', 'front', 'clientsbillingagreements' ), Member::loggedIn()->language()->addToStack('client_billing_agreements') );
Output::i()->title = Member::loggedIn()->language()->addToStack('client_billing_agreements');
Output::i()->sidebar['enabled'] = FALSE;
if ( $output = \IPS\MFA\MFAHandler::accessToArea( 'nexus', 'BillingAgreements', \IPS\Http\Url::internal( 'app=nexus&module=clients&controller=billingagreements', 'front', 'clientsbillingagreements' ) ) )
if ( $output = MFAHandler::accessToArea( 'nexus', 'BillingAgreements', Url::internal( 'app=nexus&module=clients&controller=billingagreements', 'front', 'clientsbillingagreements' ) ) )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->billingAgreements( array() ) . $output;
Output::i()->output = Theme::i()->getTemplate('clients')->billingAgreements( array() ) . $output;
return;
}
@@ -54,15 +75,14 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
$billingAgreements = array();
$where = array( 'ba_member=?', \IPS\Member::loggedIn()->member_id );
$parentContacts = \IPS\nexus\Customer::loggedIn()->parentContacts( array( 'billing=1' ) );
if ( \count( $parentContacts ) )
$where = array( 'ba_member=?', Member::loggedIn()->member_id );
$parentContacts = Customer::loggedIn()->parentContacts( array( 'billing=1' ) );
if ( count( $parentContacts ) )
{
$or = array();
foreach ( array_keys( iterator_to_array( $parentContacts ) ) as $id )
{
$where[0] .= ' OR ba_member=?';
@@ -70,13 +90,14 @@ class _billingagreements extends \IPS\Dispatcher\Controller
}
}
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', $where ), 'IPS\nexus\Customer\BillingAgreement' ) as $billingAgreement )
{
foreach ( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_billing_agreements', $where ), 'IPS\nexus\Customer\BillingAgreement' ) as $billingAgreement )
{
/* @var BillingAgreement $billingAgreement */
try
{
$status = $billingAgreement->status();
}
catch ( \Exception $e )
catch ( \Exception )
{
$status = NULL;
}
@@ -85,7 +106,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
{
$term = $billingAgreement->term();
}
catch ( \Exception $e )
catch ( \Exception )
{
$term = NULL;
}
@@ -98,7 +119,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
);
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->billingAgreements( $billingAgreements );
Output::i()->output = Theme::i()->getTemplate('clients')->billingAgreements( $billingAgreements );
}
/**
@@ -106,48 +127,48 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function view()
protected function view() : void
{
/* Load Billing Agreement */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::loadAndCheckPerms( \IPS\Request::i()->id );
$billingAgreement = BillingAgreement::loadAndCheckPerms( Request::i()->id );
$billingAgreement->status(); // Just to make the API call so we can catch the error if there is one
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X320/4', 404, '' );
Output::i()->error( 'node_error', '2X320/4', 404, '' );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
catch ( Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '4X321/5', 500, '', array(), $e->getName() );
Output::i()->error( 'billing_agreement_error', '4X321/5', 500, '', array(), $e->getName() );
}
/* Get associated purchases */
$purchases = array();
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'IPS\nexus\Purchase' ) as $purchase )
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'nexus_purchases', array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'IPS\nexus\Purchase' ) as $purchase )
{
$purchases[0][ $purchase->id ] = $purchase;
}
/* Transactions */
$currentPage = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
$currentPage = isset( Request::i()->page ) ? intval( Request::i()->page ) : 1;
$perPage = 25;
$invoices = new \IPS\Patterns\ActiveRecordIterator(
\IPS\Db::i()->select(
$invoices = new ActiveRecordIterator(
Db::i()->select(
'*',
'nexus_invoices',
array( 'i_id IN(?)', \IPS\Db::i()->select( 't_invoice', 'nexus_transactions', array( 't_billing_agreement=?', $billingAgreement->id ) ) ),
array( 'i_id IN(?)', Db::i()->select( 't_invoice', 'nexus_transactions', array( 't_billing_agreement=?', $billingAgreement->id ) ) ),
'i_date DESC',
array( ( $currentPage - 1 ) * $perPage, $perPage )
),
'IPS\nexus\Invoice'
);
$invoicesCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', array( 'i_id IN(?)', \IPS\Db::i()->select( 't_invoice', 'nexus_transactions', array( 't_billing_agreement=?', $billingAgreement->id ) ) ) )->first();
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $billingAgreement->url(), ceil( $invoicesCount / $perPage ), $currentPage, $perPage );
$invoicesCount = Db::i()->select( 'COUNT(*)', 'nexus_invoices', array( 'i_id IN(?)', Db::i()->select( 't_invoice', 'nexus_transactions', array( 't_billing_agreement=?', $billingAgreement->id ) ) ) )->first();
$pagination = Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $billingAgreement->url(), ceil( $invoicesCount / $perPage ), $currentPage, $perPage );
\IPS\Output::i()->breadcrumb[] = array( $billingAgreement->url(), $billingAgreement->gw_id );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('clients')->billingAgreement( $billingAgreement, $purchases, $invoices, $pagination );
Output::i()->breadcrumb[] = array( $billingAgreement->url(), $billingAgreement->gw_id );
Output::i()->output = Theme::i()->getTemplate('clients')->billingAgreement( $billingAgreement, $purchases, $invoices, $pagination );
}
/**
@@ -155,25 +176,25 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function act()
protected function act() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
/* Check act */
$act = \IPS\Request::i()->act;
if ( !\in_array( $act, array( 'suspend', 'reactivate', 'cancel' ) ) )
$act = Request::i()->act;
if ( !in_array( $act, array( 'suspend', 'reactivate', 'cancel' ) ) )
{
\IPS\Output::i()->error( 'node_error', '3X321/3', 403, '' );
Output::i()->error( 'node_error', '3X321/3', 403, '' );
}
/* Load Billing Agreement */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::loadAndCheckPerms( \IPS\Request::i()->id );
$billingAgreement = BillingAgreement::loadAndCheckPerms( Request::i()->id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X321/2', 404, '' );
Output::i()->error( 'node_error', '2X321/2', 404, '' );
}
/* Perform Action */
@@ -181,11 +202,11 @@ class _billingagreements extends \IPS\Dispatcher\Controller
{
$billingAgreement->$act();
\IPS\Output::i()->redirect( $billingAgreement->url() );
Output::i()->redirect( $billingAgreement->url() );
}
catch ( \DomainException $e )
catch ( DomainException )
{
\IPS\Output::i()->error( 'billing_agreement_error_public', '3X321/4', 500, '' );
Output::i()->error( 'billing_agreement_error_public', '3X321/4', 500, '' );
}
}
}