Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,9 @@
/**
* @brief Customer Address Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Alternative Contact Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 09 May 2014
* @version SVN_VERSION_NUMBER
@@ -0,0 +1,263 @@
<?php
/**
* @brief Billing Agreement Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 16 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\Customer;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Billing Agreement Model
*/
class _BillingAgreement extends \IPS\Patterns\ActiveRecord
{
const STATUS_ACTIVE = 'active'; // Billing Agreement is active and will charge automatically
const STATUS_SUSPENDED = 'suspended'; // Billing Agreement has been suspended but can be reactivated
const STATUS_CANCELED = 'canceled'; // Billing Agreement has been canceled
/**
* @brief Multiton Store
*/
protected static $multitons;
/**
* @brief Database Table
*/
public static $databaseTable = 'nexus_billing_agreements';
/**
* @brief Database Prefix
*/
public static $databasePrefix = 'ba_';
/**
* Construct ActiveRecord from database row
*
* @param array $data Row from database table
* @param bool $updateMultitonStoreIfExists Replace current object in multiton store if it already exists there?
* @return static
*/
public static function constructFromData( $data, $updateMultitonStoreIfExists = TRUE )
{
$gateway = \IPS\nexus\Gateway::load( $data['ba_method'] );
$classname = 'IPS\nexus\Gateway\\' . $gateway->gateway . '\\BillingAgreement';
/* Initiate an object */
$obj = new $classname;
$obj->_new = FALSE;
/* Import data */
foreach ( $data as $k => $v )
{
if( static::$databasePrefix AND mb_strpos( $k, static::$databasePrefix ) === 0 )
{
$k = \substr( $k, \strlen( static::$databasePrefix ) );
}
$obj->_data[ $k ] = $v;
}
$obj->changed = array();
/* Init */
if ( method_exists( $obj, 'init' ) )
{
$obj->init();
}
/* Return */
return $obj;
}
/**
* Load and check permissions
*
* @return \IPS\Content\Item
* @throws \OutOfRangeException
*/
public static function loadAndCheckPerms( $id )
{
$obj = static::load( $id );
if ( !$obj->canView() )
{
throw new \OutOfRangeException;
}
return $obj;
}
/**
* Member can view?
*
* @param \IPS\Member|NULL $member The member to check for, or NULL for currently logged in member
* @return bool
*/
public function canView( \IPS\Member $member = NULL )
{
$member = $member ?: \IPS\Member::loggedIn();
return $this->member->member_id === $member->member_id or array_key_exists( $member->member_id, iterator_to_array( $this->member->alternativeContacts( array( 'billing=1' ) ) ) );
}
/**
* Get member
*
* @return \IPS\Member
*/
public function get_member()
{
return \IPS\nexus\Customer::load( $this->_data['member'] );
}
/**
* Set member
*
* @param \IPS\Member
* @return void
*/
public function set_member( \IPS\Member $member )
{
$this->_data['member'] = $member->member_id;
}
/**
* Get payment gateway
*
* @return \IPS\nexus\Gateway
*/
public function get_method()
{
return \IPS\nexus\Gateway::load( $this->_data['method'] );
}
/**
* Set payment gateway
*
* @param \IPS\nexus\Gateway
* @return void
*/
public function set_method( \IPS\nexus\Gateway $gateway )
{
$this->_data['method'] = $gateway->id;
}
/**
* Get start date
*
* @return \IPS\DateTime
*/
public function get_started()
{
return \IPS\DateTime::ts( $this->_data['started'] );
}
/**
* Set next payment date
*
* @param \IPS\DateTime $date The invoice date
* @return void
*/
public function set_next_cycle( \IPS\DateTime $date = NULL )
{
$this->_data['next_cycle'] = $date ? $date->getTimestamp() : NULL;
}
/**
* Get next payment date
*
* @return \IPS\DateTime
*/
public function get_next_cycle()
{
return $this->_data['next_cycle'] ? \IPS\DateTime::ts( $this->_data['next_cycle'] ) : NULL;
}
/**
* Set start date
*
* @param \IPS\DateTime $date The invoice date
* @return void
*/
public function set_started( \IPS\DateTime $date )
{
$this->_data['started'] = $date->getTimestamp();
}
/**
* Suspend
*
* @return void
* @throws \DomainException
*/
public function suspend()
{
$this->doSuspend();
$this->member->log( 'billingagreement', array( 'type' => 'suspend', 'id' => $this->id, 'gw_id' => $this->gw_id ) );
$this->next_cycle = NULL;
$this->save();
}
/**
* Reactivate
*
* @return void
* @throws \DomainException
*/
public function reactivate()
{
$this->doReactivate();
$this->member->log( 'billingagreement', array( 'type' => 'reactivate', 'id' => $this->id, 'gw_id' => $this->gw_id ) );
$this->next_cycle = $this->nextPaymentDate();
$this->save();
}
/**
* Cancel
*
* @return void
* @throws \DomainException
*/
public function cancel()
{
$this->doCancel();
$this->member->log( 'billingagreement', array( 'type' => 'cancel', 'id' => $this->id, 'gw_id' => $this->gw_id ) );
$this->next_cycle = NULL;
$this->canceled = TRUE;
}
/**
* Front-End URL
*
* @return \IPS\Http\Url
*/
public function url()
{
return \IPS\Http\Url::internal( "app=nexus&module=clients&controller=billingagreements&do=view&id={$this->id}", 'front', 'clientsbillingagreement' );
}
/**
* ACP URL
*
* @return \IPS\Http\Url
*/
public function acpUrl()
{
return \IPS\Http\Url::internal( "app=nexus&module=payments&controller=billingagreements&id={$this->id}", 'admin' );
}
}
@@ -2,9 +2,9 @@
/**
* @brief Customer Stored Card Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 12 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -56,11 +56,15 @@ class _CreditCard extends \IPS\Patterns\ActiveRecord
$obj->_new = FALSE;
/* Import data */
if ( static::$databasePrefix )
{
$databasePrefixLength = \strlen( static::$databasePrefix );
}
foreach ( $data as $k => $v )
{
if( static::$databasePrefix AND mb_strpos( $k, static::$databasePrefix ) === 0 )
{
$k = \substr( $k, \strlen( static::$databasePrefix ) );
$k = \substr( $k, $databasePrefixLength );
}
$obj->_data[ $k ] = $v;
@@ -93,7 +97,7 @@ class _CreditCard extends \IPS\Patterns\ActiveRecord
foreach ( $gateways as $gateway )
{
$invoice = new \IPS\nexus\Invoice;
foreach ( $gateway->paymentScreen( $invoice, $invoice->total ) as $element )
foreach ( $gateway->paymentScreen( $invoice, $invoice->total, $customer ) as $element )
{
if ( !$element->htmlId )
{
@@ -2,9 +2,10 @@
/**
* @brief Custom Customer Field Node
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 16 Apr 2013
* @version SVN_VERSION_NUMBER
*/
@@ -118,13 +119,14 @@ class _CustomField extends \IPS\CustomField
$form->addHeader( 'customer_field_purchase' );
$form->add( new \IPS\Helpers\Form\YesNo( 'f_purchase_show', $this->purchase_show ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'f_purchase_require', $this->purchase_require ) );
unset( $form->elements[''][1] );
unset( $form->elements['']['pf_not_null'] );
unset( $form->elements['']['pf_max_input'] );
unset( $form->elements['']['pf_input_format'] );
unset( $form->elements[''][2] );
unset( $form->elements['']['pf_search_type'] );
unset( $form->elements['']['pf_search_type_on_off'] );
unset( $form->elements['']['pf_format'] );
}
@@ -2,9 +2,9 @@
/**
* @brief Customer Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -32,13 +32,29 @@ class _Customer extends \IPS\Member
/**
* @brief Cached logged in member
*/
protected static $loggedInMember = NULL;
public static $loggedInMember = NULL;
/**
* @brief [ActiveRecord] ID Database Column
*/
public static $databaseColumnId = 'member_id';
/**
* Get logged in member
*
* @return \IPS\Member
*/
public static function loggedIn()
{
/* If we haven't loaded the member yet, or if the session member has changed since we last loaded the member, reload and cache */
if( static::$loggedInMember === NULL )
{
static::$loggedInMember = static::load( parent::loggedIn()->member_id );
}
return static::$loggedInMember;
}
/**
* Construct Load Query
*
@@ -204,7 +220,7 @@ class _Customer extends \IPS\Member
$save = array();
foreach ( $amounts as $amount )
{
$save[ $amount->currency ] = $amount->amount;
$save[ $amount->currency ] = $amount->amountAsString();
}
$this->_data['cm_credits'] = json_encode( $save );
}
@@ -499,6 +515,6 @@ class _Customer extends \IPS\Member
*/
public function acpUrl()
{
return \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member_id}");
return \IPS\Http\Url::internal( "app=nexus&module=customers&controller=view&id={$this->member_id}", 'admin' );
}
}
+112 -7
View File
@@ -2,9 +2,9 @@
/**
* @brief Customer History Table
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 18 Sep 2014
* @version SVN_VERSION_NUMBER
@@ -48,8 +48,8 @@ class _History extends \IPS\Helpers\Table\Db
if ( $showCustomer )
{
$this->include[] = 'log_member';
}
}
$this->sortBy = $this->sortBy ?: 'log_date';
$this->noSort = array( 'log_type', 'log_ip_address', 'log_data' );
$this->parsers = array(
@@ -292,9 +292,28 @@ class _History extends \IPS\Helpers\Table\Db
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_edited', FALSE, array( 'htmlsprintf' => array( $purchase, ( isset( $val['system'] ) and $val['system'] ) ? '' : $byStaff ) ) );
case 'transfer_from':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_transfer_from', FALSE, array( 'htmlsprintf' => array( $purchase, \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['to'] ) ), $byStaff ) ) );
try
{
$to = \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['to'] ) );
}
catch( \OutOfRangeException $e )
{
$to = \IPS\Member::loggedIn()->language()->addToStack( 'deleted_member' );
}
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_transfer_from', FALSE, array( 'htmlsprintf' => array( $purchase, $to, $byStaff ) ) );
case 'transfer_to':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_transfer_to', FALSE, array( 'htmlsprintf' => array( $purchase, \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['from'] ) ), $byStaff ) ) );
try
{
$from = \IPS\Theme::i()->getTemplate('global', 'nexus')->userLink( \IPS\nexus\Customer::load( $val['from'] ) );
}
catch( \OutOfRangeException $e )
{
$from = \IPS\Member::loggedIn()->language()->addToStack( 'deleted_member' );
}
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_transfer_to', FALSE, array( 'htmlsprintf' => array( $purchase, $from, $byStaff ) ) );
case 'cancel':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_purchase_canceled', FALSE, array( 'htmlsprintf' => array( $purchase, $byStaff ) ) );
@@ -336,6 +355,7 @@ class _History extends \IPS\Helpers\Table\Db
return \IPS\Member::loggedIn()->language()->addToStack( "history_commission_{$val['type']}", FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $purchase ) ) );
case 'invoice':
case 'invoice_refund':
try
{
$invoice = \IPS\Theme::i()->getTemplate('invoices', 'nexus')->link( \IPS\nexus\Invoice::load( $val['invoice_id'] ), TRUE );
@@ -345,7 +365,7 @@ class _History extends \IPS\Helpers\Table\Db
$invoice = \IPS\Member::loggedIn()->language()->addToStack('invoice_number', FALSE, array( 'sprintf' => array( $val['invoice_id'] ) ) );
}
return \IPS\Member::loggedIn()->language()->addToStack( 'history_commission_invoice', FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $invoice ) ) );
return \IPS\Member::loggedIn()->language()->addToStack( "history_commission_{$val['type']}", FALSE, array( 'htmlsprintf' => array( new \IPS\nexus\Money( $val['amount'], $val['currency'] ), $invoice ) ) );
case 'bought':
try
@@ -432,6 +452,49 @@ class _History extends \IPS\Helpers\Table\Db
{
foreach ( $val['other'] as $change )
{
/* Older versions may not have stored the display value, so we need to account for that */
if( mb_strpos( $change['name'], 'nexus_ccfield_' ) !== FALSE AND is_array( $change['value'] ) )
{
try
{
/* If it's an array, we will start first by assuming it is probably an address */
$value = \IPS\GeoLocation::buildFromJson( json_encode( $change['value'] ) )->toString( ', ' );
/* A bad address will return an empty string */
if( !$value )
{
throw new \BadFunctionCallException;
}
$change['value'] = $value;
}
/* Maybe it wasn't an address or geoip support is disabled */
catch( \BadFunctionCallException $e )
{
$_value = array();
/* We will just loop and implode so we have a string */
foreach( $change['value'] as $k => $v )
{
if( is_array( $v ) )
{
foreach( $v as $_k => $_v )
{
$_value[] = $_k . ': ' . $_v;
}
}
else
{
$_value[] = $k . ': ' . $v;
}
}
$value = implode( ', ', $_value );
$change['value'] = htmlspecialchars( $value, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
}
}
if ( isset( $change['old'] ) )
{
$changes[] = \IPS\Member::loggedIn()->language()->addToStack('history_field_changed_from', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $change['name'] ), $change['old'], $change['value'] ) ) );
@@ -554,11 +617,18 @@ class _History extends \IPS\Helpers\Table\Db
break;
case 'download':
switch ( $val['type'] )
{
case 'idm':
try
{
if ( \IPS\Application::appIsEnabled( 'downloads' ) === FALSE )
{
/* If the app is disabled, bubble up to avoid an \IPS\Db\Exception for missing tables - we still want to show the log */
throw new \OutOfRangeException;
}
$options = array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->downloadsLink( \IPS\downloads\File::load( $val['id'] ) ) ) );
}
catch ( \OutOfRangeException $e )
@@ -585,6 +655,41 @@ class _History extends \IPS\Helpers\Table\Db
return \IPS\Member::loggedIn()->language()->addToStack( 'history_download', FALSE, array( 'htmlsprintf' => $file ) );
}
break;
case 'support':
if ( isset( $val['type'] ) and $val['type'] == 'email' )
{
$by = \IPS\Member::loggedIn()->language()->addToStack( 'history_support_by_email' );
}
else
{
$by = $byCustomer ?: $byStaff;
}
try
{
$options = array( 'htmlsprintf' => array( \IPS\Theme::i()->getTemplate( 'support', 'nexus' )->link( \IPS\nexus\Support\Request::load( $val['id'] ), FALSE ), $by ) );
}
catch ( \OutOfRangeException $e )
{
$options = array( 'sprintf' => array( $val['title'] ), 'htmlsprintf' => array( $by ) );
}
return \IPS\Member::loggedIn()->language()->addToStack( 'history_support', FALSE, $options );
case 'billingagreement':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_billingagreement_' . $val['type'], FALSE, array( 'sprintf' => array( $val['id'], $val['gw_id'], $byCustomer ?: $byStaff ) ) );
break;
case 'note':
return \IPS\Member::loggedIn()->language()->addToStack( 'history_' . $val . '_note', FALSE, array( 'sprintf' => $byStaff ) );
break;
case 'custom':
return $val['message'];
break;
}
return '';