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

+32 -17
View File
@@ -12,16 +12,27 @@
namespace IPS\nexus\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use IPS\DateTime;
use IPS\Db;
use IPS\nexus\Transaction;
use IPS\Task;
use IPS\Task\Exception;
use UnderflowException;
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;
}
/**
* Task to capture payments approaching their authorization deadlines
*/
class _capture extends \IPS\Task
class capture extends Task
{
/**
* Execute
@@ -31,19 +42,19 @@ class _capture extends \IPS\Task
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
* Tasks should execute within the time of a normal HTTP request.
*
* @return mixed Message to log or NULL
* @throws \IPS\Task\Exception
* @return string|null Message to log or NULL
* @throws Exception
*/
public function execute()
public function execute() : string|null
{
$taskFrequency = new \DateInterval( $this->frequency );
$time = \IPS\DateTime::create()->add( $taskFrequency )->add( $taskFrequency );
$taskFrequency = new DateInterval( $this->frequency );
$time = DateTime::create()->add( $taskFrequency )->add( $taskFrequency );
$this->runUntilTimeout( function() use ( $time )
{
try
{
$transaction = \IPS\nexus\Transaction::constructFromData( \IPS\Db::i()->select( '*', 'nexus_transactions', array( 't_auth<?', $time->getTimestamp() ), 't_auth ASC', 1 )->first() );
$transaction = Transaction::constructFromData( Db::i()->select( '*', 'nexus_transactions', array( 't_auth<?', $time->getTimestamp() ), 't_auth ASC', 1 )->first() );
if ( $transaction->method )
{
@@ -53,11 +64,11 @@ class _capture extends \IPS\Task
}
catch ( \Exception $e )
{
if ( \in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
if ( in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
{
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
$transaction->status = Transaction::STATUS_REFUSED;
$extra = $transaction->extra;
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'noteRaw' => $e->getMessage() );
$extra['history'][] = array( 's' => Transaction::STATUS_REFUSED, 'noteRaw' => $e->getMessage() );
$transaction->extra = $extra;
}
@@ -70,19 +81,23 @@ class _capture extends \IPS\Task
/* the gateway doesn't exist anymore, so reset the auth time */
$transaction->auth = NULL;
$extra = $transaction->extra;
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'on' => time(), 'noteRaw' => 'invalid_gateway' );
$extra['history'][] = array( 's' => Transaction::STATUS_REFUSED, 'on' => time(), 'noteRaw' => 'invalid_gateway' );
$transaction->extra = $extra;
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
$transaction->status = Transaction::STATUS_REFUSED;
$transaction->save();
throw new \IPS\Task\Exception( $this, array( 'invalid_gateway', $transaction->id ) );
throw new Exception( $this, array( 'invalid_gateway', $transaction->id ) );
}
}
catch ( \UnderflowException $e )
catch ( UnderflowException )
{
return FALSE;
}
return NULL;
});
return null;
}
/**
@@ -94,7 +109,7 @@ class _capture extends \IPS\Task
*
* @return void
*/
public function cleanup()
public function cleanup() : void
{
}