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

@@ -12,43 +12,62 @@
namespace IPS\nexus\Gateway;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\core\AdminNotification;
use IPS\DateTime;
use IPS\File;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Translatable;
use IPS\Lang;
use IPS\nexus\Customer;
use IPS\nexus\Customer\CreditCard;
use IPS\nexus\Fraud\MaxMind\Request;
use IPS\nexus\Gateway;
use IPS\nexus\Invoice;
use IPS\nexus\Money;
use IPS\nexus\Transaction;
use IPS\Output;
use LogicException;
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;
}
/**
* Manual Gateway
*/
class _Manual extends \IPS\nexus\Gateway
class Manual extends Gateway
{
/* !Payment Gateway */
/**
* Authorize
*
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @param Transaction $transaction Transaction
* @param array|CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @param array $recurrings Details about recurring costs
* @param string|NULL $source 'checkout' if the customer is doing this at a normal checkout, 'renewal' is an automatically generated renewal invoice, 'manual' is admin manually charging. NULL is unknown
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
* @param string|NULL $source 'checkout' if the customer is doing this at a normal checkout, 'renewal' is an automatically generated renewal invoice, 'manual' is admin manually charging. NULL is unknown
* @return array|DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array(), $source = NULL )
public function auth(Transaction $transaction, array|CreditCard $values, Request $maxMind = NULL, array $recurrings = array(), ?string $source = NULL ): DateTime|array|null
{
$transaction->status = \IPS\nexus\Transaction::STATUS_WAITING;
$transaction->status = Transaction::STATUS_WAITING;
$extra = $transaction->extra;
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_WAITING );
$extra['history'][] = array( 's' => Transaction::STATUS_WAITING );
$transaction->extra = $extra;
$transaction->save();
/* Send Notification */
$transaction->sendNotification();
\IPS\core\AdminNotification::send( 'nexus', 'Transaction', \IPS\nexus\Transaction::STATUS_WAITING, TRUE, $transaction );
AdminNotification::send( 'nexus', 'Transaction', Transaction::STATUS_WAITING, TRUE, $transaction );
\IPS\Output::i()->redirect( $transaction->url() );
Output::i()->redirect( $transaction->url() );
}
/* !ACP Configuration */
@@ -56,12 +75,12 @@ class _Manual extends \IPS\nexus\Gateway
/**
* Settings
*
* @param \IPS\Helpers\Form $form The form
* @return void
* @param Form $form The form
* @return void
*/
public function settings( &$form )
public function settings( Form $form ): void
{
$form->add( new \IPS\Helpers\Form\Translatable( 'manual_instructions', NULL, TRUE, array( 'app' => 'nexus', 'key' => ( $this->id ? "nexus_gateway_{$this->id}_ins" : NULL ), 'editor' => array( 'app' => 'nexus', 'key' => 'Admin', 'autoSaveKey' => ( $this->id ? "nexus-gateway-{$this->id}" : "nexus-new-gateway" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'description' ) : NULL, 'minimize' => 'manual_gateway_description_placeholder' ) ) ) );
$form->add( new Translatable( 'manual_instructions', NULL, TRUE, array( 'app' => 'nexus', 'key' => ( $this->id ? "nexus_gateway_{$this->id}_ins" : NULL ), 'editor' => array( 'app' => 'nexus', 'key' => 'Admin', 'autoSaveKey' => ( $this->id ? "nexus-gateway-{$this->id}" : "nexus-new-gateway" ), 'attachIds' => $this->id ? array( $this->id, NULL, 'description' ) : NULL, 'minimize' => 'manual_gateway_description_placeholder' ) ) ) );
}
/**
@@ -70,44 +89,72 @@ class _Manual extends \IPS\nexus\Gateway
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
if ( !$this->id )
{
$this->save();
\IPS\File::claimAttachments( 'nexus_gateway_new', $this->id, NULL, 'gateway', TRUE );
File::claimAttachments( 'nexus_gateway_new', $this->id, NULL, 'gateway', TRUE );
}
if( isset( $values['manual_instructions'] ) )
{
\IPS\Lang::saveCustom( 'nexus', "nexus_gateway_{$this->id}_ins", $values['manual_instructions'] );
Lang::saveCustom( 'nexus', "nexus_gateway_{$this->id}_ins", $values['manual_instructions'] );
unset( $values['manual_instructions'] );
}
return parent::formatFormValues( $values );
}
/**
* Test Settings
*
* @param array $settings Settings
* @return array
* @throws \InvalidArgumentException
*/
public function testSettings( $settings=array() )
{
return $settings;
}
/**
* Refund
*
* @param \IPS\nexus\Transaction $transaction Transaction to be refunded
* @param float|NULL $amount Amount to refund (NULL for full amount - always in same currency as transaction)
* @return mixed Gateway reference ID for refund, if applicable
* @param Transaction $transaction Transaction to be refunded
* @param mixed|NULL $amount Amount to refund (NULL for full amount - always in same currency as transaction)
* @param string|null $reason
* @return mixed Gateway reference ID for refund, if applicable
*/
public function refund( \IPS\nexus\Transaction $transaction, $amount = NULL )
public function refund(Transaction $transaction, mixed $amount = NULL, ?string $reason = NULL): mixed
{
return null;
}
/**
* Payment Screen Fields
*
* @param Invoice $invoice Invoice
* @param Money $amount The amount to pay now
* @param Customer|null $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @param string $type 'checkout' means the cusotmer is doing this on the normal checkout screen, 'admin' means the admin is doing this in the ACP, 'card' means the user is just adding a card
* @return array
*/
public function paymentScreen(Invoice $invoice, Money $amount, ?Customer $member = NULL, array $recurrings = array(), string $type = 'checkout'): array
{
return [];
}
/**
* Capture
*
* @param Transaction $transaction Transaction
* @return void
* @throws LogicException
*/
public function capture(Transaction $transaction): void
{
}
/**
* Test Settings
*
* @param array $settings Settings
* @return array
* @throws InvalidArgumentException
*/
public function testSettings(array $settings = array()): array
{
return $settings;
}
}
@@ -12,42 +12,63 @@
namespace IPS\nexus\Gateway\Manual;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use IPS\Helpers\Form\Text;
use IPS\Helpers\Form\TextArea;
use IPS\nexus\Payout as NexusPayout;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
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;
}
/**
* Manual Pay Out Gateway
*/
class _Payout extends \IPS\nexus\Payout
class Payout extends NexusPayout
{
/**
* @brief Requires manual approval?
*/
public static $requiresApproval = TRUE;
public static bool $requiresApproval = TRUE;
/**
* Extra HTML to display when the admin view the Payout in the ACP
*
* @return string
*/
public function acpHtml() : string
{
return Theme::i()->getTemplate( 'payouts', 'nexus' )->Manual( $this );
}
/**
* ACP Settings
*
* @return array
*/
public static function settings()
public static function settings() : array
{
$settings = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
$settings = json_decode( Settings::i()->nexus_payout, TRUE );
$return = array();
$return[] = new \IPS\Helpers\Form\Text( 'manual_name', isset( $settings['Manual'] ) ? $settings['Manual']['name'] : '' , NULL, array(), function( $val ) {
if ( !$val AND isset( \IPS\Request::i()->nexus_payout['Manual'] ) AND \IPS\Request::i()->nexus_payout['Manual'] == 1 )
$return[] = new Text( 'manual_name', isset( $settings['Manual'] ) ? $settings['Manual']['name'] : '' , NULL, array(), function( $val ) {
if ( !$val AND isset( Request::i()->nexus_payout['Manual'] ) AND Request::i()->nexus_payout['Manual'] == 1 )
{
throw new \DomainException( 'form_required' );
throw new DomainException( 'form_required' );
}
});
$return[] = new \IPS\Helpers\Form\Text( 'manual_title', isset( $settings['Manual'] ) ? $settings['Manual']['title'] : '', NULL, array(), function( $val ) {
if ( !$val AND isset( \IPS\Request::i()->nexus_payout['Manual'] ) AND \IPS\Request::i()->nexus_payout['Manual'] == 1 )
$return[] = new Text( 'manual_title', isset( $settings['Manual'] ) ? $settings['Manual']['title'] : '', NULL, array(), function( $val ) {
if ( !$val AND isset( Request::i()->nexus_payout['Manual'] ) AND Request::i()->nexus_payout['Manual'] == 1 )
{
throw new \DomainException( 'form_required' );
throw new DomainException( 'form_required' );
}
});
@@ -59,11 +80,11 @@ class _Payout extends \IPS\nexus\Payout
*
* @return array
*/
public static function form()
public static function form() : array
{
$settings = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
$settings = json_decode( Settings::i()->nexus_payout, TRUE );
$field = new \IPS\Helpers\Form\TextArea( 'manual_details', NULL, TRUE, array() );
$field = new TextArea( 'manual_details', NULL, TRUE, array() );
$field->label = $settings['Manual']['title'];
return array( $field );
}
@@ -73,23 +94,22 @@ class _Payout extends \IPS\nexus\Payout
*
* @param array $values Values from form
* @return mixed
* @throws \DomainException
* @throws DomainException
*/
public function getData( array $values )
public function getData( array $values ) : mixed
{
return $values['manual_details'];
}
/**
* Process
/**
* Process the payout
* Return the new status for this payout record
*
* @return void
* @throws \Exception
* @return string
* @throws Exception
*/
public function process()
public function process() : string
{
$this->status = static::STATUS_COMPLETE;
$this->completed = new \IPS\DateTime;
$this->save();
return static::STATUS_COMPLETE;
}
}