Version 4.1.19

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

No files matched your search

@@ -0,0 +1,210 @@
<?php
/**
* @brief Billing Agreememts
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 16 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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;
}
/**
* Billing Agreements
*/
class _billingagreements extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'billingagreements_view' );
parent::execute();
}
/**
* View
*
* @return void
*/
public function manage()
{
/* Load */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
if ( !$billingAgreement->canceled and $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
{
$billingAgreement->canceled = TRUE;
$billingAgreement->save();
}
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X320/1', 404, '' );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error_public', '4X320/9', 500, 'billing_agreement_error', array(), $e->getName() );
}
/* Show */
try
{
/* Purchases */
$purchases = NULL;
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) and ( !isset( \IPS\Request::i()->table ) ) )
{
$purchases = \IPS\nexus\Purchase::tree( $billingAgreement->acpUrl(), array( array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'ba' );
}
/* Transactions */
$transactions = NULL;
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) and ( !isset( \IPS\Request::i()->table ) ) )
{
$transactions = \IPS\nexus\Transaction::table( array( array( 't_billing_agreement=? AND t_status<>?', $billingAgreement->id, \IPS\nexus\Transaction::STATUS_PENDING ) ), $billingAgreement->acpUrl(), 'ba' );
$transactions->limit = 50;
foreach ( $transactions->include as $k => $v )
{
if ( in_array( $v, array( 't_method', 't_member' ) ) )
{
unset( $transactions->include[ $k ] );
}
}
}
/* Action Buttons */
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'billingagreements_manage' ) )
{
if ( $billingAgreement->status() == $billingAgreement::STATUS_ACTIVE )
{
\IPS\Output::i()->sidebar['actions']['suspend'] = array(
'icon' => 'times',
'title' => 'billing_agreement_suspend',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'suspend' ) ),
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('billing_agreement_suspend_confirm') )
);
}
elseif ( $billingAgreement->status() == $billingAgreement::STATUS_SUSPENDED )
{
\IPS\Output::i()->sidebar['actions']['reactivate'] = array(
'icon' => 'check',
'title' => 'billing_agreement_reactivate',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'reactivate' ) ),
'data' => array( 'confirm' => '' )
);
}
if ( $billingAgreement->status() != $billingAgreement::STATUS_CANCELED )
{
\IPS\Output::i()->sidebar['actions']['cancel'] = array(
'icon' => 'times-circle',
'title' => 'billing_agreement_cancel',
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'cancel' ) ),
);
}
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'billing_agreement_id', FALSE, array( 'sprintf' => array( $billingAgreement->id ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'billingagreements' )->view( $billingAgreement, $purchases, $transactions );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/2', 500, '', array(), $e->getName() );
}
catch ( \DomainException $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/3', 500 );
}
}
/**
* Reconcile - resets next_cycle date
*
* @return void
*/
public function reconcile()
{
/* Load */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X320/5', 404, '' );
}
/* Reconcile */
try
{
$billingAgreement->next_cycle = $billingAgreement->nextPaymentDate();
$billingAgreement->save();
\IPS\Output::i()->redirect( $billingAgreement->acpUrl() );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/6', 500, '', array(), $e->getName() );
}
catch ( \DomainException $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/7', 500 );
}
}
/**
* Suspend/Reactivate/Cancel
*
* @return void
*/
public function act()
{
/* Check act */
$act = \IPS\Request::i()->act;
if ( !in_array( $act, array( 'suspend', 'reactivate', 'cancel' ) ) )
{
\IPS\Output::i()->error( 'node_error', '3X320/8', 403, '' );
}
/* Load */
try
{
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2X320/8', 404, '' );
}
/* Perform Action */
try
{
$billingAgreement->$act();
\IPS\Output::i()->redirect( $billingAgreement->acpUrl() );
}
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/9', 500, '', array(), $e->getName() );
}
catch ( \DomainException $e )
{
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/A', 500 );
}
}
}
@@ -2,9 +2,9 @@
/**
* @brief Checkout Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 28 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -41,7 +41,23 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
* @return void
*/
public function manage()
{
{
$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 )
{
$requireBillingOptions['giftvoucher'] = 'nexus_require_billing_gift';
}
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_donate_goals' )->first() )
{
$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 ) )
{
$requireBillingOptions['domain'] = 'nexus_require_billing_domain';
}
$requireBillingOptions['other'] = 'nexus_require_billing_other';
$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 )
@@ -58,6 +74,7 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
}
}
} ) );
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_require_billing', explode( ',', \IPS\Settings::i()->nexus_require_billing ), FALSE, array( 'options' => $requireBillingOptions ) ) );
$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(
@@ -76,9 +93,14 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
$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 ( \IPS\Settings::i()->reg_auth_type != 'none' )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_checkreg_validate', \IPS\Settings::i()->nexus_checkreg_validate ) );
}
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';
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplogs__checkout_settings' );
@@ -2,9 +2,9 @@
/**
* @brief Currencies
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -45,6 +45,7 @@ class _currencies extends \IPS\Dispatcher\Controller
$languages = \IPS\Lang::languages();
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->squashFields = FALSE; // This has issues with select fields
$matrix->langPrefix = 'currency_';
$matrix->columns = array(
'code' => function( $key, $value, $data )
@@ -80,7 +81,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', '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' ) ) )
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', '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' );
}
@@ -109,6 +110,22 @@ class _currencies extends \IPS\Dispatcher\Controller
\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 );
$definition = \IPS\Db::i()->getTableDefinition( 'nexus_package_base_prices' );
foreach ( $definition['columns'] AS $key => $value )
{
if ( $key === 'id' )
{
continue;
}
if ( !isset( $save[$key] ) )
{
\IPS\Db::i()->dropColumn( 'nexus_package_base_prices', $key );
}
}
\IPS\Session::i()->log( 'acplogs__currencies' );
@@ -2,10 +2,10 @@
/**
* @brief donations
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage
* @package IPS Community Suite
* @subpackage Nexus
* @since 05 May 2014
* @version SVN_VERSION_NUMBER
*/
@@ -2,10 +2,10 @@
/**
* @brief donations
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage
* @package IPS Community Suite
* @subpackage Nexus
* @since 17 Jun 2014
* @version SVN_VERSION_NUMBER
*/
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 19 Aug 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @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.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Payment Gateways
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Invoice Timeline
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 19 Jun 2015
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Invoices
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -98,8 +98,8 @@ class _invoices extends \IPS\Dispatcher\Controller
}
/* Display */
\IPS\Output::i()->title = $customer ? \IPS\Member::loggedIn()->language()->addToStack( 'members_invoices', FALSE, array( 'sprintf' => array( $customer->cm_name ) ) ) : \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_invoices');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
\IPS\Output::i()->title = $customer ? \IPS\Member::loggedIn()->language()->addToStack( 'members_invoices', FALSE, array( 'sprintf' => array( $customer->cm_name ) ) ) : \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_invoices');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table );
}
/**
@@ -123,7 +123,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$transactions = NULL;
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) and ( !isset( \IPS\Request::i()->table ) ) )
{
$transactions = \IPS\nexus\Transaction::table( array( array( 't_invoice=?', $invoice->id ) ), $invoice->acpUrl(), 'i' );
$transactions = \IPS\nexus\Transaction::table( array( array( 't_invoice=? and t_status<>?', $invoice->id, \IPS\nexus\Transaction::STATUS_PENDING ) ), $invoice->acpUrl(), 'i' );
$transactions->limit = 50;
$transactions->tableTemplate = array( \IPS\Theme::i()->getTemplate('invoices'), 'transactionsTable' );
$transactions->rowsTemplate = array( \IPS\Theme::i()->getTemplate('invoices'), 'transactionsTableRows' );
@@ -219,7 +219,7 @@ class _invoices extends \IPS\Dispatcher\Controller
/* 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 ) );
$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 ) )
{
$transUrl = $invoice->acpUrl();
@@ -248,7 +248,7 @@ class _invoices extends \IPS\Dispatcher\Controller
) );
/* Send Email */
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceMarkedPaid', array( $invoice, $invoice->summary() ) )
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceMarkedPaid', array( $invoice, $invoice->summary() ), \IPS\Email::TYPE_TRANSACTIONAL )
->send(
$invoice->member,
array_map(
@@ -276,7 +276,8 @@ class _invoices extends \IPS\Dispatcher\Controller
public function card()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'chargetocard' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'customer.css', 'nexus', 'admin' ) );
/* Load Invoice */
try
{
@@ -305,7 +306,7 @@ class _invoices extends \IPS\Dispatcher\Controller
{
$amountToPay = $invoice->amountToPay()->amount;
$form = new \IPS\Helpers\Form( 'amount', 'continue' );
$form->add( new \IPS\Helpers\Form\Number( 't_amount', $amountToPay, TRUE, array( 'min' => 0.01, 'max' => $amountToPay, 'decimals' => TRUE ), NULL, NULL, $invoice->currency ) );
$form->add( new \IPS\Helpers\Form\Number( 't_amount', $amountToPay, TRUE, array( 'min' => 0.01, 'max' => (string) $amountToPay, 'decimals' => TRUE ), NULL, NULL, $invoice->currency ) );
if ( $values = $form->values() )
{
return $values;
@@ -321,7 +322,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$paymentMethodsToggles = array();
foreach ( $gateways as $gateway )
{
foreach ( $gateway->paymentScreen( $invoice, $amountToPay ) as $element )
foreach ( $gateway->paymentScreen( $invoice, $amountToPay, $invoice->member ) as $element )
{
if ( !$element->htmlId )
{
@@ -433,11 +434,11 @@ class _invoices extends \IPS\Dispatcher\Controller
$amountToPay = $invoice->amountToPay()->amount;
$credits = $invoice->member->cm_credits;
$credit = $credits[ $invoice->currency ]->amount;
$maxCanCharge = ( $credit < $amountToPay ) ? $credit : $amountToPay;
$maxCanCharge = ( $credit->compare( $amountToPay ) === -1 ) ? $credit : $amountToPay;
/* Build Form */
$form = new \IPS\Helpers\Form( 'amount', 'invoice_charge_to_credit' );
$form->add( new \IPS\Helpers\Form\Number( 't_amount', $maxCanCharge, TRUE, array( 'min' => 0.01, 'max' => $maxCanCharge, 'decimals' => TRUE ), NULL, NULL, $invoice->currency ) );
$form->add( new \IPS\Helpers\Form\Number( 't_amount', $maxCanCharge, TRUE, array( 'min' => 0.01, 'max' => (string) $maxCanCharge, 'decimals' => TRUE ), NULL, NULL, $invoice->currency ) );
/* Handle submissions */
if ( $values = $form->values() )
@@ -452,7 +453,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$transaction->approve( NULL );
$transaction->sendNotification();
$credits[ $invoice->currency ]->amount -= $values['t_amount'];
$credits[ $invoice->currency ]->amount = $credits[ $invoice->currency ]->amount->subtract( $transaction->amount->amount );
$invoice->member->cm_credits = $credits;
$invoice->member->save();
@@ -527,9 +528,24 @@ 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() );
$output = \IPS\Theme::i()->getTemplate( 'invoices', 'nexus', 'global' )->printInvoice( $invoice, $invoice->summary(), $address );
\IPS\Output::i()->title = 'I' . $invoice->id;
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->blankTemplate( $output ) );
}
@@ -585,7 +601,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$form->add( $field );
/* Partial refund? */
$field = new \IPS\Helpers\Form\Number( $transaction->id . '_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, $transaction->id . '_refund_amount' );
$field = new \IPS\Helpers\Form\Number( $transaction->id . '_refund_amount', ( $transaction->status === \IPS\nexus\Transaction::STATUS_PART_REFUNDED ? (string) $transaction->amount->amount->subtract( $transaction->partial_refund->amount ) : 0 ), TRUE, array( 'unlimited' => 0, 'unlimitedLang' => \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) ), 'max' => (string) $transaction->amount->amount->subtract( $transaction->partial_refund->amount ), 'decimals' => TRUE ), NULL, NULL, $transaction->amount->currency, $transaction->id . '_refund_amount' );
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'refund_amount' );
$form->add( $field );
}
@@ -595,7 +611,7 @@ class _invoices extends \IPS\Dispatcher\Controller
if ( $invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
{
$statusOptions = array();
if ( $invoice->total->amount !== (float) 0 )
if ( !$invoice->total->amount->isZero() )
{
$statusOptions[ \IPS\nexus\Invoice::STATUS_PENDING ] = 'refund_invoice_pending';
}
@@ -724,6 +740,9 @@ class _invoices extends \IPS\Dispatcher\Controller
{
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_delete' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
/* Load Transaction */
try
{
@@ -758,21 +777,39 @@ class _invoices extends \IPS\Dispatcher\Controller
/* Init */
\IPS\Dispatcher::i()->checkAcpPermission( 'invoices_add' );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_store.js', 'nexus', 'admin' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('generate_invoice');
$url = \IPS\Http\Url::internal("app=nexus&module=payments&controller=invoices&do=generate");
if ( isset( \IPS\Request::i()->member ) )
{
$url = $url->setQueryString( 'member', \IPS\Request::i()->member );
}
/* Are we editing an invoice? */
$invoice = NULL;
if ( isset( \IPS\Request::i()->id ) )
{
try
{
$invoice = \IPS\nexus\Invoice::load( \IPS\Request::i()->id );
if ( $invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
{
\IPS\Output::i()->error( 'cannot_edit_paid_invoice', '2X190/F', 403, '' );
}
$url = $url->setQueryString( 'id', \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e ) { }
}
\IPS\Output::i()->title = $invoice ? \IPS\Member::loggedIn()->language()->addToStack( 'invoice_number', FALSE, array( 'sprintf' => array( $invoice->id ) ) ) : \IPS\Member::loggedIn()->language()->addToStack('generate_invoice');
/* Select Customer */
$steps = array();
if ( !isset( \IPS\Request::i()->member ) )
if ( !isset( \IPS\Request::i()->member ) and !$invoice )
{
$steps['invoice_generate_member'] = function( $data )
{
$form = new \IPS\Helpers\Form('customer', 'continue');
$form->add( new \IPS\Helpers\Form\Member( 'invoice_generate_member' ) );
$form->add( new \IPS\Helpers\Form\Member( 'invoice_generate_member', NULL, TRUE ) );
if ( $values = $form->values() )
{
return array( 'member' => $values['invoice_generate_member']->member_id );
@@ -782,9 +819,9 @@ class _invoices extends \IPS\Dispatcher\Controller
}
/* Select Addresses */
$steps['invoice_generate_settings'] = function( $data )
$steps['invoice_generate_settings'] = function( $data ) use ( $invoice )
{
$customer = \IPS\nexus\Customer::load( isset( \IPS\Request::i()->member ) ? \IPS\Request::i()->member : $data['member'] );
$customer = $invoice ? $invoice->member : ( \IPS\nexus\Customer::load( isset( \IPS\Request::i()->member ) ? \IPS\Request::i()->member : $data['member'] ) );
$form = new \IPS\Helpers\Form('settings', 'continue');
@@ -792,7 +829,7 @@ class _invoices extends \IPS\Dispatcher\Controller
$currencies = \IPS\nexus\Money::currencies();
if ( count( $currencies ) > 1 )
{
$form->add( new \IPS\Helpers\Form\Radio( 'currency', $customer->defaultCurrency(), TRUE, array( 'options' => array_combine( $currencies, $currencies ) ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'currency', $invoice ? $invoice->currency : $customer->defaultCurrency(), TRUE, array( 'options' => array_combine( $currencies, $currencies ) ) ) );
}
$statusOptions = array();
$statusOptions[ \IPS\nexus\Invoice::STATUS_PAID ] = 'invoice_status_paid';
@@ -802,47 +839,58 @@ class _invoices extends \IPS\Dispatcher\Controller
$statusOptions[ \IPS\nexus\Invoice::STATUS_EXPIRED ] = 'invoice_status_expd';
}
$statusOptions[ \IPS\nexus\Invoice::STATUS_CANCELED ] = 'invoice_status_canc';
$form->add( new \IPS\Helpers\Form\Radio( 'invoice_status', \IPS\nexus\Invoice::STATUS_PENDING, TRUE, array( 'options' => $statusOptions ) ) );
$form->add( new \IPS\Helpers\Form\Text( 'invoice_title', NULL, FALSE ) );
$form->add( new \IPS\Helpers\Form\Text( 'invoice_po_number', NULL, FALSE, array( 'maxLength' => 255 ) ) );
$form->add( new \IPS\Helpers\Form\TextArea( 'invoice_notes', NULL ) );
$form->add( new \IPS\Helpers\Form\Radio( 'invoice_status', $invoice ? $invoice->status : \IPS\nexus\Invoice::STATUS_PENDING, TRUE, array( 'options' => $statusOptions ) ) );
$form->add( new \IPS\Helpers\Form\Text( 'invoice_title', $invoice ? $invoice->title : NULL, FALSE ) );
$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 ) );
$form->addHeader( 'invoice_generate_addresses' );
$addresses = \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=?', isset( \IPS\Request::i()->member ) ? \IPS\Request::i()->member : $data['member'] ) );
$addresses = \IPS\Db::i()->select( '*', 'nexus_customer_addresses', array( 'member=?', $customer->member_id ) );
if ( count( $addresses ) )
{
$billing = NULL;
$shipping = 'x';
$primaryBillingAddressId = NULL;
$chosenBillingAddressId = 0;
$primaryShippingAddressId = 'x';
$chosenShippingAddressid = 0;
$options = array();
foreach ( new \IPS\Patterns\ActiveRecordIterator( $addresses, 'IPS\nexus\Customer\Address' ) as $address )
{
$options[ $address->id ] = (string) $address->address;
if ( $address->primary_billing )
{
$billing = $address->id;
$primaryBillingAddressId = $address->id;
}
if ( $address->primary_shipping )
{
$shipping = $address->id;
$primaryShippingAddressId = $address->id;
}
if ( $invoice and $invoice->billaddress and $invoice->billaddress == $address->address )
{
$chosenBillingAddressId = $address->id;
}
if ( $invoice and $invoice->shipaddress and $invoice->shipaddress == $address->address )
{
$chosenShippingAddressid = $address->id;
}
}
$options[0] = 'other';
$form->add( new \IPS\Helpers\Form\Radio( 'billing_address', $billing, TRUE, array( 'options' => $options, 'toggles' => array( 0 => array( 'new_billing_address' ) ) ) ) );
$newAddress = new \IPS\Helpers\Form\Address( 'new_billing_address', 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' ) ) ) ) );
$newAddress = new \IPS\Helpers\Form\Address( 'new_billing_address', $invoice ? $invoice->billaddress : NULL, FALSE, array(), NULL, NULL, NULL, 'new_billing_address' );
$newAddress->label = ' ';
$form->add( $newAddress );
$form->add( new \IPS\Helpers\Form\Radio( 'shipping_address', ( $shipping == $billing ) ? 'x' : $shipping, TRUE, array( 'unlimited' => 'x', 'unlimitedLang' => 'same_as_billing_address', 'options' => $options, 'toggles' => array( 0 => array( 'new_shipping_address' ) ) ) ) );
$newAddress = new \IPS\Helpers\Form\Address( 'new_shipping_address', 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' => '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' );
$newAddress->label = ' ';
$form->add( $newAddress );
}
else
{
$form->add( new \IPS\Helpers\Form\Address( 'new_billing_address', NULL, TRUE ) );
$form->add( new \IPS\Helpers\Form\Checkbox( 'same_shipping_address', TRUE, FALSE, array( 'togglesOff' => array( 'new_shipping_address' ) ) ) );
$form->add( new \IPS\Helpers\Form\Address( 'new_shipping_address', NULL, FALSE, array(), NULL, NULL, NULL, 'new_shipping_address' ) );
$form->add( new \IPS\Helpers\Form\Address( 'new_billing_address', $invoice ? $invoice->billaddress : NULL, FALSE ) );
$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' ) );
}
if ( $values = $form->values() )
@@ -855,18 +903,19 @@ class _invoices extends \IPS\Dispatcher\Controller
{
if( $values['new_billing_address'] === NULL OR empty( $values['new_billing_address']->addressLines ) or !$values['new_billing_address']->city or !$values['new_billing_address']->country or ( !$values['new_billing_address']->region and array_key_exists( $values['new_billing_address']->country, \IPS\GeoLocation::$states ) ) or !$values['new_billing_address']->postalCode )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('billing_address_required');
return $form;
$data['billaddress'] = NULL;
}
else
{
$data['billaddress'] = $values['new_billing_address'];
}
$data['billaddress'] = $values['new_billing_address'];
}
if ( count( $addresses ) and $values['shipping_address'] and $values['shipping_address'] !== 'x' )
{
$data['shipaddress'] = \IPS\nexus\Customer\Address::load( $values['shipping_address'] )->address;
}
elseif ( ( isset( $values['same_shipping_address'] ) and $values['same_shipping_address'] ) or $values['shipping_address'] === 'x' )
elseif ( $values['shipping_address'] === 'x' )
{
$data['shipaddress'] = $data['billaddress'];
}
@@ -874,19 +923,25 @@ class _invoices extends \IPS\Dispatcher\Controller
{
if( $values['new_shipping_address'] === NULL OR empty( $values['new_shipping_address']->addressLines ) or !$values['new_shipping_address']->city or !$values['new_shipping_address']->country or ( !$values['new_shipping_address']->region and array_key_exists( $values['new_shipping_address']->country, \IPS\GeoLocation::$states ) ) or !$values['new_shipping_address']->postalCode )
{
$form->error = \IPS\Member::loggedIn()->language()->addToStack('shipping_address_required');
return $form;
$data['shipaddress'] = NULL;
}
else
{
$data['shipaddress'] = $values['new_shipping_address'];
}
$data['shipaddress'] = $values['new_shipping_address'];
}
$data['currency'] = isset( $values['currency'] ) ? $values['currency'] : $customer->defaultCurrency();
$data['status'] = $values['invoice_status'];
$data['title'] = $values['invoice_title'];
$data['po_number'] = $values['invoice_po_number'];
$data['notes'] = $values['invoice_notes'];
if ( $invoice )
{
$data['items'] = $invoice->items;
}
return $data;
}
@@ -894,13 +949,22 @@ class _invoices extends \IPS\Dispatcher\Controller
};
/* Add Items */
$steps['invoice_generate_items'] = function( $data ) use ( $url )
$steps['invoice_generate_items'] = function( $data ) use ( $url, $invoice )
{
$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\Member::load( isset( \IPS\Request::i()->member ) ? \IPS\Request::i()->member : $data['member'] );
if ( !$invoice )
{
$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\Member::load( isset( \IPS\Request::i()->member ) ? \IPS\Request::i()->member : $data['member'] );
}
$invoice->currency = $data['currency'];
$invoice->billaddress = $data['billaddress'];
$invoice->shipaddress = $data['shipaddress'];
if ( $data['billaddress'] )
{
$invoice->billaddress = $data['billaddress'];
}
if ( $data['shipaddress'] )
{
$invoice->shipaddress = $data['shipaddress'];
}
$invoice->items = isset( $data['items'] ) ? json_encode( $data['items'] ) : json_encode( array() );
if ( isset( \IPS\Request::i()->continue ) )
@@ -1102,7 +1166,7 @@ class _invoices extends \IPS\Dispatcher\Controller
if ( $values = $form->values() )
{
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => (int) (bool) $values['cm_invoice_expireafter'] ), "`key`='expireInvoices'" );
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => (int) (bool) $values['cm_invoice_expireafter'] ), "`key`='expireInvoices'" );
$form->saveAsSettings();
\IPS\Session::i()->log( 'acplogs__invoice_settings' );
@@ -2,9 +2,9 @@
/**
* @brief Payment Settings
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Payouts
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 07 Apr 2014
* @version SVN_VERSION_NUMBER
@@ -138,7 +138,7 @@ class _payouts extends \IPS\Dispatcher\Controller
\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\Email::buildFromTemplate( 'nexus', 'payoutComplete', array( $payout ), \IPS\Email::TYPE_TRANSACTIONAL )->send( $payout->member );
$this->_redirect( $payout );
}
@@ -178,7 +178,7 @@ class _payouts extends \IPS\Dispatcher\Controller
\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\Email::buildFromTemplate( 'nexus', 'payoutComplete', array( $payout ), \IPS\Email::TYPE_TRANSACTIONAL )->send( $payout->member );
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
@@ -217,7 +217,7 @@ class _payouts extends \IPS\Dispatcher\Controller
if ( \IPS\Request::i()->prompt )
{
$credits = $payout->member->cm_credits;
$credits[ $payout->currency ]->amount += $payout->amount->amount;
$credits[ $payout->amount->currency ]->amount = $credits[ $payout->amount->currency ]->amount->add( $payout->amount->amount );
$payout->member->cm_credits = $credits;
$payout->member->save();
}
@@ -234,6 +234,9 @@ class _payouts extends \IPS\Dispatcher\Controller
{
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
try
{
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
@@ -264,7 +267,7 @@ class _payouts extends \IPS\Dispatcher\Controller
$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' ) )
if ( $file->isDir() and !$file->isDot() and $file != 'Stripe' 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' );
@@ -304,6 +307,14 @@ class _payouts extends \IPS\Dispatcher\Controller
}
$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\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' );
$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] );
} ), NULL, NULL, NULL, 'nexus_payout_maximum' ) );
$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' ) ) ) );
@@ -326,7 +337,9 @@ class _payouts extends \IPS\Dispatcher\Controller
}
$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_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] ) );
if ( $values['allow_topups'] )
{
@@ -2,9 +2,9 @@
/**
* @brief Transaction Review
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 26 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Shipments
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 20 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -550,7 +550,7 @@ class _shipping extends \IPS\Dispatcher\Controller
if ( isset( $response['error'] ) )
{
\IPS\Output::i()->error( 'err_err_easypost', '3X193/9', 500, '', array(), $response['error'] );
\IPS\Output::i()->error( 'err_err_easypost', '3X193/9', 500, '', array(), $response['error']['message'] );
}
$shipment->label = $response['postage_label']['label_url'];
@@ -619,6 +619,9 @@ class _shipping extends \IPS\Dispatcher\Controller
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_delete' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
/* Load */
try
{
@@ -2,9 +2,9 @@
/**
* @brief Shipping Rates
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 13 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -36,7 +36,108 @@ class _shippingrates extends \IPS\Node\Controller
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'shipping_manage' );
\IPS\Dispatcher::i()->checkAcpPermission( 'shipmethods_manage' );
parent::execute();
}
/**
* Warning about unconsecutive rules
*
* @return void
*/
protected function warning()
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->decision( 'ship_rates_' . \IPS\Request::i()->type, array(
'ship_rates_go_back' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=shippingrates&do=form&id=' . \IPS\Request::i()->id ),
'ship_rates_save_anyway' => \IPS\Http\Url::internal( $this->url ),
) );
}
/**
* Redirect after save
*
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
* @param \IPS\Node\Model $new The node now
* @param string $lastUsedTab The tab last used in the form
* @return void
*/
protected function _afterSave( \IPS\Node\Model $old = NULL, \IPS\Node\Model $new, $lastUsedTab = FALSE )
{
$haveNoLowerLimit = FALSE;
$haveNoUpperLimit = FALSE;
$lastUpper = NULL;
$consecutive = TRUE;
foreach ( json_decode( $new->rates, TRUE ) as $rate )
{
if ( !$haveNoLowerLimit )
{
if ( $rate['min'] === '*' )
{
$haveNoLowerLimit = TRUE;
}
elseif ( is_array( $rate['min'] ) )
{
$allAreZero = TRUE;
foreach ( $rate['min'] as $val )
{
if ( $val !== 0 )
{
$allAreZero = FALSE;
}
}
if ( $allAreZero )
{
$haveNoLowerLimit = TRUE;
}
}
elseif ( $rate['min'] === 0 )
{
$haveNoLowerLimit = TRUE;
}
}
if ( !$haveNoUpperLimit and $rate['max'] === '*' )
{
$haveNoUpperLimit = TRUE;
}
if ( $lastUpper !== NULL )
{
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
{
$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
{
$consecutive = FALSE;
}
}
$lastUpper = $rate['max'];
}
if( !$haveNoLowerLimit )
{
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'do' => 'warning', 'type' => 'missing_lower', 'id' => $new->_id ) ) );
}
elseif( !$haveNoUpperLimit )
{
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'do' => 'warning', 'type' => 'missing_upper', 'id' => $new->_id ) ) );
}
elseif ( !$consecutive )
{
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'do' => 'warning', 'type' => 'unconsecutive', 'id' => $new->_id ) ) );
}
else
{
parent::_afterSave( $old, $new, $lastUsedTab );
}
}
}
@@ -2,9 +2,9 @@
/**
* @brief Tax Classes
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 12 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief Transactions
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -44,9 +44,9 @@ class _transactions extends \IPS\Dispatcher\Controller
protected function manage()
{
/* Create Table */
$table = \IPS\nexus\Transaction::table( array(), \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=transactions' ), 't' );
$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(
'tstatus_hold' => array( 't_status=?', 'hold' ),
'tstatus_hold' => array( '( t_status=? OR t_status=? )', \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW ),
);
$table->advancedSearch = array(
't_id' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
@@ -106,18 +106,21 @@ class _transactions extends \IPS\Dispatcher\Controller
$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 ) ) )
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\nexus\Transaction::STATUS_GATEWAY_PENDING ) ) )
{
\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
) );
if( $transaction->member )
{
$transaction->member->log( 'transaction', array(
'type' => 'status',
'status' => \IPS\nexus\Transaction::STATUS_PAID,
'id' => $transaction->id
) );
}
/* Do it */
try
{
@@ -183,22 +186,28 @@ class _transactions extends \IPS\Dispatcher\Controller
/* Create a support request? */
if ( \IPS\Settings::i()->nexus_revw_sa != -1 )
{
$extraData = array();
if ( $transaction->member->member_id )
{
$extraData['member'] = $transaction->member->member_id;
}
else
{
$extraData['email'] = $transaction->invoice->guest_data['member']['email'];
}
$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
);
$extraData['stock_action'] = \IPS\Settings::i()->nexus_revw_sa;
$_SESSION["wizard-{$key}-data"] = $extraData;
$_SESSION["wizard-{$key}-step"] = 'request_details';
}
else
{
$_SESSION["wizard-{$key}-data"] = array(
'member' => $transaction->member->member_id,
);
$_SESSION["wizard-{$key}-data"] = $extraData;
if ( count( \IPS\nexus\Support\StockAction::roots() ) )
{
$_SESSION["wizard-{$key}-step"] = 'stock_action';
@@ -240,7 +249,7 @@ class _transactions extends \IPS\Dispatcher\Controller
$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 ) ) ) )
if ( !in_array( $transaction->status, array( \IPS\nexus\Transaction::STATUS_PENDING, \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, '' );
}
@@ -248,7 +257,7 @@ class _transactions extends \IPS\Dispatcher\Controller
/* Void it */
try
{
$transaction->method->void( $transaction );
$transaction->void( $transaction );
}
catch ( \Exception $e )
{
@@ -257,18 +266,6 @@ class _transactions extends \IPS\Dispatcher\Controller
\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();
@@ -320,7 +317,7 @@ class _transactions extends \IPS\Dispatcher\Controller
/* 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' ) );
$form->add( new \IPS\Helpers\Form\Number( 'refund_amount', ( $transaction->status === \IPS\nexus\Transaction::STATUS_PART_REFUNDED ? $transaction->amount->amount->subtract( $transaction->partial_refund->amount ) : 0 ), TRUE, array( 'unlimited' => 0, 'unlimitedLang' => \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) ), 'max' => (string) $transaction->amount->amount->subtract( $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(
@@ -388,6 +385,9 @@ class _transactions extends \IPS\Dispatcher\Controller
{
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_delete' );
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
/* Load Transaction */
try
{
@@ -402,11 +402,18 @@ class _transactions extends \IPS\Dispatcher\Controller
$transaction->delete();
/* Log it */
$transaction->member->log( 'transaction', array(
'type' => 'delete',
'id' => $transaction->id,
'method' => $transaction->method->id
) );
try
{
$transaction->member->log( 'transaction', array(
'type' => 'delete',
'id' => $transaction->id,
'method' => $transaction->method->id
) );
}
catch ( \OutOfRangeException $e )
{
// If the member no longer exists, we just won't log it
}
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions') );