Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,90 @@
<?php
/**
* @brief Checkout Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 28 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Checkout Settings
*/
class _checkoutsettings extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'checkout_settings' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
$form = new \IPS\Helpers\Form;
$form->addHeader( 'checkout_settings' );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_https', \IPS\Settings::i()->nexus_https, FALSE, array(), function( $val )
{
if ( $val )
{
try
{
\IPS\Http\Url::internal( '', 'front', NULL, array(), TRUE )->request()->get();
}
catch ( \IPS\Http\Request\Exception $e )
{
throw new \DomainException('nexus_https_err');
}
}
} ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_split_payments_on', \IPS\Settings::i()->nexus_split_payments != -1, FALSE, array( 'togglesOn' => array( 'nexus_split_payments' ) ) ) );
$form->add( new \IPS\nexus\Form\Money( 'nexus_split_payments', \IPS\Settings::i()->nexus_split_payments ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_split_payments' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'nexus_tac', \IPS\Settings::i()->nexus_tac, FALSE, array(
'options' => array(
'none' => 'nexus_tac_none',
'button' => 'nexus_tac_button',
'checkbox' => 'nexus_tac_checkbox'
),
'toggles' => array(
'button' => array( 'nexus_tac_link' ),
'checkbox' => array( 'nexus_tac_link' )
)
) ) );
$form->add( new \IPS\Helpers\Form\Url( 'nexus_tac_link', \IPS\Settings::i()->nexus_tac_link, FALSE, array(), NULL, NULL, NULL, 'nexus_tac_link' ) );
$form->addHeader( 'nexus_checkreg' );
$form->addMessage( 'nexus_checkreg_desc' );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_checkreg_usernames', \IPS\Settings::i()->nexus_checkreg_usernames ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_checkreg_captcha', \IPS\Settings::i()->nexus_checkreg_captcha ) );
if ( $values = $form->values() )
{
$values['nexus_split_payments'] = $values['nexus_split_payments_on'] ? ( $values['nexus_split_payments'] == '*' ? 0 : json_encode( $values['nexus_split_payments'] ) ) : -1;
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__checkout_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=checkoutsettings' ) );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('checkout_settings');
\IPS\Output::i()->output = $form;
}
}
@@ -0,0 +1,120 @@
<?php
/**
* @brief Currencies
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Currencies
*/
class _currencies extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'currencies_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
$languages = \IPS\Lang::languages();
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->langPrefix = 'currency_';
$matrix->columns = array(
'code' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Text( $key, $value, FALSE, array( 'minLength' => 3, 'maxLength' => 3, 'placeholder' => 'USD' ) );
},
'default' => function( $key, $value, $data ) use ( $languages )
{
if ( count( $languages ) === 1 )
{
return new \IPS\Helpers\Form\Checkbox( $key, $value );
}
else
{
$options = array();
foreach ( $languages as $k => $v )
{
$options[ $v->id ] = $v->_title;
}
return new \IPS\Helpers\Form\Select( $key, $value, FALSE, array( 'options' => $options, 'multiple' => TRUE ) );
}
}
);
$warnings = '';
if ( $currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE ) )
{
foreach ( $currencies as $code => $defaults )
{
$matrix->rows[] = array(
'code' => $code,
'default' => $defaults
);
if ( !in_array( $code, array( 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYR', 'BZD', 'CAD', 'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GGP', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'IMP', 'INR', 'IQD', 'IRR', 'ISK', 'JEP', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SPL*', 'SRD', 'STD', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP', 'TRY', 'TTD', 'TVD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XDR', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW', 'ZWD' ) ) )
{
$warnings .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'currency_code_invalid', FALSE, array( 'sprintf' => array( $code ) ) ), 'warning' );
}
}
}
else
{
$matrix->rows[] = array(
'code' => \IPS\Settings::i()->nexus_currency,
'default' => count( $languages ) === 1 ? TRUE : array_keys( $languages )
);
}
if ( $values = $matrix->values() )
{
$save = array();
foreach ( $values as $data )
{
if ( $data['code'] )
{
$save[ $data['code'] ] = ( count( $languages ) === 1 ) ? ( $data['default'] ? array_keys( $languages ) : array() ) : $data['default'];
}
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => json_encode( $save ) ), array( 'conf_key=?', 'nexus_currency' ) );
\IPS\Settings::i()->nexus_currency = json_encode( $save );
unset( \IPS\Data\Store::i()->settings );
\IPS\Session::i()->log( 'acplogs__currencies' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=currencies' ) );
}
\IPS\Output::i()->output = $matrix . $warnings;
}
}
@@ -0,0 +1,42 @@
<?php
/**
* @brief donations
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage
* @since 05 May 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* donations
*/
class _donationgoals extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Donation\Goal';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'donationgoals_manage' );
parent::execute();
}
}
@@ -0,0 +1,116 @@
<?php
/**
* @brief donations
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage
* @since 17 Jun 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* donations
*/
class _donations extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'donations_manage' );
parent::execute();
}
/**
* View Donations
*
* @return void
*/
protected function manage()
{
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'donationgoals_manage' ) )
{
\IPS\Output::i()->sidebar['actions'][] = array(
'icon' => 'cog',
'title' => 'donation_goals',
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=donationgoals" )
);
}
$table = new \IPS\Helpers\Table\Db( 'nexus_donate_logs', \IPS\Http\Url::internal('app=nexus&module=payments&controller=donations') );
$table->include = array( 'dl_goal', 'dl_amount', 'dl_member', 'dl_invoice', 'dl_date' );
$table->parsers = array(
'dl_goal' => function( $val )
{
try
{
return \IPS\nexus\Donation\Goal::load( $val )->_title;
}
catch ( \Exception $e )
{
return NULL;
}
},
'dl_member' => function ( $val )
{
return \IPS\Theme::i()->getTemplate('global')->userLink( \IPS\Member::load( $val ) );
},
'dl_amount' => function( $val, $row )
{
try
{
return (string) new \IPS\nexus\Money( $val, \IPS\nexus\Donation\Goal::load( $row['dl_goal'] )->currency );
}
catch ( \Exception $e )
{
return $val;
}
},
'dl_invoice' => function( $val )
{
try
{
return \IPS\Theme::i()->getTemplate('invoices')->link( \IPS\nexus\Invoice::load( $val ), TRUE );
}
catch ( \OutOfRangeException $e )
{
return '';
}
},
'dl_date' => function( $val )
{
return \IPS\DateTime::ts( $val );
}
);
foreach ( \IPS\nexus\Donation\Goal::roots() as $goal )
{
$table->filters[ "nexus_donategoal_{$goal->_id}" ] = "dl_goal={$goal->_id}";
}
$table->advancedSearch = array(
'dl_goal' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => '\IPS\nexus\Donation\Goal' ) ),
'dl_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
'dl_amount' => \IPS\Helpers\Table\SEARCH_NUMERIC,
'dl_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
);
\IPS\Output::i()->output = (string) $table;
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_donations');
}
}
@@ -0,0 +1,68 @@
<?php
/**
* @brief Notification Copy Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 19 Aug 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Notification Copy Settings
*/
class _emails extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_copies_setting' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_notify_copy_types', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ), FALSE, array( 'options' => array(
'invoice_warn' => 'nexus_notify_copy_invoice_warn',
'new_invoice' => 'nexus_notify_copy_new_invoice',
'payment_received' => 'nexus_notify_copy_payment_received',
'payment_waiting' => 'nexus_notify_copy_payment_waiting',
'payment_held' => 'nexus_notify_copy_payment_held',
'payment_failed' => 'nexus_notify_copy_payment_failed',
'payment_refunded' => 'nexus_notify_copy_payment_refunded',
'commission_earned' => 'nexus_notify_copy_commission_earned',
) ) ) );
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_notify_copy_email', explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) ) );
if ( $form->values() )
{
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__email_copies_setting' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=emails' ), 'saved' );
}
\IPS\Output::i()->output = $form;
}
}
@@ -0,0 +1,69 @@
<?php
/**
* @brief Anti-Fraud Rules
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 11 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Anti-Fraud Rules
*/
class _fraud extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Fraud\Rule';
/**
* Description can contain HTML?
*/
public $_descriptionHtml = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'fraud_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
foreach ( \IPS\nexus\Fraud\Rule::roots() as $rule )
{
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_fraud_rules', array( 'f_order>?', $rule->order ) ), 'IPS\nexus\Fraud\Rule' ) as $otherRule )
{
if ( $rule->isSubsetOf( $otherRule ) )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( \IPS\Member::loggedIn()->language()->addToStack('fraud_rule_conflict', FALSE, array( 'sprintf' => array( $rule->name, $otherRule->name ) ) ), 'warning', NULL, FALSE );
break 2;
}
}
}
parent::manage();
}
}
@@ -0,0 +1,148 @@
<?php
/**
* @brief Payment Gateways
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Payment Gateways
*/
class _gateways extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Gateway';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'gateways_manage' );
parent::execute();
}
/**
* Get Root Buttons
*
* @return array
*/
public function _getRootButtons()
{
$buttons = parent::_getRootButtons();
if ( isset( $buttons['add'] ) )
{
$buttons['add']['link'] = $buttons['add']['link']->setQueryString( '_new', TRUE );
}
return $buttons;
}
/**
* Add/Edit Form
*
* @return void
*/
protected function form()
{
if ( \IPS\Request::i()->id )
{
return parent::form();
}
else
{
if ( \IPS\IN_DEV )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) );
}
else
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) );
}
\IPS\Output::i()->output = new \IPS\Helpers\Wizard( array(
'gateways_gateway' => function( $data )
{
$options = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway' ) as $file )
{
if ( $file->isDir() and !$file->isDot() )
{
if ( ( (string) $file === 'Test' and !\IPS\NEXUS_TEST_GATEWAYS ) or (string) $file === 'SagePay' )
{
continue;
}
$options[ (string) $file ] = 'gateway__' . $file;
}
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'gateways_gateway', TRUE, NULL, array( 'options' => $options ) ) );
if ( $values = $form->values() )
{
return array( 'gateway' => $values['gateways_gateway'] );
}
return $form;
},
'gateways_details' => function( $data )
{
$form = new \IPS\Helpers\Form('gw');
$form->add( new \IPS\Helpers\Form\Translatable( 'paymethod_name', \IPS\Member::loggedIn()->language()->addToStack( 'gateway__' . $data['gateway'] ), TRUE ) );
$class = 'IPS\nexus\Gateway\\' . $data['gateway'];
$obj = new $class;
$obj->gateway = $data['gateway'];
$obj->active = TRUE;
$obj->settings( $form );
if ( $values = $form->values() )
{
$settings = array();
foreach ( $values as $k => $v )
{
if ( $k !== 'paymethod_name' )
{
$settings[ mb_substr( $k, mb_strlen( $data['gateway'] ) + 1 ) ] = $v;
}
}
try
{
$settings = $obj->testSettings( $settings );
}
catch ( \InvalidArgumentException $e )
{
$form->error = $e->getMessage();
return $form;
}
$obj->settings = json_encode( $settings );
$obj->save();
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $values['paymethod_name'] );
$values = $obj->formatFormValues( $values );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways') );
}
return $form;
}
), \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways&do=form') );
}
}
}
Whitespace-only changes.
@@ -0,0 +1,37 @@
<?php
/**
* @brief Invoice Timeline
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 19 Jun 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Invoice Timeline
*/
class _invoiceTimeline extends \IPS\Dispatcher\Controller
{
/**
* Manage
*
* @return void
*/
protected function manage()
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'invoiceTimeline.css', 'nexus', 'admin' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('invoices')->invoiceTimeline();
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,87 @@
<?php
/**
* @brief Payment Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Payment Settings
*/
class _paymentsettings extends \IPS\Dispatcher\Controller
{
/**
* Call
*
* @return void
*/
public function __call( $method, $args )
{
$tabs = array();
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'currencies_manage' ) )
{
$tabs['currencies'] = 'currencies';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'gateways_manage' ) )
{
$tabs['gateways'] = 'payment_methods';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'tax_manage' ) )
{
$tabs['tax'] = 'tax_rates';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'checkout_settings' ) )
{
$tabs['checkoutsettings'] = 'checkout_settings';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'fraud_manage' ) )
{
$tabs['fraud'] = 'anti_fraud_rules';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transaction_review_settings' ) )
{
$tabs['review'] = 'transaction_review';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'email_copies_setting' ) )
{
$tabs['emails'] = 'notification_copies';
}
if ( isset( \IPS\Request::i()->tab ) and isset( $tabs[ \IPS\Request::i()->tab ] ) )
{
$activeTab = \IPS\Request::i()->tab;
}
else
{
$_tabs = array_keys( $tabs ) ;
$activeTab = array_shift( $_tabs );
}
$classname = 'IPS\nexus\modules\admin\payments\\' . $activeTab;
$class = new $classname;
$class->url = \IPS\Http\Url::internal("app=nexus&module=payments&controller=paymentsettings&tab={$activeTab}");
$class->execute();
if ( $method !== 'manage' or \IPS\Request::i()->isAjax() )
{
return;
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('payment_settings');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, \IPS\Output::i()->output, \IPS\Http\Url::internal( "app=nexus&module=payments&controller=paymentsettings" ) );
}
}
@@ -0,0 +1,384 @@
<?php
/**
* @brief Payouts
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 07 Apr 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Payouts
*/
class _payouts extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_manage' );
parent::execute();
}
/**
* Payout Requests
*
* @return void
*/
protected function manage()
{
/* Redirect to settings if we haven't set it up */
if ( !\IPS\Settings::i()->nexus_payout )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' ) );
}
/* Build table */
$table = \IPS\nexus\Payout::table( array(), \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_payouts');
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'payouts_settings' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
'settings' => array(
'icon' => 'cog',
'title' => 'account_credit_settings',
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' )
),
);
foreach ( \IPS\Db::i()->select( 'po_gateway', 'nexus_payouts', array( 'po_status=?', \IPS\nexus\Payout::STATUS_PENDING ), NULL, NULL, 'po_gateway' ) as $gateway )
{
$classname = 'IPS\nexus\Gateway\\' . $gateway . '\Payout';
if ( class_exists( $classname ) and method_exists( $classname, 'massProcess' ) )
{
\IPS\Output::i()->sidebar['actions'][] = array(
'icon' => 'check',
'title' => \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_mass_payout', TRUE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( 'payout__admin_' . $gateway ) ) ) ),
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=massprocess&gateway=' . $gateway )
);
}
}
}
\IPS\Output::i()->output = (string) $table;
}
/**
* View
*
* @return void
*/
protected function view()
{
try
{
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X200/2', 404, '' );
}
\IPS\Output::i()->sidebar['actions'] = $payout->buttons( 'v' );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'payout_number', FALSE, array( 'sprintf' => array( $payout->id ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('payouts')->view( $payout );
}
/**
* Approve
*
* @return void
*/
protected function process()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
try
{
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X200/3', 404, '' );
}
if ( $payout->status !== $payout::STATUS_PENDING )
{
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/4', 403, '' );
}
try
{
$payout->process();
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( $e->getMessage(), '1X200/1', 500, '' );
}
$payout->status = $payout::STATUS_COMPLETE;
$payout->processed_by = \IPS\Member::loggedIn();
$payout->save();
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
$payout->member->log( 'payout', array( 'type' => 'processed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
\IPS\Email::buildFromTemplate( 'nexus', 'payoutComplete', array( $payout ) )->send( $payout->member );
$this->_redirect( $payout );
}
/**
* Mass Approve
*
* @return void
*/
protected function massprocess()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
$classname = 'IPS\nexus\Gateway\\' . \IPS\Request::i()->gateway . '\Payout';
if ( !class_exists( $classname ) or !method_exists( $classname, 'massProcess' ) )
{
\IPS\Output::i()->error( 'generic_error', '2X200/8', 403, '' );
}
$payouts = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_payouts', array( 'po_status=? AND po_gateway=?', \IPS\nexus\Payout::STATUS_PENDING, \IPS\Request::i()->gateway ) ), $classname );
try
{
$classname::massProcess( $payouts );
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( $e->getMessage(), '1X200/9', 403, '' );
}
foreach ( $payouts as $payout )
{
$payout->status = $payout::STATUS_COMPLETE;
$payout->completed = new \IPS\DateTime;
$payout->processed_by = \IPS\Member::loggedIn();
$payout->save();
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
$payout->member->log( 'payout', array( 'type' => 'processed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
\IPS\Email::buildFromTemplate( 'nexus', 'payoutComplete', array( $payout ) )->send( $payout->member );
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
}
/**
* Cancel
*
* @return void
*/
protected function cancel()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
try
{
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X200/6', 404, '' );
}
if ( $payout->status !== $payout::STATUS_PENDING )
{
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/5', 403, '' );
}
$payout->status = $payout::STATUS_CANCELED;
$payout->completed = new \IPS\DateTime;
$payout->processed_by = \IPS\Member::loggedIn();
$payout->save();
\IPS\Session::i()->log( 'acplogs__payout_cancelled', array( $payout->id => FALSE ) );
$payout->member->log( 'payout', array( 'type' => 'cancel', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
if ( \IPS\Request::i()->prompt )
{
$credits = $payout->member->cm_credits;
$credits[ $payout->currency ]->amount += $payout->amount->amount;
$payout->member->cm_credits = $credits;
$payout->member->save();
}
$this->_redirect( $payout );
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
try
{
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X200/7', 404, '' );
}
$payout->delete();
\IPS\Session::i()->log( 'acplogs__payout_deleted', array( $payout->id => FALSE ) );
$payout->member->log( 'payout', array( 'type' => 'dismissed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
}
/**
* Payout Settings
*
* @return void
*/
protected function settings()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_settings' );
$options = array();
$toggles = array();
$fields = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway' ) as $file )
{
if ( $file->isDir() and !$file->isDot() and file_exists( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway/' . $file . '/Payout.php' ) )
{
$options[ (string) $file ] = 'payout__admin_' . $file;
$toggles[ (string) $file ] = array( 'form_header_payout_settings' );
$class = 'IPS\nexus\Gateway\\' . (string) $file . '\\Payout';
foreach ( $class::settings() as $field )
{
if ( !$field->htmlId )
{
$field->htmlId = md5(uniqid());
}
$fields[] = $field;
$toggles[ (string) $file ][] = $field->htmlId;
}
}
}
$groups = array();
foreach ( \IPS\Member\Group::groups( TRUE, FALSE ) as $group )
{
$groups[ $group->g_id ] = $group->name;
}
$settings = \IPS\Settings::i()->nexus_payout ? json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) : array();
$settings = is_array( $settings ) ? array_keys( $settings ) : array();
$form = new \IPS\Helpers\Form;
$form->addMessage('payout_description');
$form->addHeader('commission_settings');
$form->add( new \IPS\Helpers\Form\Select( 'nexus_no_commission', explode( ',', \IPS\Settings::i()->nexus_no_commission ), FALSE, array( 'multiple' => TRUE, 'options' => $groups ) ) );
$form->addHeader('withdrawal_methods');
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_payout', $settings, FALSE, array( 'options' => $options, 'toggles' => $toggles ) ) );
foreach ( $fields as $field )
{
$form->add( $field );
}
$form->addHeader('payout_settings');
$form->add( new \IPS\nexus\Form\Money( 'nexus_payout_min', \IPS\Settings::i()->nexus_payout_min ? json_decode( \IPS\Settings::i()->nexus_payout_min, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_payout_min' ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_payout_approve', \IPS\Settings::i()->nexus_payout_approve, FALSE, array(), NULL, NULL, NULL, 'nexus_payout_approve' ) );
$form->addHeader('topup_settings');
$form->add( new \IPS\Helpers\Form\YesNo( 'allow_topups', \IPS\Settings::i()->nexus_min_topup, FALSE, array( 'togglesOn' => array( 'nexus_min_topup', 'nexus_max_credit' ) ) ) );
$form->add( new \IPS\nexus\Form\Money( 'nexus_min_topup', \IPS\Settings::i()->nexus_min_topup ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_min_topup' ) );
$form->add( new \IPS\nexus\Form\Money( 'nexus_max_credit', \IPS\Settings::i()->nexus_max_credit ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_max_credit' ) );
if ( $values = $form->values() )
{
$payoutSettings = array();
foreach ( $values['nexus_payout'] as $k )
{
$payoutSettings[ $k ] = array();
foreach ( $values as $l => $v )
{
if ( mb_substr( $l, 0, mb_strlen( $k ) ) === mb_strtolower( $k ) )
{
$payoutSettings[ $k ][ mb_substr( $l, mb_strlen( $k ) + 1 ) ] = $v;
unset( $values[ $l ] );
}
}
}
$values['nexus_payout'] = json_encode( $payoutSettings );
$values['nexus_payout_min'] = is_array( $values['nexus_payout_min'] ) ? json_encode( $values['nexus_payout_min'] ) : '*';
if ( $values['allow_topups'] )
{
$values['nexus_min_topup'] = $values['nexus_min_topup'] == '*' ? '*' : json_encode( $values['nexus_min_topup'] );
$values['nexus_max_credit'] = $values['nexus_max_credit'] == '*' ? '*' : json_encode( $values['nexus_max_credit'] );
}
else
{
$values['nexus_min_topup'] = '';
$values['nexus_max_credit'] = '';
}
unset( $values['allow_topups'] );
$values['nexus_no_commission'] = implode( ',', $values['nexus_no_commission'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__payout_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts'), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('account_credit_settings');
\IPS\Output::i()->output = $form;
}
/**
* Redirect
*
* @param \IPS\nexus\Payout $payout The payout
* @return void
*/
protected function _redirect( \IPS\nexus\Payout $payout )
{
if ( isset( \IPS\Request::i()->r ) )
{
switch ( mb_substr( \IPS\Request::i()->r, 0, 1 ) )
{
case 'v':
\IPS\Output::i()->redirect( $payout->acpUrl() );
break;
case 'c':
\IPS\Output::i()->redirect( $payout->member->acpUrl() );
break;
case 't':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', \IPS\Request::i()->filter ) );
break;
}
}
\IPS\Output::i()->redirect( $payout->acpUrl() );
}
}
@@ -0,0 +1,68 @@
<?php
/**
* @brief Transaction Review
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Transaction Review
*/
class _review extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transaction_review_settings' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_revw_sa_on', \IPS\Settings::i()->nexus_revw_sa != -1, FALSE, array( 'togglesOn' => array( 'nexus_revw_sa' ) ) ) );
$form->add( new \IPS\Helpers\Form\Node( 'nexus_revw_sa', \IPS\Settings::i()->nexus_revw_sa ?: 0, FALSE, array( 'class' => 'IPS\nexus\Support\StockAction', 'zeroVal' => 'do_not_suggest_stock_action' ), NULL, NULL, NULL, 'nexus_revw_sa' ) );
if ( $values = $form->values() )
{
if ( !$values['nexus_revw_sa_on'] )
{
$values['nexus_revw_sa'] = -1;
}
elseif ( $values['nexus_revw_sa'] )
{
$values['nexus_revw_sa'] = $values['nexus_revw_sa']->id;
}
unset( $values['nexus_revw_sa_on'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__transaction_review_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=review' ), 'saved' );
}
\IPS\Output::i()->output = $form;
}
}
@@ -0,0 +1,711 @@
<?php
/**
* @brief Shipments
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 20 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Shipments
*/
class _shipping extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'nexus_ship_orders', \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=shipping' ) );
$table->sortBy = $table->sortBy ?: 'o_date';
/* Format Columns */
$table->include = array( 'o_status', 'o_method', 'o_invoice', 'o_date' );
$table->parsers = array(
'o_status' => function( $val )
{
return \IPS\Theme::i()->getTemplate('shiporders')->status( $val );
},
'o_method' => function( $val, $row )
{
if ( $row['o_api_service'] )
{
return $row['o_api_service'];
}
try
{
return \IPS\nexus\Shipping\FlatRate::load( $val )->_title;
}
catch ( \Exception $e )
{
return '';
}
},
'o_invoice' => function( $val )
{
try
{
return \IPS\Theme::i()->getTemplate('invoices')->link( \IPS\nexus\Invoice::load( $val ) );
}
catch ( \Exception $e )
{
return '';
}
},
'o_date' => function( $val )
{
return (string) \IPS\DateTime::ts( $val );
}
);
/* Filters */
$table->filters = array(
'sstatus_pend' => array( 'o_status=?', 'pend' ),
);
/* Search */
$methods = array();
foreach( \IPS\nexus\Shipping\FlatRate::roots() as $method )
{
$methods[ $method->id ] = $method->_title;
}
$table->advancedSearch = array(
'o_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
\IPS\nexus\Shipping\Order::STATUS_SHIPPED => 'sstatus_done',
\IPS\nexus\Shipping\Order::STATUS_PENDING => 'sstatus_pend',
\IPS\nexus\Shipping\Order::STATUS_CANCELED => 'sstatus_canc',
), 'multiple' => TRUE ) ),
'o_method' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $methods, 'multiple' => TRUE ) ),
'o_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'o_shipped_date'=> \IPS\Helpers\Table\SEARCH_DATE_RANGE,
'o_tracknumber' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
);
$table->quickSearch = 'o_tracknumber';
/* Buttons */
$table->rowButtons = function( $row )
{
return array_merge( array(
'view' => array(
'icon' => 'search',
'title' => 'shipment_view',
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=shipping&do=view&id={$row['o_id']}" )
)
), \IPS\nexus\Shipping\Order::constructFromData( $row )->buttons( 't' ) );
};
/* Settings Button */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'shipmethods_manage' ) )
{
\IPS\Output::i()->sidebar['actions']['settings'] = array(
'title' => 'shipping_rates',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal('app=nexus&module=payments&controller=shippingrates'),
);
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('shipping');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
}
/**
* View
*
* @return void
*/
public function view()
{
/* Load */
try
{
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X193/1', 404, '' );
}
$easyPost = NULL;
if ( \IPS\Settings::i()->easypost_api_key )
{
$extra = json_decode( $shipment->extra, TRUE );
if ( isset( $extra['shipment'] ) )
{
try
{
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . $extra['shipment'] )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->get()->decodeJson();
}
catch ( \IPS\Http\Request\Exception $e ) { }
}
}
/* Add Buttons */
\IPS\Output::i()->sidebar['actions'] = $shipment->buttons( 'v' );
/* Output */
\IPS\Output::i()->title = $shipment->method ? \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number_with_method', FALSE, array( 'sprintf' => array( $shipment->id, $shipment->method->_title ) ) ) : \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'shiporders' )->view( $shipment, $easyPost );
}
/**
* Ship
*
* @return void
*/
public function ship()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
/* Load */
try
{
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X193/2', 404, '' );
}
/* Build Form */
$form = new \IPS\Helpers\Form( 'form', 'shipment_ship' );
if ( \IPS\Settings::i()->easypost_api_key )
{
/* Calculate stuff */
$weightInOz = 0;
$lengthInInches = 0;
$widthInInches = 0;
$heightInInches = 0;
foreach ( $shipment->items as $item )
{
$weight = new \IPS\nexus\Shipping\Weight( $item['weight']['kilograms'] );
$weightInOz += ( $weight->float('oz') * $item['quantity'] );
foreach ( array( 'length', 'width', 'height' ) as $k )
{
$dim = new \IPS\nexus\Shipping\Length( $item[ $k ]['metres'] );
$v = "{$k}InInches";
$$v += ( $dim->float('in') * $item['quantity'] );
}
}
/* Method */
$form->add( new \IPS\Helpers\Form\Radio( 'shipment_ship_method', 'easypost', TRUE, array(
'options' => array( 'easypost' => 'shipment_ship_easypost', 'manual' => 'shipment_ship_manual' ),
'toggles' => array(
'easypost' => array( 'form_header_easypost_package_header', 'easypost_package', 'easypost_package_weight', 'form_header_easypost_customs_header', 'easypost_customs_details' ),
'manual' => array( 'o_tracknumber', 'tracking_url' )
)
) ) );
/* Parcel */
$form->addHeader( 'easypost_package_header' );
$form->add( new \IPS\Helpers\Form\Select( 'easypost_package', 'custom', NULL, array(
'options' => array(
'custom' => 'easypost_package_custom',
'easypost_package_usps' => array(
'Card' => 'easypost_package_usps_Card',
'Letter' => 'easypost_package_usps_Letter',
'Flat' => 'easypost_package_usps_Flat',
'Parcel' => 'easypost_package_usps_Parcel',
'LargeParcel' => 'easypost_package_usps_LargeParcel',
'IrregularParcel' => 'easypost_package_usps_IrregularParcel',
'FlatRateEnvelope' => 'easypost_package_usps_FlatRateEnvelope',
'FlatRateLegalEnvelope' => 'easypost_package_usps_FlatRateLegalEnvelope',
'FlatRatePaddedEnvelope' => 'easypost_package_usps_FlatRatePaddedEnvelope',
'FlatRateGiftCardEnvelope' => 'easypost_package_usps_FlatRateGiftCardEnvelope',
'FlatRateWindowEnvelope' => 'easypost_package_usps_FlatRateWindowEnvelope',
'FlatRateCardboardEnvelope' => 'easypost_package_usps_FlatRateCardboardEnvelope',
'SmallFlatRateEnvelope' => 'easypost_package_usps_SmallFlatRateEnvelope',
'SmallFlatRateBox' => 'easypost_package_usps_SmallFlatRateBox',
'MediumFlatRateBox' => 'easypost_package_usps_MediumFlatRateBox',
'LargeFlatRateBox' => 'easypost_package_usps_LargeFlatRateBox',
'RegionalRateBoxA' => 'easypost_package_usps_RegionalRateBoxA',
'RegionalRateBoxB' => 'easypost_package_usps_RegionalRateBoxB',
'RegionalRateBoxC' => 'easypost_package_usps_RegionalRateBoxC',
'LargeFlatRateBoardGameBox' => 'easypost_package_usps_LargeFlatRateBoardGameBox',
),
'easypost_package_ups' => array(
'UPSLetter' => 'easypost_package_ups_UPSLetter',
'UPSExpressBox' => 'easypost_package_ups_UPSExpressBox',
'UPS25kgBox' => 'easypost_package_ups_UPS25kgBox',
'UPS10kgBox' => 'easypost_package_ups_UPS10kgBox',
'Tube' => 'easypost_package_ups_Tube',
'Pak' => 'easypost_package_ups_Pak',
'Pallet' => 'easypost_package_ups_Pallet',
'SmallExpressBox' => 'easypost_package_ups_SmallExpressBox',
'MediumExpressBox' => 'easypost_package_ups_MediumExpressBox',
'LargeExpressBox' => 'easypost_package_ups_LargeExpressBox',
),
'easypost_package_fedex' => array(
'FedExEnvelope' => 'easypost_package_fedex_FedExEnvelope',
'FedExBox' => 'easypost_package_fedex_FedExBox',
'FedExPak' => 'easypost_package_fedex_FedExPak',
'FedExTube' => 'easypost_package_fedex_FedExTube',
'FedEx10kgBox' => 'easypost_package_fedex_FedEx10kgBox',
'FedEx25kgBox' => 'easypost_package_fedex_FedEx25kgBox',
),
),
'toggles' => array(
'custom' => array( 'easypost_package_length', 'easypost_package_width', 'easypost_package_height' )
)
), NULL, NULL, NULL, 'easypost_package' ) );
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_length', $lengthInInches, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
{
throw new \DomainException('form_required');
}
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_length' ) );
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_width', $widthInInches, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
{
throw new \DomainException('form_required');
}
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_width' ) );
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_height', $heightInInches, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
{
throw new \DomainException('form_required');
}
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_height' ) );
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_weight', $weightInOz, NULL, array( 'decimals' => 1 ), function( $val )
{
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' )
{
throw new \DomainException('form_required');
}
}, NULL, 'oz', 'easypost_package_weight' ) );
$matrix = NULL;
$fromCountry = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address )->country;
if ( $fromCountry != $shipment->data['address']['country'] )
{
$originCountries = array();
foreach ( \IPS\GeoLocation::$countries as $code )
{
$originCountries[ $code ] = 'country-' . $code;
}
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->columns = array(
'epc_description' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Text( $key, $value, TRUE );
},
'epc_quantity' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Number( $key, $value ?: 1, TRUE );
},
'epc_value' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Number( $key, $value ?: 0, TRUE, array( 'decimals' => TRUE ) );
},
'epc_weight' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Text( $key, $value ?: 0, TRUE, array( 'decimals' => 1 ) );
},
'epc_origin' => function( $key, $value, $data ) use ( $originCountries, $fromCountry )
{
return new \IPS\Helpers\Form\Select( $key, $value ?: $fromCountry, FALSE, array( 'options' => $originCountries ) );
},
'epc_hs_tarrif' => function( $key, $value, $data )
{
return new \IPS\Helpers\Form\Text( $key, $value, FALSE, array( 'maxLength' => 6, 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('optional') ) );
},
);
foreach ( $shipment->items as $item )
{
$weight = new \IPS\nexus\Shipping\Weight( $item['weight']['kilograms'] );
$matrix->rows[] = array(
'epc_description' => $item['name'],
'epc_quantity' => $item['quantity'],
'epc_value' => $item['price']['currency'] === 'USD' ? $item['price']['amount'] : 0,
'epc_weight' => round( $weight->float('oz'), 1 )
);
}
$form->addHeader( 'easypost_customs_header' );
$form->addMatrix( 'easypost_customs_details', $matrix );
}
}
$form->add( new \IPS\Helpers\Form\Text( 'o_tracknumber', NULL, FALSE, array( 'maxLength' => 255 ), NULL, NULL, NULL, 'o_tracknumber' ) );
$form->add( new \IPS\Helpers\Form\Url( 'tracking_url', NULL, FALSE, array( 'maxLength' => 255 ), NULL, NULL, NULL, 'tracking_url' ) );
/* Handle Submissions */
if ( $values = $form->values() )
{
/* EasyPost */
if ( isset( $values['shipment_ship_method'] ) AND $values['shipment_ship_method'] === 'easypost' )
{
try
{
/* Parcel Data */
if ( $values['easypost_package'] === 'custom' )
{
$parcelData = array(
'length' => $values['easypost_package_length'],
'width' => $values['easypost_package_width'],
'height' => $values['easypost_package_height'],
);
}
else
{
$parcelData = array( 'predefined_package' => $values['easypost_package'] );
}
$parcelData['weight'] = $values['easypost_package_weight'];
/* Customs Info */
$customsInfo = NULL;
if ( isset( $values['easypost_customs_details'] ) )
{
$customItems = array();
$totalValue = 0;
foreach ( $values['easypost_customs_details'] as $customItem )
{
if ( $customItem['epc_description'] )
{
$totalValue += $customItem['epc_value'];
$customItems[] = array(
'description' => $customItem['epc_description'],
'quantity' => $customItem['epc_quantity'],
'value' => $customItem['epc_value'],
'weight' => $customItem['epc_weight'],
'hs_tariff_number' => $customItem['epc_hs_tarrif'],
'origin_country' => $customItem['epc_origin'],
);
}
}
$customsInfo = array(
'eel_pfc' => ( $totalValue < 2500 ) ? 'NOEEI 30.37(a)' : '',
'contents_type' => 'merchandise',
'customs_items' => $customItems
);
}
/* Send API call */
$toAddress = $shipment->data['address'];
$fromAddress = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address );
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments' )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->post( array( 'shipment' => array(
'to_address' => array(
'street1' => array_shift( $toAddress['addressLines'] ),
'street2' => count( $toAddress['addressLines'] ) ? implode( ', ', $toAddress['addressLines'] ) : NULL,
'city' => $toAddress['city'],
'state' => $toAddress['region'],
'zip' => $toAddress['postalCode'],
'country' => $toAddress['country'],
'name' => $shipment->data['cm_first_name'] . ' ' . $shipment->data['cm_last_name'],
'phone' => $shipment->data['cm_phone'],
'email' => $shipment->invoice->member->email
),
'from_address' => array(
'street1' => array_shift( $fromAddress->addressLines ),
'street2' => count( $fromAddress->addressLines ) ? implode( ', ', $fromAddress->addressLines ) : NULL,
'city' => $fromAddress->city,
'state' => $fromAddress->region,
'zip' => $fromAddress->postalCode,
'country' => $fromAddress->country,
'company' => \IPS\Settings::i()->board_name,
'phone' => \IPS\Settings::i()->easypost_phone,
'email' => \IPS\Settings::i()->email_in
),
'parcel' => $parcelData,
'customs_info' => $customsInfo
) ) )->decodeJson();
if ( !count( $easyPost['rates'] ) )
{
\IPS\Output::i()->error( 'err_no_easypost', '1X193/6', 403, '' );
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=payments&controller=shipping&do=easypost&id={$easyPost['id']}&shipment={$shipment->id}" ) );
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Output::i()->error( 'err_err_easypost', '3X193/7', 500, '', array(), $e->getMessage() );
}
}
/* Manual */
else
{
$shipment->status = \IPS\nexus\Shipping\Order::STATUS_SHIPPED;
$shipment->shipped_date = new \IPS\DateTime;
if ( $values['o_tracknumber'] )
{
$shipment->tracknumber = $values['o_tracknumber'];
}
if ( $values['tracking_url'] )
{
$shipment->service = $values['tracking_url'];
}
$shipment->save();
$shipment->sendNotification();
}
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id ) );
$this->_redirect( $shipment );
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
\IPS\Output::i()->output = $form;
}
/**
* EasyPost
*
* @return void
*/
public function easypost()
{
/* Get Data */
try
{
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . \IPS\Request::i()->id )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->get()->decodeJson();
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->shipment );
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'err_err_easypost', '3X193/8', 500, '', array(), $e->getMessage() );
}
/* Gigure out our options */
$selected = NULL;
$options = array();
$descriptions = array();
foreach ( $easyPost['rates'] as $rate )
{
if ( $rate['service'] === $shipment->api_service )
{
$selected = $rate['id'];
}
$service = '';
for ( $i=0; $i<\strlen( $rate['service'] ); $i++ )
{
if ( \strtoupper( $rate['service'][ $i ] ) === $rate['service'][ $i ] )
{
$service .= " {$rate['service'][ $i ]}";
}
else
{
$service .= $rate['service'][ $i ];
}
}
$options[ $rate['id'] ] = $rate['carrier'] . $service . ' - ' . new \IPS\nexus\Money( $rate['rate'], $rate['currency'] );
if ( $rate['est_delivery_days'] )
{
$descriptions[ $rate['id'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'easypost_rates_desc', FALSE, array( 'sprintf' => array( $rate['est_delivery_days'] ) ) );
}
}
/* Build form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'easypost_rate', $selected, TRUE, array( 'options' => $options, 'descriptions' => $descriptions ) ) );
/* Handle submissions */
if ( $values = $form->values() )
{
try
{
$response = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . \IPS\Request::i()->id . '/buy' )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->post( array(
'rate' => array(
'id' => $values['easypost_rate']
)
) )->decodeJson();
if ( isset( $response['error'] ) )
{
\IPS\Output::i()->error( 'err_err_easypost', '3X193/9', 500, '', array(), $response['error'] );
}
$shipment->label = $response['postage_label']['label_url'];
$shipment->tracknumber = $response['tracking_code'];
$shipment->extra = json_encode( array( 'shipment' => $response['selected_rate']['shipment_id'], 'rate' => $response['selected_rate']['id'] ) );
$shipment->status = \IPS\nexus\Shipping\Order::STATUS_SHIPPED;
$shipment->shipped_date = new \IPS\DateTime;
$shipment->save();
$shipment->sendNotification();
\IPS\Output::i()->redirect( $shipment->acpUrl() );
}
catch ( \IPS\Http\Request\Exception $e )
{
\IPS\Output::i()->error( 'err_err_easypost', '3X193/A', 500, '', array(), $e->getMessage() );
}
}
/* How much did the customer pay for shipping? */
$invoiceSummary = $shipment->invoice->summary();
$otherShipments = count( $shipment->invoice->shipments() ) - 1;
$message = $otherShipments ? \IPS\Member::loggedIn()->language()->addToStack( 'shipment_cost_others', FALSE, array( 'sprintf' => array( $invoiceSummary['shippingTotal'], $shipment->invoice->id, $otherShipments ) ) ) : \IPS\Member::loggedIn()->language()->addToStack( 'shipment_cost_noothers', FALSE, array( 'sprintf' => array( $invoiceSummary['shippingTotal'] ) ) );
\IPS\Member::loggedIn()->language()->words['easypost_rate_desc'] = $message;
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
\IPS\Output::i()->output = $form;
}
/**
* Cancel
*
* @return void
*/
public function cancel()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
/* Load */
try
{
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X193/4', 404, '' );
}
/* Cancel */
$shipment->status = $shipment::STATUS_CANCELED;
$shipment->save();
/* Log */
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'type' => 'canc' ) );
/* Redirect */
$this->_redirect( $shipment );
}
/**
* Delete
*
* @return void
*/
public function delete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_delete' );
/* Load */
try
{
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X193/5', 404, '' );
}
/* Delete */
$shipment->delete();
/* Log */
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'deleted' => TRUE ) );
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
}
/**
* Print
*
* @return void
*/
public function printout()
{
/* Load */
try
{
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X193/3', 404, '' );
}
$data = $shipment->data;
if ( \IPS\Request::i()->print === 'apilabel' )
{
\IPS\Output::i()->sendOutput( $shipment->label, 200, 'application/pdf' );
}
if ( \IPS\Request::i()->print === 'label' )
{
$output = \IPS\Theme::i()->getTemplate('shiporders')->packingLabel( $shipment );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'shipping.css', 'nexus' ) );
}
else
{
$output = \IPS\Theme::i()->getTemplate('shiporders')->packingSheet( $shipment );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'shipping.css', 'nexus' ) );
}
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->blankTemplate( $output ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
/**
* Redirect
*
* @param \IPS\nexus\Shipping\Order $shipment The shipment
* @return void
*/
protected function _redirect( \IPS\nexus\Shipping\Order $shipment )
{
if ( isset( \IPS\Request::i()->r ) )
{
switch ( \IPS\Request::i()->r )
{
case 'v':
\IPS\Output::i()->redirect( $shipment->acpUrl() );
break;
case 'i':
\IPS\Output::i()->redirect( $shipment->invoice->acpUrl() );
break;
case 'c':
\IPS\Output::i()->redirect( $shipment->member->acpUrl() );
break;
case 't':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
break;
}
}
\IPS\Output::i()->redirect( $transaction->acpUrl() );
}
}
@@ -0,0 +1,42 @@
<?php
/**
* @brief Shipping Rates
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 13 Feb 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Shipping
*/
class _shippingrates extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Shipping\FlatRate';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shipping_manage' );
parent::execute();
}
}
@@ -0,0 +1,42 @@
<?php
/**
* @brief Tax Classes
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 12 Feb 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* tax
*/
class _tax extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = 'IPS\nexus\Tax';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'tax_manage' );
parent::execute();
}
}
@@ -0,0 +1,448 @@
<?php
/**
* @brief Transactions
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 11 Feb 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\modules\admin\payments;
/* 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;
}
/**
* Transactions
*/
class _transactions extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'transaction.css', 'nexus', 'admin' ) );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
/* Create Table */
$table = \IPS\nexus\Transaction::table( array(), \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=transactions' ), 't' );
$table->filters = array(
'tstatus_hold' => array( 't_status=?', 'hold' ),
);
$table->advancedSearch = array(
't_id' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
't_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => \IPS\nexus\Transaction::statuses(), 'multiple' => TRUE ) ),
't_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
't_amount' => \IPS\Helpers\Table\SEARCH_NUMERIC,
't_method' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => '\IPS\nexus\Gateway' ) ),
't_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
);
$table->quickSearch = 't_id';
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_transactions');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
}
/**
* View
*
* @return void
*/
public function view()
{
/* Load Transaction */
try
{
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X186/8', 404, '' );
}
/* Output */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_number', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'transactions' )->view( $transaction );
}
/**
* Approve
*
* @return void
*/
public function approve()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
/* Load Transaction */
try
{
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X186/9', 404, '' );
}
$method = $transaction->method;
/* Can we approve it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/A', 403, '' );
}
/* Log it */
$transaction->member->log( 'transaction', array(
'type' => 'status',
'status' => \IPS\nexus\Transaction::STATUS_PAID,
'id' => $transaction->id
) );
/* Do it */
try
{
$transaction->capture();
$transaction->approve( \IPS\Member::loggedIn() );
}
catch ( \LogicException $e )
{
\IPS\Output::i()->error( $e->getMessage(), '3X186/2', 500, '' );
}
catch ( \RuntimeException $e )
{
\IPS\Output::i()->error( 'transaction_capture_err', '3X186/3', 500, '' );
}
/* Send Email */
$transaction->sendNotification();
/* Redirect */
$this->_redirect( $transaction );
}
/**
* Flag for review
*
* @return void
*/
public function review()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
/* Load Transaction */
try
{
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X186/C', 404, '' );
}
$method = $transaction->method;
/* Can we flag it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/B', 403, '' );
}
/* Set it */
$extra = $transaction->extra;
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REVIEW, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
$transaction->extra = $extra;
$transaction->status = \IPS\nexus\Transaction::STATUS_REVIEW;
$transaction->save();
/* Log it */
$transaction->member->log( 'transaction', array(
'type' => 'status',
'status' => \IPS\nexus\Transaction::STATUS_REVIEW,
'id' => $transaction->id
) );
/* Create a support request? */
if ( \IPS\Settings::i()->nexus_revw_sa != -1 )
{
$createUrl = \IPS\Http\Url::internal('app=nexus&module=support&controller=requests&do=create');
$key = md5( $createUrl );
if ( \IPS\Settings::i()->nexus_revw_sa )
{
$_SESSION["wizard-{$key}-data"] = array(
'member' => $transaction->member->member_id,
'stock_action' => \IPS\Settings::i()->nexus_revw_sa
);
$_SESSION["wizard-{$key}-step"] = 'request_details';
}
else
{
$_SESSION["wizard-{$key}-data"] = array(
'member' => $transaction->member->member_id,
);
if ( count( \IPS\nexus\Support\StockAction::roots() ) )
{
$_SESSION["wizard-{$key}-step"] = 'stock_action';
}
else
{
$_SESSION["wizard-{$key}-step"] = 'request_details';
}
}
$_SESSION["wizard-{$key}-data"]['transaction'] = $transaction->id;
$_SESSION["wizard-{$key}-data"]['ref'] = isset( \IPS\Request::i()->r ) ? \IPS\Request::i()->r : 'v';
\IPS\Output::i()->redirect( $createUrl );
}
/* Redirect */
$this->_redirect( $transaction );
}
/**
* Void
*
* @return void
*/
public function void()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
/* Load Transaction */
try
{
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X186/4', 404, '' );
}
$method = $transaction->method;
/* Can we void it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \IPS\nexus\Transaction::STATUS_WAITING ) ) and ( !$transaction->auth or !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW ) ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/5', 403, '' );
}
/* Void it */
try
{
$transaction->method->void( $transaction );
}
catch ( \Exception $e )
{
if ( !isset( \IPS\Request::i()->override ) )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'transaction_void_err', FALSE, array( 'sprintf' => array( $transaction->acpUrl()->setQueryString( array( 'do' => 'void', 'override' => 1 ) ) ) ) ), '3X186/6', 500, '', array(), $e->getMessage() );
}
}
$extra = $transaction->extra;
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
$transaction->extra = $extra;
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
$transaction->save();
/* Log it */
$transaction->member->log( 'transaction', array(
'type' => 'status',
'status' => \IPS\nexus\Transaction::STATUS_REFUSED,
'id' => $transaction->id
) );
/* Send Email */
$transaction->sendNotification();
/* Redirect */
$this->_redirect( $transaction );
}
/**
* Refund
*
* @return void
*/
public function refund()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_refund' );
/* Load Transaction */
try
{
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X186/D', 404, '' );
}
$method = $transaction->method;
/* Can we refund it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_PART_REFUNDED ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/E', 403, '' );
}
/* What are the refund methods? */
$refundMethods = array();
$refundMethodToggles = array( 'credit' => array( 'refund_amount' ) );
if ( $method and $method::SUPPORTS_REFUNDS )
{
$refundMethods['gateway'] = $method->_title;
if ( $method::SUPPORTS_PARTIAL_REFUNDS )
{
$refundMethodToggles['gateway'] = array( 'refund_amount' );
}
}
$refundMethods['credit'] = 'refund_method_credit';
$refundMethods['none'] = 'refund_method_none';
/* Build form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'refund_method', ( $method and $method::SUPPORTS_REFUNDS ) ? 'gateway' : 'credit', TRUE, array( 'options' => $refundMethods, 'toggles' => $refundMethodToggles ) ) );
$form->add( new \IPS\Helpers\Form\Number( 'refund_amount', ( $transaction->status === \IPS\nexus\Transaction::STATUS_PART_REFUNDED ? $transaction->amount->amount - $transaction->partial_refund->amount : 0 ), TRUE, array( 'unlimited' => 0, 'unlimitedLang' => \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) ), 'max' => ( $transaction->amount->amount - $transaction->partial_refund->amount ), 'decimals' => TRUE ), NULL, NULL, $transaction->amount->currency, 'refund_amount' ) );
if ( $transaction->invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
{
$field = new \IPS\Helpers\Form\Radio( 'refund_invoice_status', \IPS\nexus\Invoice::STATUS_PENDING, TRUE, array(
'options' => array(
\IPS\nexus\Invoice::STATUS_PAID => 'refund_invoice_paid',
\IPS\nexus\Invoice::STATUS_PENDING => 'refund_invoice_pending',
\IPS\nexus\Invoice::STATUS_CANCELED => 'refund_invoice_canceled',
),
'toggles' => array(
\IPS\nexus\Invoice::STATUS_PENDING => array( 'form_refund_invoice_status_warning' ),
\IPS\nexus\Invoice::STATUS_CANCELED => array( 'form_refund_invoice_status_warning' )
)
) );
$field->warningBox = \IPS\Theme::i()->getTemplate('invoices')->unpaidConsequences( $transaction->invoice );
$form->add( $field );
}
/* Handle submissions */
if ( $values = $form->values() )
{
/* Refund */
try
{
$transaction->refund( $values['refund_method'], $values['refund_amount'] );
}
catch ( \LogicException $e )
{
\IPS\Output::i()->error( $e->getMessage(), '1X186/1', 500, '' );
}
catch ( \RuntimeException $e )
{
\IPS\Output::i()->error( 'refund_failed', '3X186/7', 500, '' );
}
/* Handle invoice */
if ( isset( $values['refund_invoice_status'] ) and $values['refund_invoice_status'] !== \IPS\nexus\Invoice::STATUS_PAID )
{
$transaction->invoice->markUnpaid( $values['refund_invoice_status'] );
$transaction->invoice->member->log( 'invoice', array(
'type' => 'status',
'new' => $values['refund_invoice_status'],
'id' => $transaction->invoice->id,
'title' => $transaction->invoice->title
) );
}
/* Send Email */
$transaction->sendNotification();
/* Redirect */
$this->_redirect( $transaction );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_refund_title', FALSE, array( 'sprintf' => array( $transaction->amount ) ) );
\IPS\Output::i()->output = $form;
}
/**
* Delete
*
* @return void
*/
public function delete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_delete' );
/* Load Transaction */
try
{
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X186/F', 404, '' );
}
/* Delete */
$transaction->delete();
/* Log it */
$transaction->member->log( 'transaction', array(
'type' => 'delete',
'id' => $transaction->id,
'method' => $transaction->method->id
) );
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );
}
/**
* Redirect
*
* @param \IPS\nexus\Transaction $transaction The transaction
* @return void
*/
protected function _redirect( \IPS\nexus\Transaction $transaction )
{
if ( isset( \IPS\Request::i()->r ) )
{
switch ( \IPS\Request::i()->r )
{
case 'v':
\IPS\Output::i()->redirect( $transaction->acpUrl() );
break;
case 'i':
\IPS\Output::i()->redirect( $transaction->invoice->acpUrl() );
break;
case 'c':
\IPS\Output::i()->redirect( $transaction->member->acpUrl() );
break;
case 't':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );
break;
}
}
\IPS\Output::i()->redirect( $transaction->acpUrl() );
}
}