Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,26 +12,33 @@
|
||||
namespace IPS\nexus;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use InvalidArgumentException;
|
||||
use function defined;
|
||||
use function intval;
|
||||
use function strlen;
|
||||
|
||||
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 object
|
||||
*/
|
||||
class _CreditCard
|
||||
class CreditCard
|
||||
{
|
||||
/**
|
||||
* @brief Card Number
|
||||
*/
|
||||
public $number;
|
||||
public ?string $number = NULL;
|
||||
|
||||
/**
|
||||
* @brief Last 4 numbers
|
||||
*/
|
||||
public $lastFour;
|
||||
public mixed $lastFour = NULL;
|
||||
|
||||
/**
|
||||
* @brief Type
|
||||
@@ -44,27 +51,27 @@ class _CreditCard
|
||||
const TYPE_JCB = 'jcb';
|
||||
const TYPE_PAYPAL = 'paypal';
|
||||
const TYPE_VENMO = 'venmo';
|
||||
public $type;
|
||||
public string $type = "";
|
||||
|
||||
/**
|
||||
* @brief Expire Month
|
||||
*/
|
||||
public $expMonth;
|
||||
public mixed $expMonth = NULL;
|
||||
|
||||
/**
|
||||
* @brief Expire Year
|
||||
*/
|
||||
public $expYear;
|
||||
public mixed $expYear = NULL;
|
||||
|
||||
/**
|
||||
* @brief Security Code
|
||||
*/
|
||||
public $ccv;
|
||||
public mixed $ccv = NULL;
|
||||
|
||||
/**
|
||||
* @brief Save
|
||||
*/
|
||||
public $save;
|
||||
public bool $save = FALSE;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -76,16 +83,16 @@ class _CreditCard
|
||||
/**
|
||||
* Create object
|
||||
*
|
||||
* @param string $cardNumber Card Number
|
||||
* @param int|string $expMonth Expire month
|
||||
* @param int|string $expYear Expire year
|
||||
* @param int|string $ccv Security Code
|
||||
* @param string $cardNumber Card Number
|
||||
* @param int|string $expMonth Expire month
|
||||
* @param int|string $expYear Expire year
|
||||
* @param int|string $ccv Security Code
|
||||
* @param bool $save If the card should be saved
|
||||
* @return void
|
||||
* @throws \InvalidArgumentException Card number or expiry date is invalid
|
||||
* @throws \DomainException Expire date is in the past
|
||||
* @return static
|
||||
* @throws InvalidArgumentException Card number or expiry date is invalid
|
||||
* @throws DomainException Expire date is in the past
|
||||
*/
|
||||
public static function build( $cardNumber, $expMonth, $expYear, $ccv, $save=FALSE )
|
||||
public static function build(string $cardNumber, int|string $expMonth, int|string $expYear, int|string $ccv, bool $save=FALSE ) : static
|
||||
{
|
||||
$obj = new static;
|
||||
|
||||
@@ -118,7 +125,7 @@ class _CreditCard
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \InvalidArgumentException('card_number_invalid');
|
||||
throw new InvalidArgumentException('card_number_invalid');
|
||||
}
|
||||
$obj->lastFour = mb_substr( $cardNumber, -4 );
|
||||
|
||||
@@ -129,27 +136,27 @@ class _CreditCard
|
||||
);
|
||||
$sum = 0;
|
||||
$flip = 0;
|
||||
$cardNumberLength = \strlen( $cardNumber );
|
||||
$cardNumberLength = strlen( $cardNumber );
|
||||
for ($i = $cardNumberLength - 1; $i >= 0; $i--)
|
||||
{
|
||||
$sum += $sumTable[ $flip++ & 0x1 ][ $cardNumber[ $i ] ];
|
||||
}
|
||||
if( $sum % 10 !== 0 )
|
||||
{
|
||||
throw new \InvalidArgumentException('card_number_invalid');
|
||||
throw new InvalidArgumentException('card_number_invalid');
|
||||
}
|
||||
|
||||
/* Check the expiry date */
|
||||
$expMonth = \intval( $expMonth );
|
||||
$expMonth = intval( $expMonth );
|
||||
if ( $expMonth < 0 or $expMonth > 12 )
|
||||
{
|
||||
throw new \InvalidArgumentException('card_month_invalid');
|
||||
throw new InvalidArgumentException('card_month_invalid');
|
||||
}
|
||||
$obj->expMonth = str_pad( $expMonth, 2, '0', STR_PAD_LEFT );
|
||||
$obj->expYear = \intval( $expYear );
|
||||
$obj->expYear = intval( $expYear );
|
||||
if ( mktime( 23, 59, 59, $expMonth + 1, 0, $expYear ) < time() )
|
||||
{
|
||||
throw new \DomainException;
|
||||
throw new DomainException;
|
||||
}
|
||||
|
||||
/* Check the security code */
|
||||
@@ -158,12 +165,12 @@ class _CreditCard
|
||||
{
|
||||
if ( mb_strlen( $ccv ) !== 4 )
|
||||
{
|
||||
throw new \InvalidArgumentException('ccv_invalid_4');
|
||||
throw new InvalidArgumentException('ccv_invalid_4');
|
||||
}
|
||||
}
|
||||
elseif ( mb_strlen( $ccv ) !== 3 )
|
||||
{
|
||||
throw new \InvalidArgumentException('ccv_invalid_3');
|
||||
throw new InvalidArgumentException('ccv_invalid_3');
|
||||
}
|
||||
|
||||
/* Should it be saved? */
|
||||
|
||||
Reference in new issue
Block a user