Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _billingagreements extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -79,7 +84,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
$transactions->limit = 50;
foreach ( $transactions->include as $k => $v )
{
if ( in_array( $v, array( 't_method', 't_member' ) ) )
if ( \in_array( $v, array( 't_method', 't_member' ) ) )
{
unset( $transactions->include[ $k ] );
}
@@ -94,7 +99,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
\IPS\Output::i()->sidebar['actions']['suspend'] = array(
'icon' => 'times',
'title' => 'billing_agreement_suspend',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'suspend' ) ),
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'suspend' ) )->csrf(),
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('billing_agreement_suspend_confirm') )
);
}
@@ -103,7 +108,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
\IPS\Output::i()->sidebar['actions']['reactivate'] = array(
'icon' => 'check',
'title' => 'billing_agreement_reactivate',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'reactivate' ) ),
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'reactivate' ) )->csrf(),
'data' => array( 'confirm' => '' )
);
}
@@ -112,13 +117,13 @@ class _billingagreements extends \IPS\Dispatcher\Controller
\IPS\Output::i()->sidebar['actions']['cancel'] = array(
'icon' => 'times-circle',
'title' => 'billing_agreement_cancel',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'cancel' ) ),
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'cancel' ) )->csrf(),
);
}
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'billing_agreement_id', FALSE, array( 'sprintf' => array( $billingAgreement->id ) ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'billing_agreement_id', FALSE, array( 'sprintf' => array( $billingAgreement->gw_id ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'billingagreements' )->view( $billingAgreement, $purchases, $transactions );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
@@ -138,6 +143,8 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*/
public function reconcile()
{
\IPS\Session::i()->csrfCheck();
/* Load */
try
{
@@ -173,9 +180,11 @@ class _billingagreements extends \IPS\Dispatcher\Controller
*/
public function act()
{
\IPS\Session::i()->csrfCheck();
/* Check act */
$act = \IPS\Request::i()->act;
if ( !in_array( $act, array( 'suspend', 'reactivate', 'cancel' ) ) )
if ( !\in_array( $act, array( 'suspend', 'reactivate', 'cancel' ) ) )
{
\IPS\Output::i()->error( 'node_error', '3X320/8', 403, '' );
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _checkoutsettings extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -43,7 +48,7 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
{
$requireBillingOptions = array();
$requireBillingOptions['product'] = 'nexus_require_billing_package';
if ( ( $giftVouchers = json_decode( \IPS\Settings::i()->nexus_gift_vouchers, TRUE ) and count( $giftVouchers ) ) or \IPS\Settings::i()->nexus_gift_vouchers_free )
if ( ( $giftVouchers = json_decode( \IPS\Settings::i()->nexus_gift_vouchers, TRUE ) and \count( $giftVouchers ) ) or \IPS\Settings::i()->nexus_gift_vouchers_free )
{
$requireBillingOptions['giftvoucher'] = 'nexus_require_billing_gift';
}
@@ -51,7 +56,7 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
{
$requireBillingOptions['donation'] = 'nexus_require_billing_donation';
}
if ( \IPS\Settings::i()->nexus_enom_un and $domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE ) and count( $domainPrices ) )
if ( \IPS\Settings::i()->nexus_enom_un and $domainPrices = json_decode( \IPS\Settings::i()->nexus_domain_prices, TRUE ) and \count( $domainPrices ) )
{
$requireBillingOptions['domain'] = 'nexus_require_billing_domain';
}
@@ -86,7 +91,8 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
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;
$values['nexus_require_billing'] = count( $values['nexus_require_billing'] ) ? implode( ',', $values['nexus_require_billing'] ) : 'none';
unset( $values['nexus_split_payments_on'] );
$values['nexus_require_billing'] = \count( $values['nexus_require_billing'] ) ? implode( ',', $values['nexus_require_billing'] ) : 'none';
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__checkout_settings' );
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _currencies extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -53,7 +58,7 @@ class _currencies extends \IPS\Dispatcher\Controller
},
'default' => function( $key, $value, $data ) use ( $languages )
{
if ( count( $languages ) === 1 )
if ( \count( $languages ) === 1 )
{
return new \IPS\Helpers\Form\Checkbox( $key, $value );
}
@@ -80,7 +85,7 @@ class _currencies extends \IPS\Dispatcher\Controller
'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', 'BYN', 'BYR', 'BZD', 'CAD', 'CDF', 'CHF', 'CLF', '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' ) ) )
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', 'BYN', 'BYR', 'BZD', 'CAD', 'CDF', 'CHF', 'CLF', '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' );
}
@@ -90,26 +95,35 @@ class _currencies extends \IPS\Dispatcher\Controller
{
$matrix->rows[] = array(
'code' => \IPS\Settings::i()->nexus_currency,
'default' => count( $languages ) === 1 ? TRUE : array_keys( $languages )
'default' => \count( $languages ) === 1 ? TRUE : array_keys( $languages )
);
}
if ( $values = $matrix->values() )
{
$save = array();
$definition = \IPS\Db::i()->getTableDefinition( 'nexus_package_base_prices' );
foreach ( $values as $data )
{
if ( $data['code'] )
{
$save[ $data['code'] ] = ( count( $languages ) === 1 ) ? ( $data['default'] ? array_keys( $languages ) : array() ) : $data['default'];
$save[ $data['code'] ] = ( \count( $languages ) === 1 ) ? ( $data['default'] ? array_keys( $languages ) : array() ) : $data['default'];
/* Add the column if it doesn't exist */
if ( !isset( $definition['columns'][ $data['code'] ] ) )
{
\IPS\Db::i()->addColumn( 'nexus_package_base_prices', array(
'name' => $data['code'],
'type' => 'FLOAT'
) );
}
}
}
\IPS\Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $save ) ) );
$definition = \IPS\Db::i()->getTableDefinition( 'nexus_package_base_prices' );
foreach ( $definition['columns'] AS $key => $value )
{
if ( $key === 'id' )
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _donationgoals extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _donations extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _emails extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -30,7 +35,7 @@ class _emails extends \IPS\Dispatcher\Controller
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'email_copies_setting' );
\IPS\Dispatcher::i()->checkAcpPermission( 'email_copies_settings' );
parent::execute();
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _fraud extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _gateways extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
@@ -78,22 +83,20 @@ class _gateways extends \IPS\Node\Controller
{
\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(
\IPS\Output::i()->output = (string) new \IPS\Helpers\Wizard( array(
'gateways_gateway' => function( $data )
{
$options = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway' ) as $file )
foreach ( \IPS\nexus\Gateway::gateways() as $key => $class )
{
if ( $file->isDir() and !$file->isDot() )
/* Deprecate Authorize.net, don't allow it to be used for new gateways */
if( $key === 'AuthorizeNet' )
{
if ( ( (string) $file === 'Test' and !\IPS\NEXUS_TEST_GATEWAYS ) or (string) $file === 'SagePay' )
{
continue;
}
$options[ (string) $file ] = 'gateway__' . $file;
continue;
}
$options[ $key ] = 'gateway__' . $key;
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Radio( 'gateways_gateway', TRUE, NULL, array( 'options' => $options ) ) );
if ( $values = $form->values() )
@@ -105,19 +108,18 @@ class _gateways extends \IPS\Node\Controller
'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'];
$class = \IPS\nexus\Gateway::gateways()[ $data['gateway'] ];
$obj = new $class;
$obj->gateway = $data['gateway'];
$obj->active = TRUE;
$obj->settings( $form );
$obj->form( $form );
if ( $values = $form->values() )
{
$settings = array();
foreach ( $values as $k => $v )
{
if ( $k !== 'paymethod_name' )
if ( $k !== 'paymethod_name' AND $k !== 'paymethod_countries' )
{
$settings[ mb_substr( $k, mb_strlen( $data['gateway'] ) + 1 ) ] = $v;
}
@@ -131,11 +133,13 @@ class _gateways extends \IPS\Node\Controller
$form->error = $e->getMessage();
return $form;
}
$obj->settings = json_encode( $settings );
$obj->save();
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $values['paymethod_name'] );
$name = $values['paymethod_name'];
$values = $obj->formatFormValues( $values );
$obj->settings = json_encode( $settings );
$obj->countries = $values['countries'];
$obj->save();
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $name );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways') );
}
@@ -144,4 +148,48 @@ class _gateways extends \IPS\Node\Controller
), \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways&do=form') );
}
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
/* Get node */
$nodeClass = $this->nodeClass;
if ( \IPS\Request::i()->subnode )
{
$nodeClass = $nodeClass::$subnodeClass;
}
try
{
$node = $nodeClass::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X411/1', 404, '' );
}
/* Permission check */
if( !$node->canDelete() )
{
\IPS\Output::i()->error( 'node_noperm_delete', '2X411/2', 403, '' );
}
if( $node->hasActiveBillingAgreements() )
{
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
\IPS\Task::queue( 'nexus', 'DeletePaymentMethod', array( 'id' => $node->id ), 3, array( 'id' ) );
\IPS\Session::i()->log( 'acplog__node_deleted_c', array( $this->title => TRUE, $node->titleForLog() => FALSE ) );
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'root' => ( $node->parent() ? $node->parent()->_id : '' ) ) ), 'deleted' );
}
else
{
return parent::delete();
}
}
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _invoiceTimeline extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Manage
*
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -22,7 +22,12 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
* Invoices
*/
class _invoices extends \IPS\Dispatcher\Controller
{
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -66,6 +71,12 @@ class _invoices extends \IPS\Dispatcher\Controller
'i_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
);
$table->quickSearch = 'i_id';
$table->filters = array(
'istatus_paid' => array( 'i_status=?', \IPS\nexus\Invoice::STATUS_PAID ),
'istatus_pend' => array( 'i_status=?', \IPS\nexus\Invoice::STATUS_PENDING ),
'istatus_expd' => array( 'i_status=?', \IPS\nexus\Invoice::STATUS_EXPIRED ),
'istatus_canc' => array( 'i_status=?' , \IPS\nexus\Invoice::STATUS_CANCELED )
);
$table->mainColumn = 'i_title';
if ( $customer )
{
@@ -130,7 +141,7 @@ class _invoices extends \IPS\Dispatcher\Controller
foreach ( $transactions->include as $k => $v )
{
if ( in_array( $v, array( 't_member', 't_invoice' ) ) )
if ( \in_array( $v, array( 't_member', 't_invoice' ) ) )
{
unset( $transactions->include[ $k ] );
}
@@ -205,7 +216,8 @@ class _invoices extends \IPS\Dispatcher\Controller
public function paid()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_edit' );
\IPS\Session::i()->csrfCheck();
/* Load Invoice */
try
{
@@ -216,14 +228,20 @@ class _invoices extends \IPS\Dispatcher\Controller
\IPS\Output::i()->error( 'node_error', '2X190/6', 404, '' );
}
/* Do we have a billing address? */
if ( !$invoice->billaddress AND $invoice->hasItemsRequiringBillingAddress() )
{
\IPS\Output::i()->error( 'err_no_billaddress', '2X190/I', 403 );
}
/* Any pending transactions? */
if ( !isset( \IPS\Request::i()->override ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) )
{
$pendingTransactions = $invoice->transactions( array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ) );
if ( count( $pendingTransactions ) )
if ( \count( $pendingTransactions ) )
{
$transUrl = $invoice->acpUrl();
if ( count( $pendingTransactions ) === 1 )
if ( \count( $pendingTransactions ) === 1 )
{
foreach ( $pendingTransactions as $transaction )
{
@@ -233,7 +251,7 @@ class _invoices extends \IPS\Dispatcher\Controller
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global', 'core')->decision( 'invoice_paid_trans', array(
'invoice_paid_trans_view' => $transUrl,
'invoice_paid_trans_ovrd' => $invoice->acpUrl()->setQueryString( array( 'do' => 'paid', 'override' => 1 ) )
'invoice_paid_trans_ovrd' => $invoice->acpUrl()->setQueryString( array( 'do' => 'paid', 'override' => 1 ) )->csrf()
) );
return;
}
@@ -248,7 +266,7 @@ class _invoices extends \IPS\Dispatcher\Controller
) );
/* Send Email */
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceMarkedPaid', array( $invoice, $invoice->summary() ), \IPS\Email::TYPE_TRANSACTIONAL )
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceMarkedPaid', array( $invoice, $invoice->summary( $invoice->member->language() ) ), \IPS\Email::TYPE_TRANSACTIONAL )
->send(
$invoice->member,
array_map(
@@ -258,7 +276,7 @@ class _invoices extends \IPS\Dispatcher\Controller
},
iterator_to_array( $invoice->member->alternativeContacts( array( 'billing=1' ) ) )
),
( ( in_array( 'new_invoice', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
( ( \in_array( 'new_invoice', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
);
/* Do it */
@@ -289,10 +307,10 @@ class _invoices extends \IPS\Dispatcher\Controller
}
/* Get gateways */
$gateways = \IPS\nexus\Gateway::manualChargeGateways();
$gateways = \IPS\nexus\Gateway::manualChargeGateways( $invoice->member );
/* Can we do this? */
if ( $invoice->status !== \IPS\nexus\Invoice::STATUS_PENDING or !count( $gateways ) )
if ( $invoice->status !== \IPS\nexus\Invoice::STATUS_PENDING or !\count( $gateways ) )
{
\IPS\Output::i()->error( 'invoice_status_err', '2X190/9', 403, '' );
}
@@ -300,7 +318,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$self = $this;
/* Wizard */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'invoice_charge_to_card' );
\IPS\Output::i()->output = new \IPS\Helpers\Wizard(
\IPS\Output::i()->output = (string) new \IPS\Helpers\Wizard(
array(
't_amount' => function( $data ) use ( $invoice )
{
@@ -322,7 +340,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$paymentMethodsToggles = array();
foreach ( $gateways as $gateway )
{
foreach ( $gateway->paymentScreen( $invoice, $amountToPay, $invoice->member ) as $element )
foreach ( $gateway->paymentScreen( $invoice, $amountToPay, $invoice->member, array(), 'admin' ) as $element )
{
if ( !$element->htmlId )
{
@@ -340,7 +358,23 @@ class _invoices extends \IPS\Dispatcher\Controller
/* Build form */
$form = new \IPS\Helpers\Form( 'charge', 'invoice_charge_to_card' );
if ( count( $gateways ) > 1 )
if ( isset( \IPS\Request::i()->previousTransactions ) )
{
$form->hiddenValues['previousTransactions'] = \IPS\Request::i()->previousTransactions;
}
else
{
if ( $previousTransactions = $invoice->transactions() and \count( $previousTransactions ) )
{
$previousTransactionIds = array();
foreach ( $previousTransactions as $previousTransaction )
{
$previousTransactionIds[] = $previousTransaction->id;
}
$form->hiddenValues['previousTransactions'] = implode( ',', $previousTransactionIds );
}
}
if ( \count( $gateways ) > 1 )
{
$form->add( new \IPS\Helpers\Form\Radio( 'payment_method', NULL, TRUE, array( 'options' => $paymentMethodOptions, 'toggles' => $paymentMethodsToggles ) ) );
}
@@ -352,7 +386,7 @@ class _invoices extends \IPS\Dispatcher\Controller
/* Handle submissions */
if ( $values = $form->values() )
{
if ( count( $gateways ) === 1 )
if ( \count( $gateways ) === 1 )
{
$gateway = array_pop( $gateways );
}
@@ -372,7 +406,15 @@ class _invoices extends \IPS\Dispatcher\Controller
try
{
$transaction->auth = $gateway->auth( $transaction, $values );
$auth = $gateway->auth( $transaction, $values, NULL, array(), 'manual' );
if ( \is_array( $auth ) )
{
return $this->_webhookRedirector( $invoice, $auth );
}
else
{
$transaction->auth = $auth;
}
$transaction->capture();
$transaction->member->log( 'transaction', array(
@@ -482,6 +524,7 @@ class _invoices extends \IPS\Dispatcher\Controller
public function resend()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_resend' );
\IPS\Session::i()->csrfCheck();
/* Load Invoice */
try
@@ -529,24 +572,9 @@ class _invoices extends \IPS\Dispatcher\Controller
{
\IPS\Output::i()->error( 'node_error', '2X190/D', 404, '' );
}
/* Get the address */
$address = NULL;
if ( $invoice->billaddress )
{
$address = $invoice->billaddress;
}
else
{
try
{
$address = \IPS\nexus\Customer\Address::constructFromData( \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( "member=? AND primary_billing=?", $invoice->member->member_id, 1 ) )->first() )->address;
}
catch( \UnderflowException $e ) {}
}
/* Get output */
$output = \IPS\Theme::i()->getTemplate( 'invoices', 'nexus', 'global' )->printInvoice( $invoice, $invoice->summary(), $address );
$output = \IPS\Theme::i()->getTemplate( 'invoices', 'nexus', 'global' )->printInvoice( $invoice, $invoice->summary(), $invoice->billaddress ?: $invoice->member->primaryBillingAddress() );
\IPS\Output::i()->title = 'I' . $invoice->id;
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->blankTemplate( $output ) );
}
@@ -608,12 +636,12 @@ class _invoices extends \IPS\Dispatcher\Controller
/* How do we want to refund? */
$field = new \IPS\Helpers\Form\Radio( $transaction->id . '_refund_method', 'none', TRUE, array( 'options' => $refundMethods, 'toggles' => $refundMethodToggles ) );
$field->label = count( $transactions ) === 1 ? \IPS\Member::loggedIn()->language()->addToStack( 'refund_method' ) : \IPS\Member::loggedIn()->language()->addToStack( 'trans_refund_method', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
$field->label = \count( $transactions ) === 1 ? \IPS\Member::loggedIn()->language()->addToStack( 'refund_method' ) : \IPS\Member::loggedIn()->language()->addToStack( 'trans_refund_method', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
$form->add( $field );
if ( $refundReasons )
{
$field = new \IPS\Helpers\Form\Radio( $transaction->id . '_refund_reason', NULL, FALSE, array( 'options' => $refundReasons ), NULL, NULL, NULL, $transaction->id . '_refund_reason' );
$field->label = count( $transactions ) === 1 ? \IPS\Member::loggedIn()->language()->addToStack( 'refund_reason' ) : \IPS\Member::loggedIn()->language()->addToStack( 'trans_refund_reason', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
$field->label = \count( $transactions ) === 1 ? \IPS\Member::loggedIn()->language()->addToStack( 'refund_reason' ) : \IPS\Member::loggedIn()->language()->addToStack( 'trans_refund_reason', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
$form->add( $field );
}
@@ -678,7 +706,7 @@ class _invoices extends \IPS\Dispatcher\Controller
}
/* Billing Agreement? */
if ( $billingAgreement = $transaction->billing_agreement )
if ( $billingAgreement = $transaction->billing_agreement AND $billingAgreement->status() !== $billingAgreement::STATUS_CANCELED )
{
$field = new \IPS\Helpers\Form\YesNo( $transaction->id . '_refund_cancel_billing_agreement', TRUE, NULL, array( 'togglesOff' => array( "form_{$transaction->id}_refund_cancel_billing_agreement_warning" ) ) );
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'refund_cancel_billing_agreement' );
@@ -922,7 +950,7 @@ class _invoices extends \IPS\Dispatcher\Controller
/* Select Customer */
$steps = array();
if ( !isset( \IPS\Request::i()->member ) and !$invoice )
if ( !isset( \IPS\Request::i()->member ) and ( !$invoice or !$invoice->member->member_id ) )
{
$steps['invoice_generate_member'] = function( $data )
{
@@ -945,7 +973,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$form->addHeader( 'invoice_settings' );
$currencies = \IPS\nexus\Money::currencies();
if ( count( $currencies ) > 1 )
if ( \count( $currencies ) > 1 )
{
$form->add( new \IPS\Helpers\Form\Radio( 'currency', $invoice ? $invoice->currency : $customer->defaultCurrency(), TRUE, array( 'options' => array_combine( $currencies, $currencies ) ) ) );
}
@@ -962,9 +990,25 @@ class _invoices extends \IPS\Dispatcher\Controller
$form->add( new \IPS\Helpers\Form\Text( 'invoice_po_number', $invoice ? $invoice->po_number : NULL, FALSE, array( 'maxLength' => 255 ) ) );
$form->add( new \IPS\Helpers\Form\TextArea( 'invoice_notes', $invoice ? $invoice->notes : NULL ) );
$needTaxStatus = NULL;
foreach ( \IPS\nexus\Tax::roots() as $tax )
{
if ( $tax->type === 'eu' )
{
$needTaxStatus = 'eu';
break;
}
if ( $tax->type === 'business' )
{
$needTaxStatus = 'business';
}
}
$addressHelperClass = $needTaxStatus ? 'IPS\nexus\Form\BusinessAddress' : 'IPS\Helpers\Form\Address';
$addressHelperOptions = ( $needTaxStatus === 'eu' ) ? array( 'vat' => TRUE ) : array();
$form->addHeader( 'invoice_generate_addresses' );
$addresses = \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=?', $customer->member_id ) );
if ( count( $addresses ) )
$addresses = \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( '`member`=?', $customer->member_id ) );
if ( \count( $addresses ) )
{
$primaryBillingAddressId = NULL;
$chosenBillingAddressId = 0;
@@ -973,7 +1017,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$options = array();
foreach ( new \IPS\Patterns\ActiveRecordIterator( $addresses, 'IPS\nexus\Customer\Address' ) as $address )
{
$options[ $address->id ] = (string) $address->address;
$options[ $address->id ] = $address->address->toString('<br>') . ( ( isset( $address->address->business ) and $address->address->business and isset( $address->address->vat ) and $address->address->vat ) ? ( '<br>' . \IPS\Member::loggedIn()->language()->addToStack('cm_checkout_vat_number') . ': ' . \IPS\Theme::i()->getTemplate( 'global', 'nexus' )->vatNumber( $address->address->vat ) ) : '' );
if ( $address->primary_billing )
{
$primaryBillingAddressId = $address->id;
@@ -992,28 +1036,33 @@ class _invoices extends \IPS\Dispatcher\Controller
$chosenShippingAddressid = $address->id;
}
}
$options[0] = 'other';
$options[0] = \IPS\Member::loggedIn()->language()->addToStack('other');
$form->add( new \IPS\Helpers\Form\Radio( 'billing_address', ( $invoice and $invoice->billaddress ) ? $chosenBillingAddressId : $primaryBillingAddressId, TRUE, array( 'options' => $options, 'toggles' => array( 0 => array( 'new_billing_address' ) ) ) ) );
$newAddress = new \IPS\Helpers\Form\Address( 'new_billing_address', $invoice ? $invoice->billaddress : NULL, FALSE, array(), NULL, NULL, NULL, 'new_billing_address' );
$form->add( new \IPS\Helpers\Form\Radio( 'billing_address', ( $invoice and $invoice->billaddress ) ? $chosenBillingAddressId : $primaryBillingAddressId, TRUE, array( 'options' => $options, 'toggles' => array( 0 => array( 'new_billing_address' ) ), 'parse' => 'raw' ) ) );
$newAddress = new $addressHelperClass( 'new_billing_address', $invoice ? $invoice->billaddress : NULL, FALSE, $addressHelperOptions, NULL, NULL, NULL, 'new_billing_address' );
$newAddress->label = ' ';
$form->add( $newAddress );
$form->add( new \IPS\Helpers\Form\Radio( 'shipping_address', ( $invoice and $invoice->shipaddress ) ? $chosenShippingAddressid : ( ( $primaryShippingAddressId == $primaryBillingAddressId ) ? 'x' : $primaryShippingAddressId ), TRUE, array( 'options' => array( 'x' => 'same_as_billing_address' ) + $options, 'toggles' => array( 0 => array( 'new_shipping_address' ) ) ) ) );
$newAddress = new \IPS\Helpers\Form\Address( 'new_shipping_address', $invoice ? $invoice->shipaddress : NULL, FALSE, array(), NULL, NULL, NULL, 'new_shipping_address' );
$form->add( new \IPS\Helpers\Form\Radio( 'shipping_address', ( $invoice and $invoice->shipaddress ) ? $chosenShippingAddressid : ( ( $primaryShippingAddressId == $primaryBillingAddressId ) ? 'x' : $primaryShippingAddressId ), TRUE, array( 'options' => array( 'x' => \IPS\Member::loggedIn()->language()->addToStack('same_as_billing_address') ) + $options, 'toggles' => array( 0 => array( 'new_shipping_address' ) ), 'parse' => 'raw' ) ) );
$newAddress = new $addressHelperClass( 'new_shipping_address', $invoice ? $invoice->shipaddress : NULL, FALSE, array(), NULL, NULL, NULL, 'new_shipping_address' );
$newAddress->label = ' ';
$form->add( $newAddress );
}
else
{
$form->add( new \IPS\Helpers\Form\Address( 'new_billing_address', $invoice ? $invoice->billaddress : NULL, FALSE ) );
$form->add( new $addressHelperClass( 'new_billing_address', $invoice ? $invoice->billaddress : NULL, FALSE, $addressHelperOptions, function( $val ) {
if ( \IPS\Request::i()->invoice_status === \IPS\nexus\Invoice::STATUS_PAID and !$val )
{
throw new \DomainException('billing_address_req');
}
} ) );
$form->add( new \IPS\Helpers\Form\Radio( 'shipping_address', ( $invoice and $invoice->shipaddress and $invoice->shipaddress != $invoice->billaddress ) ? '1' : 'x', FALSE, array( 'options' => array( 'x' => 'same_as_billing_address', '1' => 'other' ), 'toggles' => array( '1' => array( 'new_shipping_address' ) ) ) ) );
$form->add( new \IPS\Helpers\Form\Address( 'new_shipping_address', $invoice ? $invoice->billaddress : NULL, FALSE, array(), NULL, NULL, NULL, 'new_shipping_address' ) );
$form->add( new $addressHelperClass( 'new_shipping_address', $invoice ? $invoice->billaddress : NULL, FALSE, array(), NULL, NULL, NULL, 'new_shipping_address' ) );
}
if ( $values = $form->values() )
{
if ( count( $addresses ) and $values['billing_address'] )
if ( \count( $addresses ) and $values['billing_address'] )
{
$data['billaddress'] = \IPS\nexus\Customer\Address::load( $values['billing_address'] )->address;
}
@@ -1029,7 +1078,7 @@ class _invoices extends \IPS\Dispatcher\Controller
}
}
if ( count( $addresses ) and $values['shipping_address'] and $values['shipping_address'] !== 'x' )
if ( \count( $addresses ) and $values['shipping_address'] and $values['shipping_address'] !== 'x' )
{
$data['shipaddress'] = \IPS\nexus\Customer\Address::load( $values['shipping_address'] )->address;
}
@@ -1120,6 +1169,21 @@ class _invoices extends \IPS\Dispatcher\Controller
$invoice->status = $data['status'];
$invoice->save();
}
/* Now that we have an ID, do we need to update purchase rows? */
if ( isset( $data['update_purchase_invoice_pending'] ) and \is_array( $data['update_purchase_invoice_pending'] ) )
{
foreach( $data['update_purchase_invoice_pending'] as $id )
{
try
{
$purchase = \IPS\nexus\Purchase::load( $id );
$purchase->invoice_pending = $invoice;
$purchase->save();
}
catch( \Exception $e ) {}
}
}
$invoice->sendNotification();
@@ -1144,6 +1208,7 @@ class _invoices extends \IPS\Dispatcher\Controller
foreach ( $values['purchases_to_renew'] as $purchase )
{
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $purchase, $values['renew_cycles'] ) );
$data['update_purchase_invoice_pending'][] = $purchase->id;
}
$data['items'] = $invoice->items->getArrayCopy();
$_SESSION[ 'wizard-' . md5( $url ) . '-data' ] = $data;
@@ -1180,7 +1245,7 @@ class _invoices extends \IPS\Dispatcher\Controller
if ( $secondStepValues = $secondStepForm->values() )
{
$item = $class::createFromForm( $secondStepValues, $invoice );
if( is_array( $item ) )
if( \is_array( $item ) )
{
foreach ( $item as $i )
{
@@ -1196,12 +1261,20 @@ class _invoices extends \IPS\Dispatcher\Controller
\IPS\Output::i()->redirect( $url );
return;
}
return $secondStepForm;
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $secondStepForm ), 200, 'text/html' );
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, $secondStepForm, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
}
}
}
$item = $class::createFromForm( $values, $invoice );
if( is_array( $item ) )
if( \is_array( $item ) )
{
foreach ( $item as $i )
{
@@ -1220,11 +1293,11 @@ class _invoices extends \IPS\Dispatcher\Controller
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $form ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $form ), 200, 'text/html' );
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, $form, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, $form, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
}
return;
}
@@ -1270,13 +1343,13 @@ class _invoices extends \IPS\Dispatcher\Controller
protected function settings()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_settings' );
$form = new \IPS\Helpers\Form;
$form->addheader('invoice_flow');
$form->addMessage('invoice_flow_visualise');
$form->add( new \IPS\Helpers\Form\Number( 'cm_invoice_generate', \IPS\Settings::i()->cm_invoice_generate, FALSE, array( 'min' => 1 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('cm_invoice_generate_suffix') ) );
$form->add( new \IPS\Helpers\Form\Number( 'cm_invoice_warning', \IPS\Settings::i()->cm_invoice_warning, FALSE, array( 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('cm_invoice_warning_suffix') ) );
$form->add( new \IPS\Helpers\Form\Number( 'cm_invoice_expireafter', \IPS\Settings::i()->cm_invoice_expireafter, FALSE, array( 'unlimited' => 0 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('days') ) );
$form->add( new \IPS\Helpers\Form\Interval( 'cm_invoice_generate', \IPS\Settings::i()->cm_invoice_generate, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::HOURS, 'min' => 1 ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('cm_invoice_generate_suffix') ) );
$form->add( new \IPS\Helpers\Form\Interval( 'cm_invoice_warning', \IPS\Settings::i()->cm_invoice_warning, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::HOURS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), NULL, NULL, \IPS\Member::loggedIn()->language()->addToStack('cm_invoice_warning_suffix') ) );
$form->add( new \IPS\Helpers\Form\Interval( 'cm_invoice_expireafter', \IPS\Settings::i()->cm_invoice_expireafter, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0 ), NULL, NULL, NULL ) );
$form->addHeader('invoice_layout');
$form->addMessage('invoice_layout_blurb');
$form->add( new \IPS\Helpers\Form\Editor( 'nexus_invoice_header', \IPS\Settings::i()->nexus_invoice_header, FALSE, array( 'app' => 'nexus', 'key' => 'Admin', 'autoSaveKey' => 'nexus-invoice-header', 'attachIds' => array( NULL, NULL, 'invoice-header' ), 'minimize' => 'nexus_invoice_header_placeholder' ) ) );
@@ -1332,4 +1405,74 @@ class _invoices extends \IPS\Dispatcher\Controller
\IPS\Output::i()->redirect( $invoice->acpUrl() );
}
/**
* Wait for the webhook for a transaction to come through before it has been created
*
* @return void
*/
public function webhook()
{
/* Load the invoice */
try
{
$invoice = \IPS\nexus\Invoice::load( \IPS\Request::i()->invoice );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X190/J', 404, '' );
}
/* Have we decided to give up waiting and just show a pending screen? */
if ( isset( \IPS\Request::i()->pending ) )
{
\IPS\Output::i()->error( 'webhook_not_received', '2X190/K', 404 );
}
/* Nope - show a redirector */
\IPS\Output::i()->output = $this->_webhookRedirector( $invoice, isset( \IPS\Request::i()->exclude ) ? explode( ',', \IPS\Request::i()->exclude ) : array() );
}
/**
* Get a redirector that points to do=webhook
*
* @param \IPS\nexus\Invoice $invoice The invoice
* @param array $exclude Transaction IDs to exclude
* @return \IPS\Helpers\MultipleRedirect
*/
protected function _webhookRedirector( \IPS\nexus\Invoice $invoice, $exclude )
{
$self = $this;
return new \IPS\Helpers\MultipleRedirect(
\IPS\Http\Url::internal('app=nexus&module=payments&controller=invoices')->setQueryString( array( 'do' => 'webhook', 'invoice' => $invoice->id, 'exclude' => implode( ',', $exclude ) ) ),
function( $data ) use ( $self, $invoice, $exclude ) {
if ( $data === NULL )
{
return array( time(), \IPS\Member::loggedIn()->language()->addToStack('processing_the_payment') );
}
else
{
/* Do we have any transactions yet? */
foreach ( $invoice->transactions( array( \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REFUSED ), $exclude ? array( array( \IPS\Db::i()->in( 't_id', $exclude, TRUE ) ) ) : array() ) as $transaction )
{
$self->_redirect( $invoice );
}
$giveUpTime = ( $data + 60 );
if ( time() > $giveUpTime )
{
return NULL;
}
else
{
sleep(5);
return array( $data, \IPS\Member::loggedIn()->language()->addToStack('processing_the_payment') );
}
}
},
function() use( $invoice ) {
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=invoices')->setQueryString( array( 'do' => 'webhook', 'invoice' => $invoice->id, 'pending' => 1 ) ) );
}
);
}
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _paymentsettings extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Call
*
@@ -55,7 +60,7 @@ class _paymentsettings extends \IPS\Dispatcher\Controller
{
$tabs['review'] = 'transaction_review';
}
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'email_copies_setting' ) )
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'email_copies_settings' ) )
{
$tabs['emails'] = 'notification_copies';
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _payouts extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -64,13 +69,13 @@ class _payouts extends \IPS\Dispatcher\Controller
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';
$classname = \IPS\nexus\Gateway::payoutGateways()[ $gateway ];
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 )
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=massprocess&gateway=' . $gateway )->csrf()
);
}
}
@@ -107,6 +112,7 @@ class _payouts extends \IPS\Dispatcher\Controller
protected function process()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
\IPS\Session::i()->csrfCheck();
try
{
@@ -150,8 +156,9 @@ class _payouts extends \IPS\Dispatcher\Controller
protected function massprocess()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
\IPS\Session::i()->csrfCheck();
$classname = 'IPS\nexus\Gateway\\' . \IPS\Request::i()->gateway . '\Payout';
$classname = \IPS\nexus\Gateway::payoutGateways()[ \IPS\Request::i()->gateway ];
if ( !class_exists( $classname ) or !method_exists( $classname, 'massProcess' ) )
{
\IPS\Output::i()->error( 'generic_error', '2X200/8', 403, '' );
@@ -191,6 +198,7 @@ class _payouts extends \IPS\Dispatcher\Controller
protected function cancel()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
\IPS\Session::i()->csrfCheck();
try
{
@@ -264,24 +272,20 @@ class _payouts extends \IPS\Dispatcher\Controller
$options = array();
$toggles = array();
$fields = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway' ) as $file )
foreach ( \IPS\nexus\Gateway::payoutGateways() as $key => $class )
{
if ( $file->isDir() and !$file->isDot() and $file != 'Stripe' and file_exists( \IPS\ROOT_PATH . '/applications/nexus/sources/Gateway/' . $file . '/Payout.php' ) )
$options[ $key ] = 'payout__admin_' . $key;
$toggles[ $key ] = array( 'form_header_payout_settings' );
foreach ( $class::settings() as $field )
{
$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 )
{
if ( !$field->htmlId )
{
$field->htmlId = md5(mt_rand());
}
$fields[] = $field;
$toggles[ (string) $file ][] = $field->htmlId;
$field->htmlId = md5(mt_rand());
}
$fields[] = $field;
$toggles[ $key ][] = $field->htmlId;
}
}
@@ -292,7 +296,7 @@ class _payouts extends \IPS\Dispatcher\Controller
}
$settings = \IPS\Settings::i()->nexus_payout ? json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) : array();
$settings = is_array( $settings ) ? array_keys( $settings ) : array();
$settings = \is_array( $settings ) ? array_keys( $settings ) : array();
$form = new \IPS\Helpers\Form;
$form->addMessage('payout_description');
@@ -305,10 +309,10 @@ class _payouts extends \IPS\Dispatcher\Controller
$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\nexus\Form\Money( 'nexus_payout_min', ( \IPS\Settings::i()->nexus_payout_min AND \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\Custom( 'nexus_payout_maximum', NULL, FALSE, array( 'getHtml' => function( $element ) {
$amount = new \IPS\nexus\Form\Money( 'nexus_payout_maximum[2]', \IPS\Settings::i()->nexus_payout_max ? json_decode( \IPS\Settings::i()->nexus_payout_max, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction', 'unlimitedTogglesOff' => array( 'payout_max_limited' ) ), NULL, NULL, NULL, 'nexus_payout_max' );
$amount = new \IPS\nexus\Form\Money( 'nexus_payout_maximum[2]', ( \IPS\Settings::i()->nexus_payout_max AND \IPS\Settings::i()->nexus_payout_max != '*' ) ? json_decode( \IPS\Settings::i()->nexus_payout_max, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction', 'unlimitedTogglesOff' => array( 'payout_max_limited' ) ), NULL, NULL, NULL, 'nexus_payout_max' );
$period = \IPS\Settings::i()->nexus_payout_max_period ? json_decode( \IPS\Settings::i()->nexus_payout_max_period, TRUE ) : array( 1, 'day' );
return \IPS\Theme::i()->getTemplate( 'payouts' )->maximumLimits( $amount->html(), (int) $period[0], $period[1] );
@@ -334,12 +338,18 @@ class _payouts extends \IPS\Dispatcher\Controller
}
}
}
/* Clear out gateway fields that aren't real settings */
foreach( $fields as $field )
{
unset( $values[ $field->name ] );
}
$values['nexus_payout'] = json_encode( $payoutSettings );
$values['nexus_payout_min'] = is_array( $values['nexus_payout_min'] ) ? json_encode( $values['nexus_payout_min'] ) : '*';
$values['nexus_payout_max'] = is_array( $values['nexus_payout_maximum'][2] ) ? json_encode( $values['nexus_payout_maximum'][2] ) : '*';
$values['nexus_payout_max_period'] = json_encode( array( $values['nexus_payout_maximum'][0], $values['nexus_payout_maximum'][1] ) );
$values['nexus_payout_min'] = \is_array( $values['nexus_payout_min'] ) ? json_encode( $values['nexus_payout_min'] ) : '*';
$values['nexus_payout_max'] = ( \is_array( $values['nexus_payout_maximum'][2] ) AND ( !isset( $values['nexus_payout_maximum'][2]['__unlimited'] ) OR !$values['nexus_payout_maximum'][2]['__unlimited'] ) ) ? json_encode( $values['nexus_payout_maximum'][2] ) : '*';
$values['nexus_payout_max_period'] = ( $values['nexus_payout_max'] == '*' ) ? NULL : json_encode( array( $values['nexus_payout_maximum'][0], $values['nexus_payout_maximum'][1] ) );
if ( $values['allow_topups'] )
{
$values['nexus_min_topup'] = $values['nexus_min_topup'] == '*' ? '*' : json_encode( $values['nexus_min_topup'] );
@@ -350,10 +360,10 @@ class _payouts extends \IPS\Dispatcher\Controller
$values['nexus_min_topup'] = '';
$values['nexus_max_credit'] = '';
}
unset( $values['allow_topups'] );
unset( $values['allow_topups'], $values['nexus_payout_maximum'] );
$values['nexus_no_commission'] = implode( ',', $values['nexus_no_commission'] );
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__payout_settings' );
@@ -387,7 +397,10 @@ class _payouts extends \IPS\Dispatcher\Controller
case 't':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', \IPS\Request::i()->filter ) );
break;
case 'n':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=notifications') );
break;
}
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _review extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _shipping extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -41,87 +46,6 @@ class _shipping extends \IPS\Dispatcher\Controller
*/
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(
@@ -133,7 +57,7 @@ class _shipping extends \IPS\Dispatcher\Controller
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('shipping');
\IPS\Output::i()->output = (string) $table;
\IPS\Output::i()->output = (string) \IPS\nexus\Shipping\Order::table( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=shipping' ) );
}
/**
@@ -421,7 +345,7 @@ class _shipping extends \IPS\Dispatcher\Controller
$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,
'street2' => \count( $toAddress['addressLines'] ) ? implode( ', ', $toAddress['addressLines'] ) : NULL,
'city' => $toAddress['city'],
'state' => $toAddress['region'],
'zip' => $toAddress['postalCode'],
@@ -432,7 +356,7 @@ class _shipping extends \IPS\Dispatcher\Controller
),
'from_address' => array(
'street1' => array_shift( $fromAddress->addressLines ),
'street2' => count( $fromAddress->addressLines ) ? implode( ', ', $fromAddress->addressLines ) : NULL,
'street2' => \count( $fromAddress->addressLines ) ? implode( ', ', $fromAddress->addressLines ) : NULL,
'city' => $fromAddress->city,
'state' => $fromAddress->region,
'zip' => $fromAddress->postalCode,
@@ -445,7 +369,7 @@ class _shipping extends \IPS\Dispatcher\Controller
'customs_info' => $customsInfo
) ) )->decodeJson();
if ( !count( $easyPost['rates'] ) )
if ( !\count( $easyPost['rates'] ) )
{
\IPS\Output::i()->error( 'err_no_easypost', '1X193/6', 403, '' );
}
@@ -570,7 +494,7 @@ class _shipping extends \IPS\Dispatcher\Controller
/* How much did the customer pay for shipping? */
$invoiceSummary = $shipment->invoice->summary();
$otherShipments = count( $shipment->invoice->shipments() ) - 1;
$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;
@@ -587,6 +511,7 @@ class _shipping extends \IPS\Dispatcher\Controller
public function cancel()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
\IPS\Session::i()->csrfCheck();
/* Load */
try
@@ -675,7 +600,7 @@ class _shipping extends \IPS\Dispatcher\Controller
\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 );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->blankTemplate( $output ), 200, 'text/html' );
}
/**
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _shippingrates extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
@@ -75,7 +80,7 @@ class _shippingrates extends \IPS\Node\Controller
{
$haveNoLowerLimit = TRUE;
}
elseif ( is_array( $rate['min'] ) )
elseif ( \is_array( $rate['min'] ) )
{
$allAreZero = TRUE;
foreach ( $rate['min'] as $val )
@@ -104,17 +109,17 @@ class _shippingrates extends \IPS\Node\Controller
if ( $lastUpper !== NULL )
{
if ( is_array( $lastUpper ) )
if ( \is_array( $lastUpper ) )
{
foreach ( $lastUpper as $k => $v )
{
if ( strval( $rate['min'][ $k ] - $v ) > 0.01 ) # @note: We use strval() here to prevent PHP from applying a precision to the float, inadvertently causing this to return TRUE
if ( \strval( $rate['min'][ $k ] - $v ) > 0.01 ) # @note: We use strval() here to prevent PHP from applying a precision to the float, inadvertently causing this to return TRUE
{
$consecutive = FALSE;
}
}
}
elseif ( strval( $rate['min'] - $lastUpper ) > 0.01 ) # @note: We use strval() here to prevent PHP from applying a precision to the float, inadvertently causing this to return TRUE
elseif ( \strval( $rate['min'] - $lastUpper ) > 0.01 ) # @note: We use strval() here to prevent PHP from applying a precision to the float, inadvertently causing this to return TRUE
{
$consecutive = FALSE;
}
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _tax extends \IPS\Node\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Node Class
*/
@@ -12,7 +12,7 @@
namespace IPS\nexus\modules\admin\payments;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -23,6 +23,11 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _transactions extends \IPS\Dispatcher\Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -45,7 +50,7 @@ class _transactions extends \IPS\Dispatcher\Controller
/* Create Table */
$table = \IPS\nexus\Transaction::table( array( array( 't_status<>?', \IPS\nexus\Transaction::STATUS_PENDING ) ), \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=transactions' ), 't' );
$table->filters = array(
'trans_attention_required' => array( '( t_status=? OR t_status=? OR t_status=? )', \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_DISPUTED ),
'trans_attention_required' => array( \IPS\Db::i()->in( 't_status', array( \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_DISPUTED ) ) ),
);
$table->advancedSearch = array(
't_id' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
@@ -96,6 +101,7 @@ class _transactions extends \IPS\Dispatcher\Controller
public function approve()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
\IPS\Session::i()->csrfCheck();
/* Load Transaction */
try
@@ -109,7 +115,7 @@ class _transactions extends \IPS\Dispatcher\Controller
$method = $transaction->method;
/* Can we approve it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ) ) )
if ( !\in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING, \IPS\nexus\Transaction::STATUS_DISPUTED ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/A', 403, '' );
}
@@ -127,7 +133,10 @@ class _transactions extends \IPS\Dispatcher\Controller
/* Do it */
try
{
$transaction->capture();
if ( $transaction->status !== \IPS\nexus\Transaction::STATUS_DISPUTED )
{
$transaction->capture();
}
$transaction->approve( \IPS\Member::loggedIn() );
}
catch ( \LogicException $e )
@@ -141,9 +150,16 @@ class _transactions extends \IPS\Dispatcher\Controller
/* Send Email */
$transaction->sendNotification();
/* Redirect */
$this->_redirect( $transaction );
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->queueStatus )
{
\IPS\Output::i()->json( array( 'message' => \IPS\Member::loggedIn()->language()->addToStack('tstatus_okay_set'), 'queue' => \IPS\nexus\extensions\core\AdminNotifications\Transaction::queueHtml( \IPS\Request::i()->queueStatus ) ) );
}
else
{
$this->_redirect( $transaction );
}
}
/**
@@ -154,6 +170,7 @@ class _transactions extends \IPS\Dispatcher\Controller
public function review()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
\IPS\Session::i()->csrfCheck();
/* Load Transaction */
try
@@ -167,7 +184,7 @@ class _transactions extends \IPS\Dispatcher\Controller
$method = $transaction->method;
/* Can we flag it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD ) ) )
if ( !\in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_HELD ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/B', 403, '' );
}
@@ -189,6 +206,9 @@ class _transactions extends \IPS\Dispatcher\Controller
) );
}
/* Notification */
\IPS\core\AdminNotification::send( 'nexus', 'Transaction', \IPS\nexus\Transaction::STATUS_REVIEW, TRUE, $transaction );
/* Create a support request? */
if ( \IPS\Settings::i()->nexus_revw_sa != -1 )
{
@@ -214,7 +234,7 @@ class _transactions extends \IPS\Dispatcher\Controller
else
{
$_SESSION["wizard-{$key}-data"] = $extraData;
if ( count( \IPS\nexus\Support\StockAction::roots() ) )
if ( \count( \IPS\nexus\Support\StockAction::roots() ) )
{
$_SESSION["wizard-{$key}-step"] = 'stock_action';
}
@@ -231,7 +251,14 @@ class _transactions extends \IPS\Dispatcher\Controller
}
/* Redirect */
$this->_redirect( $transaction );
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->queueStatus )
{
\IPS\Output::i()->json( array( 'message' => \IPS\Member::loggedIn()->language()->addToStack('tstatus_revw_set'), 'queue' => \IPS\nexus\extensions\core\AdminNotifications\Transaction::queueHtml( \IPS\Request::i()->queueStatus ) ) );
}
else
{
$this->_redirect( $transaction );
}
}
/**
@@ -242,6 +269,7 @@ class _transactions extends \IPS\Dispatcher\Controller
public function void()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
\IPS\Session::i()->csrfCheck();
/* Load Transaction */
try
@@ -255,7 +283,7 @@ class _transactions extends \IPS\Dispatcher\Controller
$method = $transaction->method;
/* Can we void it? */
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ) ) and ( !$transaction->auth or !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW ) ) ) )
if ( !\in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_WAITING, \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ) ) 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, '' );
}
@@ -277,7 +305,14 @@ class _transactions extends \IPS\Dispatcher\Controller
$transaction->sendNotification();
/* Redirect */
$this->_redirect( $transaction );
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->queueStatus )
{
\IPS\Output::i()->json( array( 'message' => \IPS\Member::loggedIn()->language()->addToStack('tstatus_fail_set'), 'queue' => \IPS\nexus\extensions\core\AdminNotifications\Transaction::queueHtml( \IPS\Request::i()->queueStatus ) ) );
}
else
{
$this->_redirect( $transaction );
}
}
/**
@@ -301,7 +336,7 @@ class _transactions extends \IPS\Dispatcher\Controller
$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 ) ) )
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\nexus\Transaction::STATUS_DISPUTED ) ) )
{
\IPS\Output::i()->error( 'transaction_status_err', '2X186/E', 403, '' );
}
@@ -567,6 +602,10 @@ class _transactions extends \IPS\Dispatcher\Controller
case 't':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );
break;
case 'n':
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=notifications') );
break;
}
}