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\Invoice;
|
||||
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 Invoices API
|
||||
*/
|
||||
class _invoices extends \IPS\Api\Controller
|
||||
class invoices extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /nexus/invoices
|
||||
@@ -34,9 +46,10 @@ class _invoices 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\Invoice>
|
||||
* @apireturn PaginatedResponse<IPS\nexus\Invoice>
|
||||
* @return PaginatedResponse<Invoice>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
@@ -46,37 +59,37 @@ class _invoices extends \IPS\Api\Controller
|
||||
{
|
||||
$where[] = array( 'i_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
elseif ( isset( Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'i_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'i_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( 'i_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'i_status', array_filter( explode( ',', Request::i()->statuses ) ) ) );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'date', 'title', 'total' ) ) )
|
||||
if ( isset( Request::i()->sortBy ) and in_array( Request::i()->sortBy, array( 'date', 'title', 'total' ) ) )
|
||||
{
|
||||
$sortBy = 'i_' . \IPS\Request::i()->sortBy;
|
||||
$sortBy = 'i_' . Request::i()->sortBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sortBy = 'i_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_invoices', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
Db::i()->select( '*', 'nexus_invoices', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( Request::i()->page ) ? Request::i()->page : 1,
|
||||
'IPS\nexus\Invoice',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', $where )->first(),
|
||||
Db::i()->select( 'COUNT(*)', 'nexus_invoices', $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 _invoices extends \IPS\Api\Controller
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X299/1 INVALID_ID The invoice ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Invoice
|
||||
* @apireturn \IPS\nexus\Invoice
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$object = \IPS\nexus\Invoice::load( $id );
|
||||
$object = Invoice::load( $id );
|
||||
if ( $this->member and !$object->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
return new Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X299/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2X299/1', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,25 @@
|
||||
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\Response;
|
||||
use IPS\nexus\Purchase\LicenseKey;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
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 License Key API
|
||||
*/
|
||||
class _lkey extends \IPS\Api\Controller
|
||||
class lkey extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /nexus/lkey/{key}
|
||||
@@ -29,24 +38,25 @@ class _lkey extends \IPS\Api\Controller
|
||||
*
|
||||
* @param string $lkey License key
|
||||
* @throws 2X310/1 INVALID_KEY The license key does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Purchase
|
||||
* @apireturn \IPS\nexus\Purchase
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $lkey )
|
||||
public function GETitem( string $lkey ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( $lkey );
|
||||
$licenseKey = LicenseKey::load( $lkey );
|
||||
$purchase = $licenseKey->purchase;
|
||||
if ( $this->member and !$purchase->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
return new Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_KEY', '2X332/1', 404 );
|
||||
throw new Exception( 'INVALID_KEY', '2X332/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,24 +68,25 @@ class _lkey extends \IPS\Api\Controller
|
||||
* @apiparam object customFields Values for custom fields
|
||||
* @param string $lkey License key
|
||||
* @throws 2X310/2 INVALID_KEY The license key does not exist
|
||||
* @return \IPS\nexus\Purchase
|
||||
* @apireturn \IPS\nexus\Purchase
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $lkey )
|
||||
public function POSTitem( string $lkey ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( $lkey );
|
||||
$purchase = $licenseKey->purchase;
|
||||
$licenseKey = LicenseKey::load( $lkey );
|
||||
$purchase = $licenseKey->purchase;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_KEY', '2X332/2', 404 );
|
||||
throw new Exception( 'INVALID_KEY', '2X332/2', 404 );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->customFields ) )
|
||||
if ( isset( Request::i()->customFields ) )
|
||||
{
|
||||
$customFields = $purchase->custom_fields;
|
||||
foreach ( \IPS\Request::i()->customFields as $k => $v )
|
||||
foreach ( Request::i()->customFields as $k => $v )
|
||||
{
|
||||
$customFields[ $k ] = $v;
|
||||
}
|
||||
@@ -84,6 +95,6 @@ class _lkey extends \IPS\Api\Controller
|
||||
|
||||
$purchase->save();
|
||||
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
return new Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,30 @@
|
||||
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\Application;
|
||||
use IPS\Db;
|
||||
use IPS\nexus\Purchase;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Purchases API
|
||||
*/
|
||||
class _purchases extends \IPS\Api\Controller
|
||||
class purchases extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /nexus/purchases
|
||||
@@ -40,82 +54,83 @@ class _purchases 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\Purchase>
|
||||
* @apireturn PaginatedResponse<IPS\nexus\Purchase>
|
||||
* @return PaginatedResponse<Purchase>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
|
||||
/* Get only the purchases from active applications */
|
||||
$where[] = array( "ps_app IN('" . implode( "','", array_keys( \IPS\Application::enabledApplications() ) ) . "')" );
|
||||
$where[] = array( "ps_app IN('" . implode( "','", array_keys( Application::enabledApplications() ) ) . "')" );
|
||||
|
||||
/* Customers */
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( 'ps_member=?', $this->member->member_id );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->customers ) )
|
||||
elseif ( isset( Request::i()->customers ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'ps_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
|
||||
$where[] = array( Db::i()->in( 'ps_member', array_map( 'intval', array_filter( explode( ',', Request::i()->customers ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Status */
|
||||
if ( isset( \IPS\Request::i()->active ) )
|
||||
if ( isset( Request::i()->active ) )
|
||||
{
|
||||
$where[] = array( 'ps_active=?', \intval( \IPS\Request::i()->active ) );
|
||||
$where[] = array( 'ps_active=?', intval( Request::i()->active ) );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->canceled ) )
|
||||
if ( isset( Request::i()->canceled ) )
|
||||
{
|
||||
$where[] = array( 'ps_cancelled=?', \intval( \IPS\Request::i()->canceled ) );
|
||||
$where[] = array( 'ps_cancelled=?', intval( Request::i()->canceled ) );
|
||||
}
|
||||
|
||||
/* Item */
|
||||
if ( isset( \IPS\Request::i()->itemApp ) )
|
||||
if ( isset( Request::i()->itemApp ) )
|
||||
{
|
||||
$where[] = array( 'ps_app=?', \IPS\Request::i()->itemApp );
|
||||
$where[] = array( 'ps_app=?', Request::i()->itemApp );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->itemType ) )
|
||||
if ( isset( Request::i()->itemType ) )
|
||||
{
|
||||
$where[] = array( 'ps_type=?', \IPS\Request::i()->itemType );
|
||||
$where[] = array( 'ps_type=?', Request::i()->itemType );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->itemId ) )
|
||||
if ( isset( Request::i()->itemId ) )
|
||||
{
|
||||
$where[] = array( 'ps_item_id=?', \IPS\Request::i()->itemId );
|
||||
$where[] = array( 'ps_item_id=?', Request::i()->itemId );
|
||||
}
|
||||
|
||||
/* Parent */
|
||||
if ( isset( \IPS\Request::i()->parent ) )
|
||||
if ( isset( Request::i()->parent ) )
|
||||
{
|
||||
$where[] = array( 'ps_parent=?', \intval( \IPS\Request::i()->parent ) );
|
||||
$where[] = array( 'ps_parent=?', intval( Request::i()->parent ) );
|
||||
}
|
||||
|
||||
/* Show */
|
||||
if ( isset( \IPS\Request::i()->show ) )
|
||||
if ( isset( Request::i()->show ) )
|
||||
{
|
||||
$where[] = array( 'ps_show=?', \intval( \IPS\Request::i()->show ) );
|
||||
$where[] = array( 'ps_show=?', intval( Request::i()->show ) );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'start', 'expire' ) ) )
|
||||
if ( isset( Request::i()->sortBy ) and in_array( Request::i()->sortBy, array( 'start', 'expire' ) ) )
|
||||
{
|
||||
$sortBy = 'ps_' . \IPS\Request::i()->sortBy;
|
||||
$sortBy = 'ps_' . Request::i()->sortBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sortBy = 'ps_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_purchases', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
Db::i()->select( '*', 'nexus_purchases', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( Request::i()->page ) ? Request::i()->page : 1,
|
||||
'IPS\nexus\Purchase',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', $where )->first(),
|
||||
Db::i()->select( 'COUNT(*)', 'nexus_purchases', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,23 +140,24 @@ class _purchases extends \IPS\Api\Controller
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X310/1 INVALID_ID The purchase ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Purchase
|
||||
* @apireturn \IPS\nexus\Purchase
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$object = \IPS\nexus\Purchase::load( $id );
|
||||
$object = Purchase::load( $id );
|
||||
if ( $this->member and !$object->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
return new Response( 200, $object->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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,23 +169,24 @@ class _purchases extends \IPS\Api\Controller
|
||||
* @apiparam object customFields Values for custom fields
|
||||
* @param int $id ID Number
|
||||
* @throws 2X309/1 INVALID_ID The purchase ID does not exist
|
||||
* @return \IPS\nexus\Purchase
|
||||
* @apireturn \IPS\nexus\Purchase
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::load( $id );
|
||||
$purchase = Purchase::load( $id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X309/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2X309/1', 404 );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->customFields ) )
|
||||
if ( isset( Request::i()->customFields ) )
|
||||
{
|
||||
$customFields = $purchase->custom_fields;
|
||||
foreach ( \IPS\Request::i()->customFields as $k => $v )
|
||||
foreach ( Request::i()->customFields as $k => $v )
|
||||
{
|
||||
$customFields[ $k ] = $v;
|
||||
}
|
||||
@@ -178,6 +195,6 @@ class _purchases extends \IPS\Api\Controller
|
||||
|
||||
$purchase->save();
|
||||
|
||||
return new \IPS\Api\Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
return new Response( 200, $purchase->apiOutput( $this->member ) );
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Shipments API
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 10 Dec 2015
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shipments API
|
||||
*/
|
||||
class _shipments extends \IPS\Api\Controller
|
||||
{
|
||||
/**
|
||||
* GET /nexus/shipments
|
||||
* Get list of shipments
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only the members own shipments will be included
|
||||
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see order object for status keys
|
||||
* @apiparam string methods Comma-delimited list of shipping method IDs - if provided, only shipments from those methods are returned
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'shipped_date' or do not specify for ID
|
||||
* @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>
|
||||
*/
|
||||
public function GETindex()
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
|
||||
/* Statuses */
|
||||
if ( isset( \IPS\Request::i()->statuses ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'o_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
if ( isset( \IPS\Request::i()->methods ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'o_method', array_filter( explode( ',', \IPS\Request::i()->methods ) ) ) );
|
||||
}
|
||||
|
||||
/* Permission */
|
||||
if ( $this->member )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'o_invoice', iterator_to_array( \IPS\Db::i()->select( 'i_id', 'nexus_invoices', array( 'i_member=?', $this->member->member_id ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'date', 'shipped_date' ) ) )
|
||||
{
|
||||
$sortBy = 'o_' . \IPS\Request::i()->sortBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sortBy = 'o_id';
|
||||
}
|
||||
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\PaginatedResponse(
|
||||
200,
|
||||
\IPS\Db::i()->select( '*', 'nexus_ship_orders', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
'IPS\nexus\Shipping\Order',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_ship_orders', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /nexus/shipments/{id}
|
||||
* Get information about a specific shipment
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X307/1 INVALID_ID The shipment ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Shipping\Order
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( $id );
|
||||
if ( $this->member and !$shipment->invoice->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $shipment->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X308/1', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,294 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Replies API
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 11 Dec 2015
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Support Replies API
|
||||
*/
|
||||
class _supportreplies extends \IPS\Content\Api\CommentController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\nexus\Support\Reply';
|
||||
|
||||
/**
|
||||
* GET /nexus/supportreplies
|
||||
* Get list of support replies
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only topics the authorized user can view will be included - if the user is a staff member, will use their staff permissions
|
||||
* @apiparam int staffReplies If 1, only replies by staff will be included. If 0, only replies by non-staff.
|
||||
* @apiparam string authors Comma-delimited list of member IDs - if provided, only replies by those members are returned
|
||||
* @apiparam string departments Comma-delimited list of department IDs
|
||||
* @apiparam string statuses Comma-delimited list of status IDs
|
||||
* @apiparam string severities Comma-delimited list of severity IDs
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'title' or leave unspecified for ID
|
||||
* @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\Support\Reply>
|
||||
*/
|
||||
public function GETindex()
|
||||
{
|
||||
/* Init */
|
||||
$where = array();
|
||||
|
||||
/* Type */
|
||||
if ( isset( \IPS\Request::i()->staffReplies ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'reply_type', \IPS\Request::i()->staffReplies ? array( \IPS\nexus\Support\Reply::REPLY_STAFF, \IPS\nexus\Support\Reply::REPLY_HIDDEN ) : array( \IPS\nexus\Support\Reply::REPLY_MEMBER, \IPS\nexus\Support\Reply::REPLY_ALTCONTACT, \IPS\nexus\Support\Reply::REPLY_EMAIL ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'reply_type<>?', \IPS\nexus\Support\Reply::REPLY_PENDING );
|
||||
}
|
||||
|
||||
/* Departments */
|
||||
if ( isset( \IPS\Request::i()->departments ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_department', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->departments ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Statuses */
|
||||
if ( isset( \IPS\Request::i()->statuses ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_status', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Severities */
|
||||
if ( isset( \IPS\Request::i()->severities ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_severity', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Are we a staff member? */
|
||||
$bypassPerms = FALSE;
|
||||
if ( $this->member and $this->member->isAdmin() and \count( \IPS\nexus\Support\Department::departmentsWithPermission( $this->member ) ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_department', array_keys( iterator_to_array( \IPS\nexus\Support\Department::departmentsWithPermission( $this->member ) ) ) ) );
|
||||
$bypassPerms = TRUE;
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $this->_list( $where, NULL, $bypassPerms );
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /nexus/supportreplies/{id}
|
||||
* View information about a specific reply
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 2X314/1 INVALID_ID The reply ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Support\Reply
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$class = $this->class;
|
||||
if ( $this->member )
|
||||
{
|
||||
$object = $class::loadAndCheckPerms( $id, $this->member );
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = $class::load( $id );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $object->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X314/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /nexus/supportreplies
|
||||
* Create a reply
|
||||
*
|
||||
* @reqapiparam int request The ID number of the request the reply is for
|
||||
* @reqapiparam int author The ID number of the member making the post (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author.
|
||||
* @reqapiparam string message The reply content as HTML (e.g. "<p>This is a post.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
|
||||
* @apiparam datetime date The date/time that should be used for the topic/post post date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam string ip_address The IP address that should be stored for the topic/post. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam bool hidden If true will be added as a hidden note. Ignored if authorized member is not staff
|
||||
* @throws 2X314/2 NO_REQUEST The support request ID does not exist or the authorized user does not have permission to access it
|
||||
* @throws 1X314/3 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1X314/4 NO_MESSAGE No message was supplied
|
||||
* @return \IPS\nexus\Support\Reply
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
/* Get request */
|
||||
try
|
||||
{
|
||||
$request = \IPS\nexus\Support\Request::load( \IPS\Request::i()->request );
|
||||
if ( $this->member )
|
||||
{
|
||||
if ( $request->canView( $this->member ) )
|
||||
{
|
||||
// Okay
|
||||
}
|
||||
elseif ( $this->member->isAdmin() and ( $request->department->staff === '*' or \count( array_intersect( explode( ',', $request->department->staff ), Department::staffDepartmentPerms( $this->member ) ) ) ) )
|
||||
{
|
||||
// Okay
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_REQUEST', '2X314/2', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( $this->member )
|
||||
{
|
||||
$author = $this->member;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->author )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author );
|
||||
if ( !$author->member_id )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/3', 403 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->author === 0 )
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
$author->name = \IPS\Request::i()->author_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/3', 400 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a post */
|
||||
if ( !\IPS\Request::i()->message )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_MESSAGE', '1X314/4', 403 );
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
return $this->_create( $request, $author, 'message' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* @param \IPS\Content\Item $item Content Item
|
||||
* @param \IPS\Member $author Author
|
||||
* @param string $contentParam The parameter that contains the content body
|
||||
* @return \IPS\Api\Response
|
||||
*/
|
||||
protected function _createComment( \IPS\Content\Item $item, \IPS\Member $author, $contentParam='content' )
|
||||
{
|
||||
$comment = parent::_createComment( $item, $author, $contentParam );
|
||||
if ( $this->member )
|
||||
{
|
||||
if ( !$item->canView( $this->member ) )
|
||||
{
|
||||
$comment->type = $comment::REPLY_STAFF;
|
||||
if ( \IPS\Request::i()->hidden )
|
||||
{
|
||||
$comment->type = $comment::REPLY_HIDDEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
$comment->save();
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /nexus/supportreplies/{id}
|
||||
* Edit a reply
|
||||
*
|
||||
* @apiclientonly
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author The ID number of the member making the post (0 for guest)
|
||||
* @apiparam string message The post content as HTML (e.g. "<p>This is a post.</p>")
|
||||
* @throws 2X314/5 INVALID_ID The post ID does not exist
|
||||
* @throws 1X314/6 NO_AUTHOR The author ID does not exist
|
||||
* @return \IPS\forums\Topic\Post
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Load */
|
||||
$post = \IPS\nexus\Support\Reply::load( $id );
|
||||
|
||||
/* Do it */
|
||||
try
|
||||
{
|
||||
return $this->_edit( $post, 'message' );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/6', 400 );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X314/5', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /nexus/supportreplies/{id}
|
||||
* Deletes a reply
|
||||
*
|
||||
* @apiclientonly
|
||||
* @param int $id ID Number
|
||||
* @throws 2X314/7 INVALID_ID The post ID does not exist
|
||||
* @throws 1X314/8 CANNOT_DELETE_FIRST_POST You cannot delete the first reply to a request. Delete the request itself instead.
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$reply = \IPS\nexus\Support\Reply::load( $id );
|
||||
|
||||
if ( $reply->isFirst() )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'CANNOT_DELETE_FIRST_POST', '1X314/8', 403 );
|
||||
}
|
||||
|
||||
$reply->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X314/7', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,402 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Support Requests API
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 4 Dec 2015
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Support Requests API
|
||||
*/
|
||||
class _supportrequests extends \IPS\Content\Api\ItemController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\nexus\Support\Request';
|
||||
|
||||
/**
|
||||
* GET /nexus/supportrequests
|
||||
* Get list of support requests
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, only topics the authorized user can view will be included - if the user is a staff member, will use their staff permissions
|
||||
* @apiparam string authors Comma-delimited list of member IDs - if provided, only support requests belonging to those members (or emails specified by email param) are returned
|
||||
* @apiparam string email Comma-delimited list of email addresses - if provided, only support requests created by those emails (or members specified by authors param) are returned
|
||||
* @apiparam string departments Comma-delimited list of department IDs
|
||||
* @apiparam string statuses Comma-delimited list of status IDs
|
||||
* @apiparam string severities Comma-delimited list of severity IDs
|
||||
* @apiparam string purchases Comma-delimited list of purchase IDs - if provided, only support requests associated with one of the provided purchase IDs are returned
|
||||
* @apiparam string staff Comma-delimited list of member IDs - if provided, only support requests assigned to the staff members with one of the provided IDs are returned
|
||||
* @apiparam int hidden If 1, only replies which are hidden are returned, if 0 only not hidden
|
||||
* @apiparam string sortBy What to sort by. Can be 'date', 'title' or leave unspecified for ID
|
||||
* @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\Support\Request>
|
||||
*/
|
||||
public function GETindex()
|
||||
{
|
||||
/* Init */
|
||||
$where = array();
|
||||
|
||||
/* Authors */
|
||||
if ( isset( \IPS\Request::i()->authors ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->authors ) ) ) ) );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->authors ) and isset( \IPS\Request::i()->emails ) )
|
||||
{
|
||||
$where[] = array( '( ' . \IPS\Db::i()->in( 'r_member', array_filter( explode( ',', \IPS\Request::i()->authors ) ) ) . ' OR ' . \IPS\Db::i()->in( 'r_email', array_filter( explode( ',', \IPS\Request::i()->emails ) ) ) . ' )' );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->authors ) )
|
||||
{
|
||||
$where[] = array( '( ' . \IPS\Db::i()->in( 'r_member', array_filter( explode( ',', \IPS\Request::i()->authors ) ) ) . ' OR r_email<>? )', '' );
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->emails ) )
|
||||
{
|
||||
$where[] = array( '( r_member>0 OR ' . \IPS\Db::i()->findInSet( 'r_email', array_filter( explode( ',', \IPS\Request::i()->emails ) ) ) . ' )' );
|
||||
}
|
||||
|
||||
/* Departments */
|
||||
if ( isset( \IPS\Request::i()->departments ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_department', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->departments ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Statuses */
|
||||
if ( isset( \IPS\Request::i()->statuses ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_status', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Severities */
|
||||
if ( isset( \IPS\Request::i()->severities ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_severity', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Purchases */
|
||||
if ( isset( \IPS\Request::i()->purchases ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_purchase', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->purchases ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Staff */
|
||||
if ( isset( \IPS\Request::i()->staff ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_staff', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->staff ) ) ) ) );
|
||||
}
|
||||
|
||||
/* Are we a staff member? */
|
||||
$bypassPerms = FALSE;
|
||||
if ( $this->member and $this->member->isAdmin() and \count( \IPS\nexus\Support\Department::departmentsWithPermission( $this->member ) ) )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'r_department', array_keys( iterator_to_array( \IPS\nexus\Support\Department::departmentsWithPermission( $this->member ) ) ) ) );
|
||||
$bypassPerms = TRUE;
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $this->_list( $where, NULL, $bypassPerms );
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /nexus/supportrequests/{id}
|
||||
* Get information about and replies to a specific support request
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int hidden If 1, only posts which are hidden are returned, if 0 only not hidden
|
||||
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
|
||||
* @throws 2X313/1 INVALID_ID The request does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Support\Request
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = \IPS\nexus\Support\Request::load( $id );
|
||||
if ( $this->member and !$request->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 200, $request->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /nexus/supportrequests/{id}/replies
|
||||
* Get replies to a specific support request
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @apiparam int hidden If 1, only replies which are hidden are returned, if 0 only not hidden
|
||||
* @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
|
||||
* @throws 2X313/2 INVALID_ID The request does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Support\Reply>
|
||||
*/
|
||||
public function GETitem_replies( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = \IPS\nexus\Support\Request::load( $id );
|
||||
if ( $this->member and !$request->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return $this->_comments( $id, 'IPS\nexus\Support\Reply', array( array( 'reply_type<>?', \IPS\nexus\Support\Reply::REPLY_PENDING ) ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/2', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create or update item
|
||||
*
|
||||
* @param \IPS\Content\Item $item The item
|
||||
* @param string $type add or edit
|
||||
* @return \IPS\Content\Item
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Content\Item $item, $type='add' )
|
||||
{
|
||||
/* Department, status, etc */
|
||||
foreach ( array( 'department' => 'IPS\nexus\Support\Department', 'status' => 'IPS\nexus\Support\Status', 'severity' => 'IPS\nexus\Support\Severity', 'purchase' => 'IPS\nexus\Purchase', 'staff' => 'IPS\Member' ) as $key => $class )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$key ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$object = $class::load( \IPS\Request::i()->$key );
|
||||
|
||||
if ( $this->member )
|
||||
{
|
||||
if ( $key === 'department' and $type == 'edit' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( $key === 'severity' and ( !$this->member->cm_no_sev or !\in_array( $object, \IPS\nexus\Support\Department::load( \IPS\Request::i()->department )->availableSeverities() ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( $key === 'purchase' and ( $type == 'edit' or !$object->canView( $this->member ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( $key === 'staff' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if ( $key === 'status' and ( $type == 'add' or !\IPS\Member::loggedIn()->language()->checkKeyExists("nexus_status_{$object->id}_set") ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$item->$key = $object;
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
}
|
||||
}
|
||||
if ( ( $type == 'add' or !$this->member ) and !isset( \IPS\Request::i()->purchase ) and isset( \IPS\Request::i()->lkey ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( \IPS\Request::i()->lkey );
|
||||
if ( !$this->member or $licenseKey->purchase->canView( $this->member ) )
|
||||
{
|
||||
$item->purchase = $licenseKey->purchase;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
}
|
||||
|
||||
/* Defaults */
|
||||
if ( !$item->id )
|
||||
{
|
||||
if ( !$item->_data['status'] )
|
||||
{
|
||||
$item->status = \IPS\nexus\Support\Status::load( TRUE, 'status_default_member' );
|
||||
}
|
||||
if ( !$item->_data['severity'] )
|
||||
{
|
||||
$item->severity = \IPS\nexus\Support\Severity::load( TRUE, 'sev_default' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Cannot edit title */
|
||||
if ( $this->member and $type == 'edit' )
|
||||
{
|
||||
unset( \IPS\Request::i()->title );
|
||||
}
|
||||
|
||||
/* Pass up */
|
||||
return parent::_createOrUpdate( $item );
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /nexus/supportrequests
|
||||
* Create a support request
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, pay-per-incident departments cannot be used. Any parameters the user doesn't have permission to use are ignored (for example, severities they cannot set).
|
||||
* @reqapiparam string title The support request title
|
||||
* @reqapiparam int department Department ID number
|
||||
* @reqapiparam int account The ID number of the member creating the support request - not required if email is provided. For requests using an OAuth Access Token for a particular member, this is ignored and that member will always be the author.
|
||||
* @reqapiparam string email The email address creating the support request - not required if account is provided. For requests using an OAuth Access Token for a particular member, this is ignored and that member will always be the author.
|
||||
* @reqapiparam string message The content as HTML (e.g. "<p>This is a support request.</p>"). Will be sanatized for requests using an OAuth Access Token for a particular member; will be saved unaltered for requests made using an API Key or the Client Credentials Grant Type.
|
||||
* @apiparam int status Status ID number. If not provided, will use the default. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam int severity Severity ID number. If not provided, will use the default.
|
||||
* @apiparam int purchase Associated purchase ID number.
|
||||
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided)
|
||||
* @apiparam int staff Assigned staff ID number. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @apiparam datetime date The date/time that should be used for the support request date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @throws 1X313/3 NO_DEPARTMENT The department does not exist
|
||||
* @throws 1X313/6 NO_PERMISSION The request is for an authorizes member and the department does not accept submissions or is pay-per-incident
|
||||
* @throws 1X313/4 NO_AUTHOR The author ID does not exist
|
||||
* @throws 1X313/5 NO_TITLE No title was supplied
|
||||
* @throws 1X313/4 NO_POST No post was supplied
|
||||
* @return \IPS\nexus\Support\Request
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
/* Get department */
|
||||
try
|
||||
{
|
||||
$department = \IPS\nexus\Support\Department::load( \IPS\Request::i()->department );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_DEPARTMENT', '1X313/3', 400 );
|
||||
}
|
||||
if ( $this->member and ( !$department->open or $department->ppiCost() ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_PERMISSION', '1X313/6', 403 );
|
||||
}
|
||||
|
||||
/* Get author */
|
||||
if ( $this->member )
|
||||
{
|
||||
$author = $this->member;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\Request::i()->account )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->account );
|
||||
if ( !$author->member_id )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X313/4', 400 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$author = new \IPS\Member;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check we have a title and a post */
|
||||
if ( !\IPS\Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1X313/5', 400 );
|
||||
}
|
||||
if ( !\IPS\Request::i()->message )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_POST', '1X313/4', 400 );
|
||||
}
|
||||
|
||||
/* Create */
|
||||
$item = $this->_create( NULL, $author, 'message' );
|
||||
|
||||
/* Email */
|
||||
if ( !$this->member and isset( \IPS\Request::i()->email ) )
|
||||
{
|
||||
$item->email = \IPS\Request::i()->email;
|
||||
$item->save();
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
return new \IPS\Api\Response( 201, $item->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /nexus/supportrequests/{id}
|
||||
* Edit a support request
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, severities they cannot set).
|
||||
* @apiparam string title The support request title. Ignored for requests using an OAuth Access Token for a particular member (users cannot edit request titles after they're created)
|
||||
* @apiparam int department Department ID number. Ignored for requests using an OAuth Access Token for a particular member (users cannot move requests after they're created)
|
||||
* @apiparam int status Status ID number. If not provided, will use the default.
|
||||
* @apiparam int severity Severity ID number. If not provided, will use the default.
|
||||
* @apiparam int purchase Associated purchase ID number. Ignored for requests using an OAuth Access Token for a particular member (users cannot change associated purchase of request after its created)
|
||||
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided). Ignored for requests using an OAuth Access Token for a particular member (users cannot change associated purchase of request after its created)
|
||||
* @apiparam int staff Assigned staff ID number. Ignored for requests using an OAuth Access Token for a particular member
|
||||
* @param int $id ID Number
|
||||
* @throws 2X313/7 INVALID_ID The topic ID does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\nexus\Support\Request
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = \IPS\nexus\Support\Request::load( $id );
|
||||
if ( $this->member and !$request->canView( $this->member ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
/* Process */
|
||||
$this->_createOrUpdate( $request, 'edit' );
|
||||
|
||||
/* Save and return */
|
||||
$request->save();
|
||||
return new \IPS\Api\Response( 200, $request->apiOutput( $this->member ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/7', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /nexus/supportrequests/{id}
|
||||
* Delete a support request
|
||||
*
|
||||
* @apiclientonly
|
||||
* @param int $id ID Number
|
||||
* @throws 1F294/5 INVALID_ID The topic ID does not exist
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\nexus\Support\Request::load( $id )->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/8', 404 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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