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,16 +12,46 @@
|
||||
namespace IPS\nexus;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\core\AdminNotification;
|
||||
use IPS\DateTime;
|
||||
use IPS\Email;
|
||||
use IPS\Helpers\Table\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Log;
|
||||
use IPS\Math\Number;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer\BillingAgreement;
|
||||
use IPS\nexus\Fraud\MaxMind\Request;
|
||||
use IPS\nexus\Fraud\MaxMind\Response;
|
||||
use IPS\nexus\Fraud\Rule;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use ReflectionClass;
|
||||
use RuntimeException;
|
||||
use function defined;
|
||||
use function get_called_class;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction Model
|
||||
*
|
||||
* @property Customer $member
|
||||
* @property Invoice $invoice
|
||||
* @property Gateway $method
|
||||
*/
|
||||
class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
class Transaction extends ActiveRecord
|
||||
{
|
||||
const STATUS_PAID = 'okay'; // Transaction has been paid successfully
|
||||
const STATUS_PENDING = 'pend'; // Payment not yet submitted (for example, has been redirected to external site)
|
||||
@@ -37,31 +67,32 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_transactions';
|
||||
public static ?string $databaseTable = 'nexus_transactions';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 't_';
|
||||
public static string $databasePrefix = 't_';
|
||||
|
||||
/**
|
||||
* Load and check permissions
|
||||
*
|
||||
* @return \IPS\Content\Item
|
||||
* @throws \OutOfRangeException
|
||||
* @param int $id
|
||||
* @return static
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public static function loadAndCheckPerms( $id )
|
||||
public static function loadAndCheckPerms( int $id ) : static
|
||||
{
|
||||
$obj = static::load( $id );
|
||||
|
||||
if ( $obj->member->member_id !== \IPS\Member::loggedIn()->member_id )
|
||||
if ( $obj->member->member_id !== Member::loggedIn()->member_id )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
@@ -72,10 +103,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function statuses()
|
||||
public static function statuses(): array
|
||||
{
|
||||
$options = array();
|
||||
$reflection = new \ReflectionClass( \get_called_class() );
|
||||
$reflection = new ReflectionClass( get_called_class() );
|
||||
foreach ( $reflection->getConstants() as $k => $v )
|
||||
{
|
||||
if ( mb_substr( $k, 0, 7 ) === 'STATUS_' )
|
||||
@@ -90,13 +121,14 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* Get transaction table
|
||||
*
|
||||
* @param array $where Where clause
|
||||
* @param Url $url
|
||||
* @param string $ref Referrer
|
||||
* @return \IPS\Helpers\Table\Db
|
||||
* @return Db
|
||||
*/
|
||||
public static function table( $where, \IPS\Http\Url $url, $ref = 't' )
|
||||
public static function table( array $where, Url $url, string $ref = 't' ) : Db
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_transactions', $url, $where );
|
||||
$table = new Db( 'nexus_transactions', $url, $where );
|
||||
$table->sortBy = $table->sortBy ?: 't_date';
|
||||
|
||||
/* Format Columns */
|
||||
@@ -105,7 +137,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
$table->parsers = array(
|
||||
't_status' => function( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('transactions', 'nexus')->status( $val );
|
||||
return Theme::i()->getTemplate('transactions', 'nexus')->status( $val );
|
||||
},
|
||||
't_method' => function( $val )
|
||||
{
|
||||
@@ -113,40 +145,40 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Gateway::load( $val )->_title;
|
||||
return Gateway::load( $val )->_title;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('gateway_deleted');
|
||||
return Member::loggedIn()->language()->addToStack('gateway_deleted');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack('account_credit');
|
||||
return Member::loggedIn()->language()->addToStack('account_credit');
|
||||
}
|
||||
},
|
||||
't_member' => function ( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\Member::load( $val ) );
|
||||
return Theme::i()->getTemplate('global', 'nexus')->userLink( Member::load( $val ) );
|
||||
},
|
||||
't_amount' => function( $val, $row )
|
||||
{
|
||||
return (string) new \IPS\nexus\Money( $val, $row['t_currency'] );
|
||||
return (string) new Money( $val, $row['t_currency'] );
|
||||
},
|
||||
't_invoice' => function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val ) );
|
||||
return Theme::i()->getTemplate('invoices', 'nexus')->link( Invoice::load( $val ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
't_date' => function( $val )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val );
|
||||
return DateTime::ts( $val );
|
||||
}
|
||||
);
|
||||
|
||||
@@ -157,9 +189,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
'view' => array(
|
||||
'icon' => 'search',
|
||||
'title' => 'transaction_view',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=transactions&do=view&id={$row['t_id']}" )->getSafeUrlFromFilters()
|
||||
'link' => Url::internal( "app=nexus&module=payments&controller=transactions&do=view&id={$row['t_id']}" )->getSafeUrlFromFilters()
|
||||
),
|
||||
), \IPS\nexus\Transaction::constructFromData( $row )->buttons( $ref ) );
|
||||
), Transaction::constructFromData( $row )->buttons( $ref ) );
|
||||
};
|
||||
|
||||
return $table;
|
||||
@@ -170,10 +202,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
public function setDefaultValues() : void
|
||||
{
|
||||
$this->status = static::STATUS_PENDING;
|
||||
$this->date = new \IPS\DateTime;
|
||||
$this->date = new DateTime;
|
||||
$this->fraud_blocked = NULL;
|
||||
$this->extra = array();
|
||||
}
|
||||
@@ -181,15 +213,15 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get member
|
||||
*
|
||||
* @return \IPS\Member
|
||||
* @return Customer|null
|
||||
*/
|
||||
public function get_member()
|
||||
public function get_member() : Customer|null
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Customer::load( $this->_data['member'] );
|
||||
return Customer::load( $this->_data['member'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -198,10 +230,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set member
|
||||
*
|
||||
* @param \IPS\Member
|
||||
* @param Member $member
|
||||
* @return void
|
||||
*/
|
||||
public function set_member( \IPS\Member $member )
|
||||
public function set_member( Member $member ) : void
|
||||
{
|
||||
$this->_data['member'] = (int) $member->member_id;
|
||||
|
||||
@@ -216,16 +248,16 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get invoice
|
||||
*
|
||||
* @return \IPS\nexus\Invoice|NULL
|
||||
* @return Invoice|NULL
|
||||
*/
|
||||
public function get_invoice()
|
||||
public function get_invoice() : Invoice|null
|
||||
{
|
||||
/* If an invoice is deleted, then the transaction will remain present, which then can result in uncaught exception errors. */
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Invoice::load( $this->_data['invoice'] );
|
||||
return Invoice::load( $this->_data['invoice'] );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -234,10 +266,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set invoice
|
||||
*
|
||||
* @param \IPS\nexus\Invoice
|
||||
* @param Invoice $invoice
|
||||
* @return void
|
||||
*/
|
||||
public function set_invoice( \IPS\nexus\Invoice $invoice )
|
||||
public function set_invoice(Invoice $invoice ) : void
|
||||
{
|
||||
$this->_data['invoice'] = $invoice->id;
|
||||
}
|
||||
@@ -245,9 +277,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get payment gateway
|
||||
*
|
||||
* @return \IPS\nexus\Gateway
|
||||
* @return Gateway|int|null
|
||||
*/
|
||||
public function get_method()
|
||||
public function get_method() : Gateway|int|null
|
||||
{
|
||||
if ( !isset( $this->_data['method'] ) or $this->_data['method'] === 0 )
|
||||
{
|
||||
@@ -256,9 +288,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Gateway::load( $this->_data['method'] );
|
||||
return Gateway::load( $this->_data['method'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -267,10 +299,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set payment gateway
|
||||
*
|
||||
* @param \IPS\nexus\Gateway
|
||||
* @param Gateway $gateway
|
||||
* @return void
|
||||
*/
|
||||
public function set_method( \IPS\nexus\Gateway $gateway )
|
||||
public function set_method( Gateway $gateway ) : void
|
||||
{
|
||||
$this->_data['method'] = $gateway->id;
|
||||
}
|
||||
@@ -278,21 +310,20 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get amount
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
* @return Money
|
||||
*/
|
||||
public function get_amount()
|
||||
public function get_amount() : Money
|
||||
{
|
||||
$amount = new \IPS\nexus\Money( $this->_data['amount'], $this->_data['currency'] );
|
||||
return $amount;
|
||||
return new Money( $this->_data['amount'], $this->_data['currency'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set total
|
||||
*
|
||||
* @param \IPS\nexus\Money $amount The total
|
||||
* @param Money $amount The total
|
||||
* @return void
|
||||
*/
|
||||
public function set_amount( \IPS\nexus\Money $amount )
|
||||
public function set_amount( Money $amount ) : void
|
||||
{
|
||||
$this->_data['amount'] = $amount->amount;
|
||||
$this->_data['currency'] = $amount->currency;
|
||||
@@ -301,20 +332,20 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get date
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_date()
|
||||
public function get_date() : DateTime
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['date'] );
|
||||
return DateTime::ts( $this->_data['date'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date
|
||||
*
|
||||
* @param \IPS\DateTime $date The invoice date
|
||||
* @param DateTime $date The invoice date
|
||||
* @return void
|
||||
*/
|
||||
public function set_date( \IPS\DateTime $date )
|
||||
public function set_date( DateTime $date ) : void
|
||||
{
|
||||
$this->_data['date'] = $date->getTimestamp();
|
||||
}
|
||||
@@ -324,18 +355,18 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_extra()
|
||||
public function get_extra() : array
|
||||
{
|
||||
return json_decode( $this->_data['extra'], TRUE );
|
||||
return json_decode( $this->_data['extra'], TRUE ) ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extra information
|
||||
*
|
||||
* @param mixed $extra The data
|
||||
* @param array $extra The data
|
||||
* @return void
|
||||
*/
|
||||
public function set_extra( $extra )
|
||||
public function set_extra( array $extra ) : void
|
||||
{
|
||||
$this->_data['extra'] = json_encode( $extra );
|
||||
}
|
||||
@@ -343,20 +374,20 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get MaxMind data
|
||||
*
|
||||
* @return \IPS\nexus\Fraud\MaxMind\Response
|
||||
* @return Response|null
|
||||
*/
|
||||
public function get_fraud()
|
||||
public function get_fraud() : Response|null
|
||||
{
|
||||
return ( isset( $this->_data['fraud'] ) and $this->_data['fraud'] ) ? \IPS\nexus\Fraud\MaxMind\Response::buildFromJson( $this->_data['fraud'] ) : NULL;
|
||||
return ( isset( $this->_data['fraud'] ) and $this->_data['fraud'] ) ? Response::buildFromJson( $this->_data['fraud'] ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set MaxMind data
|
||||
*
|
||||
* @param \IPS\nexus\Fraud\MaxMind\Response $maxMind The data
|
||||
* @param Response $maxMind The data
|
||||
* @return void
|
||||
*/
|
||||
public function set_fraud( \IPS\nexus\Fraud\MaxMind\Response $maxMind )
|
||||
public function set_fraud( Response $maxMind ) : void
|
||||
{
|
||||
$this->_data['fraud'] = (string) $maxMind;
|
||||
}
|
||||
@@ -364,15 +395,15 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get triggered fraud rule
|
||||
*
|
||||
* @return \IPS\nexus\Fraud\Rule|NULL
|
||||
* @return Rule|NULL
|
||||
*/
|
||||
public function get_fraud_blocked()
|
||||
public function get_fraud_blocked() : Rule|null
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_data['fraud_blocked'] ? \IPS\nexus\Fraud\Rule::load( $this->_data['fraud_blocked'] ) : NULL;
|
||||
return $this->_data['fraud_blocked'] ? Rule::load( $this->_data['fraud_blocked'] ) : NULL;
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -381,10 +412,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set triggered fraud rule
|
||||
*
|
||||
* @param \IPS\nexus\Fraud\Rule $rule The rule
|
||||
* @param Rule|null $rule The rule
|
||||
* @return void
|
||||
*/
|
||||
public function set_fraud_blocked( \IPS\nexus\Fraud\Rule $rule = NULL )
|
||||
public function set_fraud_blocked( Rule $rule = NULL ) : void
|
||||
{
|
||||
$this->_data['fraud_blocked'] = $rule ? $rule->id : 0;
|
||||
}
|
||||
@@ -392,20 +423,20 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get partial refund amount
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
* @return Money
|
||||
*/
|
||||
public function get_partial_refund()
|
||||
public function get_partial_refund() : Money
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->_data['partial_refund'], $this->_data['currency'] );
|
||||
return new Money( $this->_data['partial_refund'], $this->_data['currency'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set partial refund amount
|
||||
*
|
||||
* @param \IPS\nexus\Money $amount The total
|
||||
* @param Money $amount The total
|
||||
* @return void
|
||||
*/
|
||||
public function set_partial_refund( \IPS\nexus\Money $amount )
|
||||
public function set_partial_refund(Money $amount ) : void
|
||||
{
|
||||
$this->_data['partial_refund'] = (string) $amount->amount;
|
||||
}
|
||||
@@ -413,20 +444,20 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get credit amount
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
* @return Money
|
||||
*/
|
||||
public function get_credit()
|
||||
public function get_credit() : Money
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->_data['credit'], $this->_data['currency'] );
|
||||
return new Money( $this->_data['credit'], $this->_data['currency'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set credit amount
|
||||
*
|
||||
* @param \IPS\nexus\Money $amount The total
|
||||
* @param Money $amount The total
|
||||
* @return void
|
||||
*/
|
||||
public function set_credit( \IPS\nexus\Money $amount )
|
||||
public function set_credit(Money $amount ) : void
|
||||
{
|
||||
$this->_data['credit'] = (string) $amount->amount;
|
||||
}
|
||||
@@ -434,59 +465,59 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get date transaction must be captured by (is set after authorisation. once captured, should be NULL)
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime|null
|
||||
*/
|
||||
public function get_auth()
|
||||
public function get_auth() : DateTime|null
|
||||
{
|
||||
return $this->_data['auth'] ? \IPS\DateTime::ts( $this->_data['auth'] ) : NULL;
|
||||
return $this->_data['auth'] ? DateTime::ts( $this->_data['auth'] ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date transaction must be captured by (is set after authorisation. once captured, should be NULL)
|
||||
*
|
||||
* @param \IPS\DateTime $date The invoice date
|
||||
* @param DateTime|null $date The invoice date
|
||||
* @return void
|
||||
*/
|
||||
public function set_auth( \IPS\DateTime $date = NULL )
|
||||
public function set_auth( ?DateTime $date = NULL ) : void
|
||||
{
|
||||
$this->_data['auth'] = $date === NULL ? NULL : $date->getTimestamp();
|
||||
$this->_data['auth'] = $date?->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get billing agreement
|
||||
*
|
||||
* @return \IPS\nexus\Customer\BillingAgreement|NULL
|
||||
* @return BillingAgreement|NULL
|
||||
*/
|
||||
public function get_billing_agreement()
|
||||
public function get_billing_agreement() : BillingAgreement|null
|
||||
{
|
||||
return ( isset( $this->_data['billing_agreement'] ) AND $this->_data['billing_agreement'] ) ? \IPS\nexus\Customer\BillingAgreement::load( $this->_data['billing_agreement'] ) : NULL;
|
||||
return ( isset( $this->_data['billing_agreement'] ) AND $this->_data['billing_agreement'] ) ? BillingAgreement::load( $this->_data['billing_agreement'] ) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set billing agreement
|
||||
*
|
||||
* @param \IPS\nexus\Customer\BillingAgreement|NULL $billingAgreement The billing agreement
|
||||
* @param BillingAgreement|NULL $billingAgreement The billing agreement
|
||||
* @return void
|
||||
*/
|
||||
public function set_billing_agreement( \IPS\nexus\Customer\BillingAgreement $billingAgreement = NULL )
|
||||
public function set_billing_agreement( ?BillingAgreement $billingAgreement = NULL ) : void
|
||||
{
|
||||
$this->_data['billing_agreement'] = $billingAgreement === NULL ? NULL : $billingAgreement->id;
|
||||
$this->_data['billing_agreement'] = $billingAgreement?->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run Anti-Fraud Checks and return status for transaction
|
||||
*
|
||||
* @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 Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
|
||||
* @return string
|
||||
*/
|
||||
public function runFraudCheck( $maxMind=NULL )
|
||||
public function runFraudCheck( ?Request $maxMind=NULL ) : string
|
||||
{
|
||||
/* Run MaxMind */
|
||||
if ( \IPS\Settings::i()->maxmind_key and ( !\IPS\Settings::i()->maxmind_gateways or \IPS\Settings::i()->maxmind_gateways == '*' or \in_array( $this->method->id, explode( ',', \IPS\Settings::i()->maxmind_gateways ) ) ) )
|
||||
if ( Settings::i()->maxmind_key and ( !Settings::i()->maxmind_gateways or Settings::i()->maxmind_gateways == '*' or in_array( $this->method->id, explode( ',', Settings::i()->maxmind_gateways ) ) ) )
|
||||
{
|
||||
if ( $maxMind === NULL )
|
||||
{
|
||||
$maxMind = new \IPS\nexus\Fraud\MaxMind\Request;
|
||||
$maxMind = new Request;
|
||||
$maxMind->setTransaction( $this );
|
||||
}
|
||||
|
||||
@@ -498,16 +529,16 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
$this->save();
|
||||
|
||||
/* If MaxMind fails, stop here */
|
||||
if ( $this->fraud->error() and \IPS\Settings::i()->maxmind_error == 'hold' )
|
||||
if ( $this->fraud->error() and Settings::i()->maxmind_error == 'hold' )
|
||||
{
|
||||
return static::STATUS_HELD;
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'maxmind_error' );
|
||||
Log::log( $e, 'maxmind_error' );
|
||||
|
||||
if ( \IPS\Settings::i()->maxmind_error == 'hold' )
|
||||
if ( Settings::i()->maxmind_error == 'hold' )
|
||||
{
|
||||
return static::STATUS_HELD;
|
||||
}
|
||||
@@ -515,7 +546,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Check Fraud Rules */
|
||||
foreach ( \IPS\nexus\Fraud\Rule::roots() as $rule )
|
||||
foreach ( Rule::roots() as $rule )
|
||||
{
|
||||
if ( $rule->matches( $this ) )
|
||||
{
|
||||
@@ -533,17 +564,17 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Check fraud rules and capture
|
||||
*
|
||||
* @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
|
||||
* @return \IPS\Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
|
||||
* @throws \LogicException
|
||||
* @param Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
|
||||
* @return Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function checkFraudRulesAndCapture( $maxMind=NULL )
|
||||
public function checkFraudRulesAndCapture( ?Request $maxMind=NULL ) : Member|null
|
||||
{
|
||||
/* Check fraud rules */
|
||||
$fraudResult = $this->runFraudCheck( $maxMind );
|
||||
if ( $fraudResult )
|
||||
{
|
||||
$this->executeFraudAction( $fraudResult, TRUE );
|
||||
$this->executeFraudAction( $fraudResult );
|
||||
}
|
||||
|
||||
/* If we're not being fraud blocked, we can capture and approve */
|
||||
@@ -560,9 +591,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* @param string $fraudResult Status as returned by runFraudCheck()
|
||||
* @param bool $isApproved Has the payment already been approved? If so and the fraus rule wants to refuse, we will void
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function executeFraudAction( $fraudResult, $isApproved=TRUE )
|
||||
public function executeFraudAction( string $fraudResult, bool $isApproved=TRUE ) : void
|
||||
{
|
||||
/* If the fraud rule wants to hold or refuse... */
|
||||
if ( $fraudResult !== static::STATUS_PAID )
|
||||
@@ -589,9 +620,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
) );
|
||||
|
||||
/* Notification */
|
||||
if ( \in_array( $fraudResult, array( static::STATUS_HELD, static::STATUS_REVIEW, static::STATUS_DISPUTED ) ) )
|
||||
if ( in_array( $fraudResult, array( static::STATUS_HELD, static::STATUS_REVIEW, static::STATUS_DISPUTED ) ) )
|
||||
{
|
||||
\IPS\core\AdminNotification::send( 'nexus', 'Transaction', $fraudResult, TRUE, $this );
|
||||
AdminNotification::send( 'nexus', 'Transaction', $fraudResult, TRUE, $this );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,10 +633,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Capture and approve
|
||||
*
|
||||
* @return \IPS\Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
|
||||
* @throws \LogicException
|
||||
* @return Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function captureAndApprove()
|
||||
public function captureAndApprove() : Member|null
|
||||
{
|
||||
$this->capture();
|
||||
|
||||
@@ -624,9 +655,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* Capture
|
||||
*
|
||||
* @return void
|
||||
* @throws \LogicException
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function capture()
|
||||
public function capture() : void
|
||||
{
|
||||
$this->method->capture( $this );
|
||||
$this->auth = NULL;
|
||||
@@ -636,10 +667,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Approve
|
||||
*
|
||||
* @param \IPS\Member|NULL $by The staff member approving, or NULL if it's automatic
|
||||
* @return \IPS\Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
|
||||
* @param Member|NULL $by The staff member approving, or NULL if it's automatic
|
||||
* @return Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
|
||||
*/
|
||||
public function approve( $by = NULL )
|
||||
public function approve( ?Member $by = NULL ) : Member|null
|
||||
{
|
||||
/* Get the amount to pay before storing this as a paid transaction */
|
||||
$amountToPayOnInvoice = $this->invoice->amountToPay();
|
||||
@@ -676,27 +707,27 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* Void
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function void()
|
||||
public function void() : void
|
||||
{
|
||||
/* Void it */
|
||||
$this->method->void( $this );
|
||||
|
||||
/* Update transaction */
|
||||
$extra = $this->extra;
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
|
||||
$extra['history'][] = array( 's' => Transaction::STATUS_REFUSED, 'on' => time(), 'by' => Member::loggedIn()->member_id );
|
||||
$this->extra = $extra;
|
||||
$this->status = \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
$this->status = Transaction::STATUS_REFUSED;
|
||||
$this->auth = NULL;
|
||||
$this->save();
|
||||
|
||||
/* Log it */
|
||||
if ( $this->member )
|
||||
if ( $this->member->member_id )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_REFUSED,
|
||||
'status' => Transaction::STATUS_REFUSED,
|
||||
'id' => $this->id
|
||||
) );
|
||||
}
|
||||
@@ -706,21 +737,21 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* Refund
|
||||
*
|
||||
* @param string $refundMethod "gateway", "credit", or "none"
|
||||
* @param float|NULL $amount Amount (NULL for full amount)
|
||||
* @param string $reason Reason for refund, if applicable (provided by gateway's refundReasons())
|
||||
* @param mixed $amount Amount (NULL for full amount)
|
||||
* @param string|null $reason Reason for refund, if applicable (provided by gateway's refundReasons())
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function refund( $refundMethod='gateway', $amount=NULL, $reason=NULL )
|
||||
public function refund( string $refundMethod='gateway', mixed $amount=NULL, ?string $reason=NULL ) : void
|
||||
{
|
||||
$extra = $this->extra;
|
||||
|
||||
/* What's the amount? */
|
||||
if ( $amount )
|
||||
{
|
||||
if ( !( $amount instanceof \IPS\Math\Number ) )
|
||||
if ( !( $amount instanceof Number ) )
|
||||
{
|
||||
$amount = new \IPS\Math\Number( number_format( $amount, \IPS\nexus\Money::numberOfDecimalsForCurrency( $this->amount->currency ), '.', '' ) );
|
||||
$amount = new Number( number_format( $amount, Money::numberOfDecimalsForCurrency( $this->amount->currency ), '.', '' ) );
|
||||
}
|
||||
}
|
||||
if ( !$amount or $this->amount->amount->compare( $amount ) === 0 )
|
||||
@@ -739,7 +770,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$this->status = static::STATUS_REFUNDED;
|
||||
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUNDED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'ref' => $refundReference );
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUNDED, 'by' => Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'ref' => $refundReference );
|
||||
|
||||
if ( $this->member )
|
||||
{
|
||||
@@ -756,7 +787,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->partial_refund = new \IPS\nexus\Money( $this->partial_refund->amount->add( $amount ), $this->currency );
|
||||
$this->partial_refund = new Money( $this->partial_refund->amount->add( $amount ), $this->currency );
|
||||
|
||||
if ( $amount >= $this->amount->amount )
|
||||
{
|
||||
@@ -766,7 +797,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$this->status = static::STATUS_PART_REFUNDED;
|
||||
}
|
||||
$extra['history'][] = array( 's' => $this->status, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => $refundReference );
|
||||
$extra['history'][] = array( 's' => $this->status, 'by' => Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => $refundReference );
|
||||
|
||||
if ( $this->member )
|
||||
{
|
||||
@@ -797,10 +828,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
/* Update transaction */
|
||||
$this->status = static::STATUS_PART_REFUNDED;
|
||||
$this->credit = new \IPS\nexus\Money( $this->credit->amount->add( $amount ), $this->currency );
|
||||
$this->credit = new Money( $this->credit->amount->add( $amount ), $this->currency );
|
||||
|
||||
/* Log */
|
||||
$extra['history'][] = array( 's' => static::STATUS_PART_REFUNDED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => NULL );
|
||||
$extra['history'][] = array( 's' => static::STATUS_PART_REFUNDED, 'by' => Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => NULL );
|
||||
if ( $this->member )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
@@ -818,7 +849,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/* Update transaction */
|
||||
$this->status = static::STATUS_REFUSED;
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUSED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time() );
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUSED, 'by' => Member::loggedIn()->member_id, 'on' => time() );
|
||||
|
||||
/* Log */
|
||||
if ( $this->member )
|
||||
@@ -841,9 +872,9 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* Reverse previously given credit (will log, but does not change status - status must be set separately)
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function reverseCredit()
|
||||
public function reverseCredit() : void
|
||||
{
|
||||
$credits = $this->member->cm_credits;
|
||||
$credits[ $this->amount->currency ]->amount = $credits[ $this->amount->currency ]->amount->subtract( $this->credit->amount );
|
||||
@@ -851,7 +882,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
$this->member->save();
|
||||
|
||||
$extra = $this->extra;
|
||||
$extra['history'][] = array( 's' => 'undo_credit', 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'amount' => $this->credit->amount );
|
||||
$extra['history'][] = array( 's' => 'undo_credit', 'by' => Member::loggedIn()->member_id, 'on' => time(), 'amount' => $this->credit->amount );
|
||||
if ( $this->member )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
@@ -863,7 +894,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
$this->extra = $extra;
|
||||
|
||||
$this->credit = new \IPS\nexus\Money( 0, $this->currency );
|
||||
$this->credit = new Money( 0, $this->currency );
|
||||
|
||||
$this->save();
|
||||
}
|
||||
@@ -873,7 +904,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendNotification()
|
||||
public function sendNotification() : void
|
||||
{
|
||||
switch ( $this->status )
|
||||
{
|
||||
@@ -909,11 +940,11 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \RuntimeException;
|
||||
throw new RuntimeException;
|
||||
break;
|
||||
}
|
||||
|
||||
\IPS\Email::buildFromTemplate( 'nexus', $key, array( $this, $this->invoice, $this->invoice->summary( $this->invoice->member->language() ) ), \IPS\Email::TYPE_TRANSACTIONAL )
|
||||
Email::buildFromTemplate( 'nexus', $key, array( $this, $this->invoice, $this->invoice->summary() ), Email::TYPE_TRANSACTIONAL )
|
||||
->send(
|
||||
$this->invoice->member,
|
||||
array_map(
|
||||
@@ -923,25 +954,25 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
},
|
||||
iterator_to_array( $this->invoice->member->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( \in_array( $emailKey, explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
( ( in_array( $emailKey, explode( ',', Settings::i()->nexus_notify_copy_types ) ) AND Settings::i()->nexus_notify_copy_email ) ? explode( ',', Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached URL
|
||||
*/
|
||||
protected $_url = NULL;
|
||||
protected mixed $_url = NULL;
|
||||
|
||||
/**
|
||||
* Get URL
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url|string|null
|
||||
*/
|
||||
public function url()
|
||||
function url(): Url|string|null
|
||||
{
|
||||
if( $this->_url === NULL )
|
||||
{
|
||||
$this->_url = \IPS\Http\Url::internal( "app=nexus&module=checkout&controller=checkout&do=transaction&id={$this->invoice->id}&t={$this->id}", 'front', 'nexus_checkout' );
|
||||
$this->_url = Url::internal( "app=nexus&module=checkout&controller=checkout&do=transaction&id={$this->invoice->id}&t={$this->id}", 'front', 'nexus_checkout' );
|
||||
}
|
||||
|
||||
return $this->_url;
|
||||
@@ -950,11 +981,11 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* ACP URL
|
||||
*
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
public function acpUrl()
|
||||
public function acpUrl() : Url
|
||||
{
|
||||
return \IPS\Http\Url::internal( "app=nexus&module=payments&controller=transactions&do=view&id={$this->id}", 'admin' );
|
||||
return Url::internal( "app=nexus&module=payments&controller=transactions&do=view&id={$this->id}", 'admin' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -963,13 +994,13 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* @param string $ref Referer
|
||||
* @return array
|
||||
*/
|
||||
public function buttons( $ref='v' )
|
||||
public function buttons( string $ref='v' ) : array
|
||||
{
|
||||
$url = $this->acpUrl()->setQueryString( 'r', $ref );
|
||||
$return = array();
|
||||
|
||||
/* Approve button */
|
||||
if ( $this->method and \in_array( $this->status, array( static::STATUS_WAITING, static::STATUS_HELD, static::STATUS_REVIEW ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
if ( $this->method and in_array( $this->status, array( static::STATUS_WAITING, static::STATUS_HELD, static::STATUS_REVIEW ) ) and Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
{
|
||||
$return['approve'] = array(
|
||||
'title' => $this->auth ? 'transaction_capture' : 'transaction_approve',
|
||||
@@ -980,7 +1011,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Review button */
|
||||
if ( \in_array( $this->status, array( static::STATUS_WAITING, static::STATUS_HELD ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
if ( in_array( $this->status, array( static::STATUS_WAITING, static::STATUS_HELD ) ) and Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
{
|
||||
$return['review'] = array(
|
||||
'title' => 'transaction_flag_review',
|
||||
@@ -990,7 +1021,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Void button */
|
||||
if ( $this->auth and \in_array( $this->status, array( static::STATUS_HELD, static::STATUS_REVIEW ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
if ( $this->auth and in_array( $this->status, array( static::STATUS_HELD, static::STATUS_REVIEW ) ) and Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
{
|
||||
$return['void'] = array(
|
||||
'title' => 'transaction_void',
|
||||
@@ -1001,7 +1032,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Cancel button for manual */
|
||||
elseif ( $this->status === static::STATUS_WAITING and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
elseif ( $this->status === static::STATUS_WAITING and Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
|
||||
{
|
||||
$return['void'] = array(
|
||||
'title' => 'cancel',
|
||||
@@ -1012,24 +1043,24 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
/* Refund button */
|
||||
elseif ( \in_array( $this->status, array( static::STATUS_PAID, static::STATUS_HELD, static::STATUS_REVIEW, static::STATUS_PART_REFUNDED ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_refund' ) )
|
||||
elseif ( in_array( $this->status, array( static::STATUS_PAID, static::STATUS_HELD, static::STATUS_REVIEW, static::STATUS_PART_REFUNDED ) ) and Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_refund' ) )
|
||||
{
|
||||
$return['refund'] = array(
|
||||
'title' => 'transaction_refund_credit',
|
||||
'icon' => 'reply',
|
||||
'link' => $url->setQueryString( array( 'do' => 'refund' ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'transaction_refund_credit_title', FALSE, array( 'sprintf' => array( $this->amount ) ) ) )
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack( 'transaction_refund_credit_title', FALSE, array( 'sprintf' => array( $this->amount ) ) ) )
|
||||
);
|
||||
}
|
||||
|
||||
/* Delete button */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_delete' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_delete' ) )
|
||||
{
|
||||
$return['delete'] = array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => $url->setQueryString( 'do', 'delete' )->csrf()->getSafeUrlFromFilters(),
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('trans_delete_warning') )
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => Member::loggedIn()->language()->addToStack('trans_delete_warning') )
|
||||
);
|
||||
}
|
||||
return $return;
|
||||
@@ -1040,7 +1071,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function history()
|
||||
public function history() : array
|
||||
{
|
||||
$return = array();
|
||||
$extra = $this->extra;
|
||||
@@ -1051,12 +1082,12 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !\in_array( $this->status, array( static::STATUS_PENDING, static::STATUS_WAITING, static::STATUS_GATEWAY_PENDING ) ) )
|
||||
if ( !in_array( $this->status, array( static::STATUS_PENDING, static::STATUS_WAITING, static::STATUS_GATEWAY_PENDING ) ) )
|
||||
{
|
||||
$return[] = array(
|
||||
's' => $this->status,
|
||||
'by' => isset( $extra['status_by'] ) ? $extra['status_by'] : NULL,
|
||||
'on' => isset( $extra['status_on'] ) ? $extra['status_on'] : NULL,
|
||||
'by' => $extra['status_by'] ?? NULL,
|
||||
'on' => $extra['status_on'] ?? NULL,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1067,7 +1098,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string status Status: 'okay' = Paid; 'pend' = Pending, waiting for gateway; 'wait' = Pending, manual approval required; 'hold' = Held for manual approval; 'revw' = Flagged for review; 'fail' = Failed; 'rfnd' = Refunded; 'prfd' = Partially refunded
|
||||
@@ -1080,15 +1111,15 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* @apiresponse datetime date Date
|
||||
* @apiresponse \IPS\nexus\Customer customer Customer
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
public function apiOutput( ?Member $authorizedMember = NULL ): array
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
'invoiceId' => $this->invoice->id,
|
||||
'amount' => $this->amount->apiOutput( $authorizedMember ),
|
||||
'refundAmount' => $this->partial_refund ? $this->partial_refund->apiOutput( $authorizedMember ) : null,
|
||||
'creditAmount' => $this->credit ? $this->credit->apiOutput( $authorizedMember ) : null,
|
||||
'refundAmount' => $this->partial_refund?->apiOutput($authorizedMember),
|
||||
'creditAmount' => $this->credit?->apiOutput($authorizedMember),
|
||||
'gateway' => $this->method ? $this->method->apiOutput( $authorizedMember ) : null,
|
||||
'gatewayId' => $this->gw_id,
|
||||
'date' => $this->date->rfc3339(),
|
||||
|
||||
Reference in new issue
Block a user