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

+48 -29
View File
@@ -12,16 +12,33 @@
namespace IPS\nexus\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use Exception;
use InvalidArgumentException;
use IPS\Db;
use IPS\Helpers\Form;
use IPS\Helpers\Form\FormAbstract;
use IPS\Member;
use IPS\nexus\CreditCard as CreditCardClass;
use IPS\nexus\Customer\CreditCard as CustomerCardClass;
use IPS\Theme;
use LogicException;
use function defined;
use function in_array;
use function intval;
use function is_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;
}
/**
* Credit card input class for Form Builder
*/
class _CreditCard extends \IPS\Helpers\Form\FormAbstract
class CreditCard extends FormAbstract
{
/**
* @brief Default Options
@@ -38,7 +55,7 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
);
* @endcode
*/
protected $defaultOptions = array(
protected array $defaultOptions = array(
'types' => array(),
'save' => NULL,
'member' => NULL,
@@ -55,22 +72,22 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
*
* @return string
*/
public function html()
public function html(): string
{
$member = $this->options['member'] ?: \IPS\Member::loggedIn();
$member = $this->options['member'] ?: Member::loggedIn();
$number = '';
$expMonth = NULL;
$expYear = NULL;
$ccv = '';
if ( \is_array( $this->value ) )
if ( is_array( $this->value ) )
{
$number = $this->value['number'];
$expMonth = $this->value['exp_month'];
$expYear = $this->value['exp_year'];
$ccv = $this->value['ccv'];
}
elseif ( $this->value instanceof \IPS\nexus\CreditCard )
elseif ( $this->value instanceof CreditCardClass )
{
$number = $this->value->number;
$expMonth = $this->value->expMonth;
@@ -81,34 +98,34 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
$types = array();
foreach ( $this->options['types'] as $type )
{
$types[ $type ] = \IPS\Member::loggedIn()->language()->addToStack( 'card_type_' . $type );
$types[ $type ] = Member::loggedIn()->language()->addToStack( 'card_type_' . $type );
}
$storedCards = array();
if ( $member->member_id and $this->options['save'] )
{
foreach( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=? AND card_method=?', $member->member_id, $this->options['save']->id ) ) as $card )
foreach( Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=? AND card_method=?', $member->member_id, $this->options['save']->id ) ) as $card )
{
try
{
$card = \IPS\nexus\Customer\CreditCard::constructFromData( $card );
$card = CustomerCardClass::constructFromData( $card );
$card->card; // This is just to make the API call now and cache the response so we can catch the exception if one is thrown
$storedCards[ $card->id ] = $card;
}
catch ( \Exception $e ) {}
catch ( Exception ) {}
}
}
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->creditCard( $this, $types, $number, \intval( $expMonth ), \intval( $expYear ), $ccv, $storedCards );
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->creditCard( $this, $types, $number, intval( $expMonth ), intval( $expYear ), $ccv, $storedCards );
}
/**
* Get HTML
*
* @param \IPS\Helpers\Form|null $form Form helper object
* @param Form|null $form Form helper object
* @return string
*/
public function rowHtml( $form=NULL )
public function rowHtml( Form $form=NULL ): string
{
if ( !$this->htmlId and $form )
{
@@ -123,16 +140,16 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
*
* @return mixed
*/
public function formatValue()
public function formatValue(): mixed
{
$member = $this->options['member'] ?: \IPS\Member::loggedIn();
$member = $this->options['member'] ?: Member::loggedIn();
if ( $this->value !== NULL and !( $this->value instanceof \IPS\nexus\CreditCard ) and !( $this->value instanceof \IPS\nexus\Customer\CreditCard ) )
if ( $this->value !== NULL and !( $this->value instanceof CreditCard ) and !( $this->value instanceof CustomerCardClass) )
{
/* Stored Card */
if ( $this->options['save'] and isset( $this->value['stored'] ) and $this->value['stored'] and ( !isset( $this->value['number'] ) or !$this->value['number'] ) and ( !isset( $this->value['token'] ) or !$this->value['token'] ) )
{
$card = \IPS\nexus\Customer\CreditCard::load( $this->value['stored'] );
$card = CustomerCardClass::load( $this->value['stored'] );
if ( $card->member->member_id === $member->member_id and $card->method->id === $this->options['save']->id )
{
return $card;
@@ -144,7 +161,7 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
/* If we don't send the values, we won't have them */
if ( !$this->options['names'] )
{
$obj = new \IPS\nexus\CreditCard;
$obj = new CustomerCardClass;
if ( isset( $this->value['token'] ) )
{
$obj->token = $this->value['token'];
@@ -165,18 +182,20 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
/* But if we do, we can build an object */
try
{
return \IPS\nexus\CreditCard::build( $this->value['number'], $this->value['exp_month'], $this->value['exp_year'], $this->value['ccv'], ( $this->options['save'] and isset( $this->value['save'] ) and $this->value['save'] ) );
return CreditCardClass::build( $this->value['number'], $this->value['exp_month'], $this->value['exp_year'], $this->value['ccv'], ( $this->options['save'] and isset( $this->value['save'] ) and $this->value['save'] ) );
}
catch ( \InvalidArgumentException $e )
catch ( InvalidArgumentException $e )
{
throw new \DomainException( $e->getMessage() );
throw new DomainException( $e->getMessage() );
}
catch ( \DomainException $e )
catch ( DomainException )
{
throw new \DomainException( 'card_expire_expired' );
throw new DomainException( 'card_expire_expired' );
}
}
}
return '';
}
/**
@@ -184,13 +203,13 @@ class _CreditCard extends \IPS\Helpers\Form\FormAbstract
*
* @return mixed
*/
public function validate()
public function validate(): bool
{
if ( $this->value instanceof \IPS\nexus\CreditCard )
if ( $this->value instanceof CreditCard )
{
if ( $this->value->type and !\in_array( $this->value->type, $this->options['types'] ) )
if ( $this->value->type and !in_array( $this->value->type, $this->options['types'] ) )
{
throw new \LogicException( \IPS\Member::loggedIn()->language()->addToStack( 'card_bad_type', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( "card_type_" . $this->value->type ) ) ) ) );
throw new LogicException( Member::loggedIn()->language()->addToStack( 'card_bad_type', FALSE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( "card_type_" . $this->value->type ) ) ) ) );
}
}