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

+39 -25
View File
@@ -12,16 +12,28 @@
namespace IPS\nexus\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Api\Controller;
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\Db;
use IPS\nexus\Transaction;
use IPS\Request;
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;
}
/**
* @brief Transactions API
*/
class _transactions extends \IPS\Api\Controller
class transactions extends Controller
{
/**
* GET /nexus/transactions
@@ -35,9 +47,10 @@ class _transactions extends \IPS\Api\Controller
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Transaction>
* @apireturn PaginatedResponse<IPS\nexus\Transaction>
* @return PaginatedResponse<Transaction>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = array();
@@ -47,43 +60,43 @@ class _transactions extends \IPS\Api\Controller
{
$where[] = array( 't_member=?', $this->member->member_id );
}
elseif ( isset( \IPS\Request::i()->customers ) )
elseif ( isset( Request::i()->customers ) )
{
$where[] = array( \IPS\Db::i()->in( 't_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
$where[] = array( Db::i()->in( 't_member', array_map( 'intval', array_filter( explode( ',', Request::i()->customers ) ) ) ) );
}
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
if ( isset( Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 't_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
$where[] = array( Db::i()->in( 't_status', array_filter( explode( ',', Request::i()->statuses ) ) ) );
}
/* Methods */
if ( isset( \IPS\Request::i()->gateways ) )
if ( isset( Request::i()->gateways ) )
{
$where[] = array( \IPS\Db::i()->in( 't_method', array_filter( explode( ',', \IPS\Request::i()->gateways ) ) ) );
$where[] = array( Db::i()->in( 't_method', array_filter( explode( ',', Request::i()->gateways ) ) ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'date', 'amount' ) ) )
if ( isset( Request::i()->sortBy ) and in_array( Request::i()->sortBy, array( 'date', 'amount' ) ) )
{
$sortBy = 't_' . \IPS\Request::i()->sortBy;
$sortBy = 't_' . Request::i()->sortBy;
}
else
{
$sortBy = 't_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
$sortDir = ( isset( Request::i()->sortDir ) and in_array( mb_strtolower( Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'nexus_transactions', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
Db::i()->select( '*', 'nexus_transactions', $where, "{$sortBy} {$sortDir}" ),
isset( Request::i()->page ) ? Request::i()->page : 1,
'IPS\nexus\Transaction',
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', $where )->first(),
Db::i()->select( 'COUNT(*)', 'nexus_transactions', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
);
}
@@ -93,18 +106,19 @@ class _transactions extends \IPS\Api\Controller
*
* @param int $id ID Number
* @throws 2X307/1 INVALID_ID The transaction ID does not exist or the authorized user does not have permission to view it
* @return \IPS\nexus\Transaction
* @apireturn \IPS\nexus\Transaction
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
try
{
$object = $this->member ? \IPS\nexus\Transaction::loadAndCheckPerms( $id ) : \IPS\nexus\Transaction::load( $id );
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
$object = $this->member ? Transaction::loadAndCheckPerms( $id ) : Transaction::load( $id );
return new Response( 200, $object->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X307/1', 404 );
throw new Exception( 'INVALID_ID', '2X307/1', 404 );
}
}
}