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,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\Payout;
|
||||
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 Withdrawals API
|
||||
*/
|
||||
class _withdrawals extends \IPS\Api\Controller
|
||||
class withdrawals extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /nexus/withdrawals
|
||||
@@ -34,9 +46,10 @@ class _withdrawals 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\Shipping\Order>
|
||||
* @apireturn PaginatedResponse<IPS\nexus\Payout>
|
||||
* @return PaginatedResponse<Payout>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex() : PaginatedResponse
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
@@ -46,37 +59,37 @@ class _withdrawals extends \IPS\Api\Controller
|
||||
{
|
||||
$where[] = array( 'po_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
elseif ( isset( Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'po_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'po_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( 'po_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'po_status', array_filter( explode( ',', Request::i()->statuses ) ) ) );
|
||||
}
|
||||
|
||||
/* 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 = 'po_' . \IPS\Request::i()->sortBy;
|
||||
$sortBy = 'po_' . Request::i()->sortBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sortBy = 'po_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_payouts', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
Db::i()->select( '*', 'nexus_payouts', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( Request::i()->page ) ? Request::i()->page : 1,
|
||||
'IPS\nexus\Payout`',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_payouts', $where )->first(),
|
||||
Db::i()->select( 'COUNT(*)', 'nexus_payouts', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,23 +99,24 @@ class _withdrawals extends \IPS\Api\Controller
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X307/1 INVALID_ID The withdrawal ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Payout
|
||||
* @apireturn \IPS\nexus\Payout
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( $id );
|
||||
$payout = Payout::load( $id );
|
||||
if ( $this->member and $this->member->member_id != $payout->member->member_id )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $payout->apiOutput( $this->member ) );
|
||||
return new Response( 200, $payout->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X309/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2X309/1', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user