Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -32,6 +32,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
const STATUS_REFUNDED = 'rfnd'; // Transaction has been refunded in full
const STATUS_PART_REFUNDED = 'prfd'; // Transaction has been partially refunded
const STATUS_GATEWAY_PENDING= 'gwpd'; // The gateway is processing the transaction
const STATUS_DISPUTED = 'dspd'; // The customer disputed the transaction with their bank (filed a chargeback)
/**
* @brief Multiton Store
@@ -89,7 +90,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
* Get transaction table
*
* @param array $where Where clause
* @param string $ref Referer
* @param string $ref Referrer
* @return \IPS\Helpers\Table\Db
*/
public static function table( $where = array(), \IPS\Http\Url $url, $ref = 't' )
@@ -99,6 +100,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
$table->sortBy = $table->sortBy ?: 't_date';
/* Format Columns */
$table->rowClasses = array( 't_invoice' => array( 'ipsTable_wrap' ) );
$table->include = array( 't_status', 't_id', 't_method', 't_member', 't_amount', 't_invoice', 't_date' );
$table->parsers = array(
't_status' => function( $val )
@@ -398,7 +400,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
*/
public function set_partial_refund( \IPS\nexus\Money $amount )
{
$this->_data['partial_refund'] = $amount->amount;
$this->_data['partial_refund'] = (string) $amount->amount;
}
/**
@@ -496,8 +498,8 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
}
}
/* Still here? No fraud rule matches so we can proceed with the transaction */
return static::STATUS_PAID;
/* Check gateway */
return $this->method->fraudCheck( $this );
}
/**
@@ -604,7 +606,10 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
* @return \IPS\Member|NULL If the invoice belonged to a guest, a member will be created by approving and returned here
*/
public function approve( $by = NULL )
{
{
/* Get the amount to pay before storing this as a paid transaction */
$amountToPayOnInvoice = $this->invoice->amountToPay();
/* Set the transaction as paid */
$this->status = static::STATUS_PAID;
$extra = $this->extra;
@@ -620,7 +625,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
$this->save();
/* Mark the invoice paid if necessary */
if ( !$this->invoice->amountToPay()->amount->isGreaterThanZero() )
if ( !$amountToPayOnInvoice->amount->subtract( $this->amount->amount )->isGreaterThanZero() )
{
return $this->invoice->markPaid();
}
@@ -661,10 +666,11 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
*
* @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())
* @return void
* @throws \Exception
*/
public function refund( $refundMethod='gateway', $amount=NULL )
public function refund( $refundMethod='gateway', $amount=NULL, $reason=NULL )
{
/* What's the amount? */
if ( $amount )
@@ -683,7 +689,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
$refundReference = NULL;
if ( $refundMethod === 'gateway' and method_exists( $this->method, 'refund' ) )
{
$refundReference = $this->method->refund( $this, $amount );
$refundReference = $this->method->refund( $this, $amount, $reason );
}
elseif ( $refundMethod === 'credit' )
{
@@ -728,7 +734,8 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
}
else
{
$this->partial_refund->amount = $this->partial_refund->amount->add( $amount );
$this->partial_refund = new \IPS\nexus\Money( $this->partial_refund->amount->add( $amount ), $this->currency );
$extra['history'][] = array( 's' => static::STATUS_PART_REFUNDED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => $refundReference );
if ( $amount >= $this->amount->amount )
{
@@ -830,7 +837,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
{
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', \IPS\Settings::i()->nexus_https );
$this->_url = \IPS\Http\Url::internal( "app=nexus&module=checkout&controller=checkout&do=transaction&id={$this->invoice->id}&t={$this->id}", 'front', 'nexus_checkout' );
}
return $this->_url;
@@ -858,7 +865,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
$return = array();
/* Approve button */
if ( in_array( $this->status, array( static::STATUS_PENDING, static::STATUS_WAITING, static::STATUS_HELD, static::STATUS_REVIEW, static::STATUS_GATEWAY_PENDING ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
if ( in_array( $this->status, array( static::STATUS_WAITING, static::STATUS_HELD, static::STATUS_REVIEW ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
{
$return['approve'] = array(
'title' => $this->auth ? 'transaction_capture' : 'transaction_approve',
@@ -869,7 +876,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
}
/* Review button */
if ( in_array( $this->status, array( static::STATUS_PENDING, 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 \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
{
$return['review'] = array(
'title' => 'transaction_flag_review',
@@ -879,7 +886,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
}
/* Void button */
if ( ( in_array( $this->status, array( static::STATUS_PENDING, static::STATUS_GATEWAY_PENDING ) ) or ( $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 \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
{
$return['void'] = array(
'title' => 'transaction_void',
@@ -889,7 +896,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
);
}
/* Cancal button for manual */
/* Cancel button for manual */
elseif ( $this->status === static::STATUS_WAITING and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_edit' ) )
{
$return['void'] = array(
@@ -957,29 +964,30 @@ 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
* @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
* @apiresponse int invoiceId Invoice ID Number
* @apiresponse \IPS\nexus\Money amount Amount
* @apiresponse \IPS\nexus\Money refundAmount If partially refunded, the amount that has been refunded
* @apiresponse \IPS\nexus\Gateway gateway The gateway
* @apiresponse string gatewayId Any ID number provided by the gateway to identify the transaction on their end
* @apiresponse datetime date Date
* @apiresponse \IPS\nexus\Customer customer Customer
* @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
* @apiresponse int invoiceId Invoice ID Number
* @apiresponse \IPS\nexus\Money amount Amount
* @apiresponse \IPS\nexus\Money refundAmount If partially refunded, the amount that has been refunded
* @apiresponse \IPS\nexus\Gateway gateway The gateway
* @clientapiresponse string gatewayId Any ID number provided by the gateway to identify the transaction on their end
* @apiresponse datetime date Date
* @apiresponse \IPS\nexus\Customer customer Customer
*/
public function apiOutput()
public function apiOutput( \IPS\Member $authorizedMember = NULL )
{
return array(
'id' => $this->id,
'status' => $this->status,
'invoiceId' => $this->invoice->id,
'amount' => $this->amount->apiOutput(),
'refundAmount' => $this->partial_refund ? $this->partial_refund->apiOutput() : null,
'gateway' => $this->method->apiOutput(),
'amount' => $this->amount->apiOutput( $authorizedMember ),
'refundAmount' => $this->partial_refund ? $this->partial_refund->apiOutput( $authorizedMember ) : null,
'gateway' => $this->method ? $this->method->apiOutput( $authorizedMember ) : null,
'gatewayId' => $this->gw_id,
'date' => $this->date->rfc3339(),
'customer' => $this->member->apiOutput()
'customer' => $this->member->apiOutput( $authorizedMember )
);
}