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,30 +12,47 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Member;
use IPS\nexus\Customer\BillingAgreement;
use IPS\nexus\Gateway\PayPal\Exception;
use IPS\nexus\Purchase;
use IPS\nexus\Transaction;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use OutOfRangeException;
use function defined;
use function in_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;
}
/**
* Billing Agreements
*/
class _billingagreements extends \IPS\Dispatcher\Controller
class billingagreements 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( 'billingagreements_view' );
Dispatcher::i()->checkAcpPermission( 'billingagreements_view' );
parent::execute();
}
@@ -44,12 +61,12 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function manage()
public function manage() : void
{
/* Load */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
$billingAgreement = BillingAgreement::load( Request::i()->id );
if ( !$billingAgreement->canceled and $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
{
@@ -58,13 +75,13 @@ class _billingagreements extends \IPS\Dispatcher\Controller
$billingAgreement->save();
}
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X320/1', 404, '' );
Output::i()->error( 'node_error', '2X320/1', 404, '' );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
catch ( Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error_public', '4X320/9', 500, 'billing_agreement_error', array(), $e->getName() );
Output::i()->error( 'billing_agreement_error_public', '4X320/9', 500, 'billing_agreement_error', array(), $e->getName() );
}
/* Show */
@@ -72,20 +89,20 @@ class _billingagreements extends \IPS\Dispatcher\Controller
{
/* Purchases */
$purchases = NULL;
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) and ( !isset( \IPS\Request::i()->table ) ) )
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) and ( !isset( Request::i()->table ) ) )
{
$purchases = \IPS\nexus\Purchase::tree( $billingAgreement->acpUrl(), array( array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'ba' );
$purchases = Purchase::tree( $billingAgreement->acpUrl(), array( array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'ba' );
}
/* Transactions */
$transactions = NULL;
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) and ( !isset( \IPS\Request::i()->table ) ) )
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) and ( !isset( Request::i()->table ) ) )
{
$transactions = \IPS\nexus\Transaction::table( array( array( 't_billing_agreement=? AND t_status<>?', $billingAgreement->id, \IPS\nexus\Transaction::STATUS_PENDING ) ), $billingAgreement->acpUrl(), 'ba' );
$transactions = Transaction::table( array( array( 't_billing_agreement=? AND t_status<>?', $billingAgreement->id, Transaction::STATUS_PENDING ) ), $billingAgreement->acpUrl(), 'ba' );
$transactions->limit = 50;
foreach ( $transactions->include as $k => $v )
{
if ( \in_array( $v, array( 't_method', 't_member' ) ) )
if ( in_array( $v, array( 't_method', 't_member' ) ) )
{
unset( $transactions->include[ $k ] );
}
@@ -93,27 +110,27 @@ class _billingagreements extends \IPS\Dispatcher\Controller
}
/* Action Buttons */
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'billingagreements_manage' ) )
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'billingagreements_manage' ) )
{
if ( $billingAgreement->status() == $billingAgreement::STATUS_ACTIVE )
{
\IPS\Output::i()->sidebar['actions']['refresh'] = array(
Output::i()->sidebar['actions']['refresh'] = array(
'icon' => 'refresh',
'title' => 'billing_agreement_check',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'refresh' ) )->csrf(),
'data' => array( 'confirm' => '' )
);
\IPS\Output::i()->sidebar['actions']['suspend'] = array(
Output::i()->sidebar['actions']['suspend'] = array(
'icon' => 'times',
'title' => 'billing_agreement_suspend',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'suspend' ) )->csrf(),
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('billing_agreement_suspend_confirm') )
'data' => array( 'confirm' => '', 'confirmSubMessage' => Member::loggedIn()->language()->addToStack('billing_agreement_suspend_confirm') )
);
}
elseif ( $billingAgreement->status() == $billingAgreement::STATUS_SUSPENDED )
{
\IPS\Output::i()->sidebar['actions']['reactivate'] = array(
Output::i()->sidebar['actions']['reactivate'] = array(
'icon' => 'check',
'title' => 'billing_agreement_reactivate',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'reactivate' ) )->csrf(),
@@ -122,7 +139,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
}
if ( $billingAgreement->status() != $billingAgreement::STATUS_CANCELED )
{
\IPS\Output::i()->sidebar['actions']['cancel'] = array(
Output::i()->sidebar['actions']['cancel'] = array(
'icon' => 'times-circle',
'title' => 'billing_agreement_cancel',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'cancel' ) )->csrf(),
@@ -131,16 +148,16 @@ class _billingagreements extends \IPS\Dispatcher\Controller
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'billing_agreement_id', FALSE, array( 'sprintf' => array( $billingAgreement->gw_id ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'billingagreements' )->view( $billingAgreement, $purchases, $transactions );
Output::i()->title = Member::loggedIn()->language()->addToStack( 'billing_agreement_id', FALSE, array( 'sprintf' => array( $billingAgreement->gw_id ) ) );
Output::i()->output = Theme::i()->getTemplate( 'billingagreements' )->view( $billingAgreement, $purchases, $transactions );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
catch ( Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/2', 500, '', array(), $e->getName() );
Output::i()->error( 'billing_agreement_error', '1X320/2', 500, '', array(), $e->getName() );
}
catch ( \DomainException $e )
catch ( DomainException )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/3', 500 );
Output::i()->error( 'billing_agreement_error', '1X320/3' );
}
}
@@ -149,18 +166,18 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function reconcile()
public function reconcile() : void
{
\IPS\Session::i()->csrfCheck();
Session::i()->csrfCheck();
/* Load */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
$billingAgreement = BillingAgreement::load( Request::i()->id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X320/5', 404, '' );
Output::i()->error( 'node_error', '2X320/5', 404, '' );
}
/* Reconcile */
@@ -169,15 +186,15 @@ class _billingagreements extends \IPS\Dispatcher\Controller
$billingAgreement->next_cycle = $billingAgreement->nextPaymentDate();
$billingAgreement->save();
\IPS\Output::i()->redirect( $billingAgreement->acpUrl() );
Output::i()->redirect( $billingAgreement->acpUrl() );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
catch ( Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/6', 500, '', array(), $e->getName() );
Output::i()->error( 'billing_agreement_error', '1X320/6', 500, '', array(), $e->getName() );
}
catch ( \DomainException $e )
catch ( DomainException )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/7', 500 );
Output::i()->error( 'billing_agreement_error', '1X320/7' );
}
}
@@ -186,25 +203,25 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function act()
public 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', 'refresh' ) ) )
$act = Request::i()->act;
if ( !in_array( $act, array( 'suspend', 'reactivate', 'cancel', 'refresh' ) ) )
{
\IPS\Output::i()->error( 'node_error', '3X320/8', 403, '' );
Output::i()->error( 'node_error', '3X320/8', 403, '' );
}
/* Load */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
$billingAgreement = BillingAgreement::load( Request::i()->id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
\IPS\Output::i()->error( 'node_error', '2X320/8', 404, '' );
Output::i()->error( 'node_error', '2X320/8', 404, '' );
}
/* Perform Action */
@@ -212,15 +229,15 @@ class _billingagreements extends \IPS\Dispatcher\Controller
{
$billingAgreement->$act();
\IPS\Output::i()->redirect( $billingAgreement->acpUrl() );
Output::i()->redirect( $billingAgreement->acpUrl() );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
catch ( Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/9', 500, '', array(), $e->getName() );
Output::i()->error( 'billing_agreement_error', '1X320/9', 500, '', array(), $e->getName() );
}
catch ( \DomainException $e )
catch ( DomainException )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/A', 500 );
Output::i()->error( 'billing_agreement_error', '1X320/A' );
}
}
}