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,16 +12,31 @@
namespace IPS\nexus\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use InvalidArgumentException;
use IPS\GeoLocation;
use IPS\Helpers\Form\Address;
use IPS\Http\Request\Exception;
use IPS\Log;
use IPS\nexus\Tax;
use IPS\Output;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
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;
}
/**
* Consumer/business address input class for Form Builder
*/
class _BusinessAddress extends \IPS\Helpers\Form\Address
class BusinessAddress extends Address
{
/**
* @brief Default Options
@@ -33,7 +48,7 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
);
* @endcode
*/
protected $defaultOptions = array(
protected array $defaultOptions = array(
'minimize' => FALSE,
'requireFullAddress' => TRUE,
'vat' => FALSE
@@ -44,14 +59,14 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
*
* @return string
*/
public function html()
public function html(): string
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_forms.js', 'nexus', 'global' ) );
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'global_forms.js', 'nexus', 'global' ) );
/* If we don't have a value, set their country based on the HTTP headers */
if ( !$this->value OR ( $this->value instanceof \IPS\GeoLocation AND !$this->value->country ) )
if ( !$this->value OR ( $this->value instanceof GeoLocation AND !$this->value->country ) )
{
$this->value = ( $this->value instanceof \IPS\GeoLocation ) ? $this->value : new \IPS\GeoLocation;
$this->value = ( $this->value instanceof GeoLocation ) ? $this->value : new GeoLocation;
if ( $defaultCountry = static::calculateDefaultCountry() )
{
$this->value->country = $defaultCountry;
@@ -65,7 +80,7 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
}
/* Display */
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->businessAddress( $this->name, $this->value, \IPS\Settings::i()->googleplacesautocomplete ? \IPS\Settings::i()->google_maps_api_key : NULL, $this->options['minimize'], $this->options['requireFullAddress'], $this->htmlId, $this->options['vat'] );
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->businessAddress( $this->name, $this->value, Settings::i()->googleplacesautocomplete ? Settings::i()->google_maps_api_key : NULL, $this->options['minimize'], $this->options['requireFullAddress'], $this->htmlId, $this->options['vat'] );
}
/**
@@ -73,7 +88,7 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
*
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
/* Get the normal address stuff */
$value = parent::getValue();
@@ -82,13 +97,13 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
if ( $value )
{
$name = $this->name;
if( \IPS\Request::i()->$name['type'] === 'business' )
if( Request::i()->$name['type'] === 'business' )
{
$value->business = \IPS\Request::i()->$name['business'];
$value->business = Request::i()->$name['business'];
if ( $this->options['vat'] and \in_array( $value->country, array('AT','BE','BG','HR','CY','CZ','DK','EE','FI','FR','DE','GR','HU','IE','IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','ES','SE','GB') ) and \IPS\Request::i()->$name['vat'] )
if ( $this->options['vat'] and in_array( $value->country, array('AT','BE','BG','HR','CY','CZ','DK','EE','FI','FR','DE','GR','HU','IE','IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','ES','SE','GB') ) and Request::i()->$name['vat'] )
{
$value->vat = \IPS\Request::i()->$name['vat'];
$value->vat = Request::i()->$name['vat'];
}
else
{
@@ -109,10 +124,10 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
/**
* Validate
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
* @return TRUE
*/
public function validate()
public function validate(): bool
{
parent::validate();
@@ -120,27 +135,27 @@ class _BusinessAddress extends \IPS\Helpers\Form\Address
{
if ( $this->value->business === '' )
{
throw new \DomainException('cm_business_name_required');
throw new DomainException('cm_business_name_required');
}
if ( $this->value->vat )
{
try
{
$response = \IPS\nexus\Tax::validateVAT( $this->value->vat );
$response = Tax::validateVAT( $this->value->vat );
if ( !$response )
{
throw new \DomainException('cm_checkout_vat_invalid');
throw new DomainException('cm_checkout_vat_invalid');
}
elseif ( $response['countryCode'] !== $this->value->country )
{
throw new \DomainException('cm_checkout_vat_wrong_country');
throw new DomainException('cm_checkout_vat_wrong_country');
}
}
catch ( \IPS\Http\Request\Exception $e )
catch ( Exception $e )
{
\IPS\Log::log( $e, 'vat-validation' );
throw new \DomainException('cm_checkout_vat_error');
Log::log( $e, 'vat-validation' );
throw new DomainException('cm_checkout_vat_error');
}
}
}