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,35 @@
namespace IPS\nexus\Fraud\MaxMind;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\GeoLocation;
use IPS\Http\Request\Exception;
use IPS\Http\Url;
use IPS\IPS;
use IPS\Member;
use IPS\nexus\CreditCard;
use IPS\nexus\Transaction;
use IPS\Request as RequestClass;
use IPS\Settings;
use function defined;
use function function_exists;
use function strpos;
use function strrpos;
use function strtolower;
use function substr;
use const IDNA_NONTRANSITIONAL_TO_ASCII;
use const INTL_IDNA_VARIANT_UTS46;
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;
}
/**
* MaxMind Request
*/
class _Request
class Request
{
/**
* @brief Maxmind User ID
@@ -46,14 +65,14 @@ class _Request
* @param NULL|string $maxmindId MaxMind User ID (NULL to get from settings)
* @return void
*/
public function __construct( $session=TRUE, $maxmindKey=NULL, $maxmindId=NULL )
public function __construct( bool $session=TRUE, ?string $maxmindKey=NULL, ?string $maxmindId=NULL )
{
$this->licenseKey = $maxmindKey ?: \IPS\Settings::i()->maxmind_key;
$this->id = $maxmindId ?: \IPS\Settings::i()->maxmind_id;
$this->licenseKey = $maxmindKey ?: Settings::i()->maxmind_key;
$this->id = $maxmindId ?: Settings::i()->maxmind_id;
if ( $session )
{
$this->setIpAddress( \IPS\Request::i()->ipAddress() );
$this->setIpAddress( RequestClass::i()->ipAddress() );
$this->data['sessionID'] = session_id();
@@ -75,7 +94,7 @@ class _Request
* @param string $ipAddress IP Address
* @return void
*/
public function setIpAddress( $ipAddress )
public function setIpAddress( string $ipAddress ) : void
{
$this->data['device']['ip_address'] = $ipAddress;
}
@@ -83,22 +102,18 @@ class _Request
/**
* Set Transaction
*
* @param \IPS\nexus\Transaction $transaction
* @param Transaction $transaction
* @return void
*/
public function setTransaction( \IPS\nexus\Transaction $transaction )
public function setTransaction( Transaction $transaction ) : void
{
$this->setMember( $transaction->member->member_id ? $transaction->member : $transaction->invoice->member );
if ( $billingAddress = $transaction->invoice->billaddress )
{
$this->setBillingAddress( $transaction->invoice->billaddress );
$this->setBillingAddress( $billingAddress );
}
if ( $shippingAddress = $transaction->invoice->shipaddress )
{
$this->setShippingAddress( $transaction->invoice->shipaddress );
}
$this->data['order']['amount'] = (string) $transaction->amount->amount;
$this->data['order']['currency'] = $transaction->amount->currency;
}
@@ -106,37 +121,23 @@ class _Request
/**
* Set Billing Address
*
* @param \IPS\GeoLocation $billingAddress
* @param GeoLocation $billingAddress
* @return void
*/
public function setBillingAddress( \IPS\GeoLocation $billingAddress )
public function setBillingAddress( GeoLocation $billingAddress ) : void
{
$this->data['billing']['city'] = $billingAddress->city;
$this->data['billing']['postal'] = $billingAddress->postalCode;
$this->data['billing']['country'] = $billingAddress->country;
}
/**
* Set Shipping Address
*
* @param \IPS\GeoLocation $shippingAddress
* @return void
*/
public function setShippingAddress( \IPS\GeoLocation $shippingAddress )
{
$this->data['shipping']['address'] = implode( ', ', $shippingAddress->addressLines );
$this->data['shipping']['city'] = $shippingAddress->city;
$this->data['shipping']['postal'] = $shippingAddress->postalCode;
$this->data['shipping']['country'] = $shippingAddress->country;
}
/**
* Set Member
*
* @param \IPS\Member $member
* @param Member $member
* @return void
*/
public function setMember( \IPS\Member $member )
public function setMember( Member $member ) : void
{
$this->_setEmailProperties( $member->email );
$this->data['account']['username_md5'] = md5( $member->name );
@@ -146,7 +147,7 @@ class _Request
* @brief MaxMind common typo domains list
* @see https://github.com/maxmind/minfraud-api-php/blob/b08158b6c096bde8560b1b7fb8bb548c79f8d57b/src/MinFraud/Util.php#L18
*/
protected static $typoDomains = [
protected static array $typoDomains = [
// gmail.com
'35gmai.com' => 'gmail.com',
'636gmail.com' => 'gmail.com',
@@ -166,23 +167,23 @@ class _Request
* @param string $email The member's email address
* @return void
*/
protected function _setEmailProperties( $email )
protected function _setEmailProperties( string $email ) : void
{
$email = trim( \strtolower( $email ) );
$local = \substr( $email, 0, \strrpos( $email, '@' ) );
$domain = \substr( $email, \strrpos( $email, '@' ) + 1 );
$email = trim( strtolower( $email ) );
$local = substr( $email, 0, strrpos( $email, '@' ) );
$domain = substr( $email, strrpos( $email, '@' ) + 1 );
/* Trim the domain and remove trailing dots */
$domain = rtrim( trim( $domain ), '.' );
/* Convert IDNs to ASCII */
if ( !\function_exists('idn_to_ascii') )
if ( !function_exists('idn_to_ascii') )
{
\IPS\IPS::$PSR0Namespaces['TrueBV'] = \IPS\ROOT_PATH . "/system/3rd_party/php-punycode";
IPS::$PSR0Namespaces['TrueBV'] = \IPS\ROOT_PATH . "/system/3rd_party/php-punycode";
require_once \IPS\ROOT_PATH . "/system/3rd_party/php-punycode/polyfill.php";
}
$asciiDomain = idn_to_ascii( $domain, \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46 );
$asciiDomain = idn_to_ascii( $domain, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46 );
if( $asciiDomain !== FALSE )
{
@@ -190,14 +191,14 @@ class _Request
}
/* Then address common typos */
$domain = isset( static::$typoDomains[ $domain ] ) ? static::$typoDomains[ $domain ] : $domain;
$domain = static::$typoDomains[$domain] ?? $domain;
/* Now remove email aliases from the local part */
$divider = ( $domain === 'yahoo.com' ) ? '-' : '+';
if( $alias = \strpos( $local, $divider ) )
if( $alias = strpos( $local, $divider ) )
{
$local = \substr( $local, 0, $alias );
$local = substr( $local, 0, $alias );
}
$this->data['email']['domain'] = $domain;
@@ -210,7 +211,7 @@ class _Request
* @param string $phoneNumber
* @return void
*/
public function setPhone( $phoneNumber )
public function setPhone( string $phoneNumber ) : void
{
$this->data['billing']['phone_number'] = $phoneNumber;
}
@@ -218,12 +219,12 @@ class _Request
/**
* Set Credit Card
*
* @param \IPS\nexus\CreditCard|string $card The card number
* @param CreditCard|string $card The card number
* @return void
*/
public function setCard( $card )
public function setCard( CreditCard|string $card ) : void
{
$cardNumber = ( $card instanceof \IPS\nexus\CreditCard ) ? $card->number : $card;
$cardNumber = ( $card instanceof CreditCard ) ? $card->number : $card;
$this->data['credit_card']['issuer_id_number'] = mb_substr( $cardNumber, 0, 6 );
$this->data['credit_card']['last_digits'] = mb_substr( $cardNumber, -4 );
}
@@ -234,7 +235,7 @@ class _Request
* @param string $type Transaction Type
* @return void
*/
public function setTransactionType( $type )
public function setTransactionType( string $type ) : void
{
$this->data['event']['txn_type'] = $type;
}
@@ -245,7 +246,7 @@ class _Request
* @param string $code AVS Code
* @return void
*/
public function setAVS( $code )
public function setAVS( string $code ): void
{
$this->data['credit_card']['avs_result'] = $code;
}
@@ -256,7 +257,7 @@ class _Request
* @param bool $result CVV check result (boolean only - do not provide actual code)
* @return void
*/
public function setCVV( $result )
public function setCVV( bool $result ) : void
{
$this->data['credit_card']['cvv_result'] = $result ? 'Y' : 'N';
}
@@ -264,18 +265,18 @@ class _Request
/**
* Make Request
*
* @return \IPS\nexus\Fraud\MaxMind\Response
* @throws \IPS\Http\Request\Exception
* @return Response
* @throws Exception
*/
public function request()
public function request() : Response
{
$response = \IPS\Http\Url::external( 'https://minfraud.maxmind.com/minfraud/v2.0/insights' )->request()->login( $this->id, $this->licenseKey )->post( json_encode( $this->data ) );
$response = Url::external( 'https://minfraud.maxmind.com/minfraud/v2.0/insights' )->request()->login( $this->id, $this->licenseKey )->post( json_encode( $this->data ) );
if ( isset( $response->httpHeaders['Content-Type'] ) and preg_match( '/; charset=(.+?);$/', $response->httpHeaders['Content-Type'], $matches ) )
{
$response = mb_convert_encoding( $response, 'UTF-8', $matches[1] );
}
return new \IPS\nexus\Fraud\MaxMind\Response( (string) $response );
return new Response( (string) $response );
}
}