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

+28 -28
View File
@@ -12,16 +12,25 @@
namespace IPS\nexus\tasks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Db;
use IPS\nexus\Gateway\Paypal;
use IPS\nexus\Transaction;
use IPS\Task;
use function count;
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;
}
/**
* gatewayPending Task
*/
class _gatewayPending extends \IPS\Task
class gatewayPending extends Task
{
/**
* Execute
@@ -31,25 +40,13 @@ class _gatewayPending 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 Task\Exception
*/
public function execute()
public function execute() : string|null
{
$paypalGateways = [];
foreach( \IPS\nexus\Gateway::roots( null ) as $gateway )
{
if( $gateway instanceof \IPS\nexus\Gateway\PayPal )
{
$paypalGateways[] = $gateway->_id;
}
}
$transactions = \IPS\Db::i()->select( '*', 'nexus_transactions', array(
array( 't_status=?', \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ),
array( \IPS\Db::i()->in( 't_method', $paypalGateways ) )
), 't_id ASC', 20 ); // We deliberately don't run until exhaustion here because we want to wait and try again later if it fails
if ( !\count( $transactions ) )
$transactions = Db::i()->select( '*', 'nexus_transactions', array( 't_status=?', Transaction::STATUS_GATEWAY_PENDING ), 't_id ASC', 20 ); // We deliberately don't run until exhaustion here because we want to wait and try again later if it fails
if ( !count( $transactions ) )
{
$this->enabled = FALSE;
$this->save();
@@ -59,20 +56,21 @@ class _gatewayPending extends \IPS\Task
foreach ( $transactions as $transaction )
{
/* Get it */
$transaction = \IPS\nexus\Transaction::constructFromData( $transaction );
$transaction = Transaction::constructFromData( $transaction );
if ( $transaction->method instanceof \IPS\nexus\Gateway\Paypal )
/* @var Transaction $transaction */
if ( $transaction->method instanceof Paypal )
{
/* Try to capture it */
try
{
$transaction->capture();
}
catch ( \Exception $e )
catch ( Exception $e )
{
if ( $e->getMessage() === 'FAIL' or $e->getMessage() === 'RFND' or $transaction->date->getTimestamp() < ( time() - ( 86400 * 5 ) ) )
{
$status = $e->getMessage() === 'RFND' ? \IPS\nexus\Transaction::STATUS_REFUNDED : \IPS\nexus\Transaction::STATUS_REFUSED;
$status = $e->getMessage() === 'RFND' ? Transaction::STATUS_REFUNDED : Transaction::STATUS_REFUSED;
$transaction->status = $status;
$transaction->save();
@@ -82,7 +80,7 @@ class _gatewayPending extends \IPS\Task
'id' => $transaction->id
), FALSE );
if ( $status === \IPS\nexus\Transaction::STATUS_REFUNDED )
if ( $status === Transaction::STATUS_REFUNDED )
{
$transaction->sendNotification();
}
@@ -94,9 +92,9 @@ class _gatewayPending extends \IPS\Task
$fraudResult = $transaction->fraud_blocked ? $transaction->fraud_blocked->action : NULL;
if ( $fraudResult )
{
$transaction->executeFraudAction( $fraudResult, TRUE );
$transaction->executeFraudAction( $fraudResult );
}
if ( !$fraudResult or $fraudResult === \IPS\nexus\Transaction::STATUS_PAID )
if ( !$fraudResult or $fraudResult === Transaction::STATUS_PAID )
{
$transaction->approve();
}
@@ -106,6 +104,8 @@ class _gatewayPending extends \IPS\Task
}
}
}
return null;
}
/**
@@ -117,7 +117,7 @@ class _gatewayPending extends \IPS\Task
*
* @return void
*/
public function cleanup()
public function cleanup() : void
{
}