Version 4.3.6

This commit is contained in:
Neo committed 2025-12-19 05:49:12 -08:00
1 parent fe1acf984a
commit 1a0c7fd3c2
609 files changed
+14707 -5726

No files matched your search

@@ -291,7 +291,7 @@ class _view extends \IPS\Dispatcher\Controller
'note_date' => time(),
) );
\IPS\File::claimAttachments( "nexus-note-{$this->member->member_id}-new", $this->member->id, $noteId, 'note' );
\IPS\File::claimAttachments( "nexus-note-{$this->member->member_id}-new", $this->member->member_id, $noteId, 'note' );
$this->member->log( 'note', 'added' );
}
@@ -434,6 +434,7 @@ class _view extends \IPS\Dispatcher\Controller
*/
public function addCard()
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
$form = \IPS\nexus\Customer\CreditCard::create( $this->member );
if ( $form instanceof \IPS\nexus\Customer\CreditCard )
{
@@ -619,7 +620,7 @@ class _view extends \IPS\Dispatcher\Controller
'do' => 'void',
'process' => 1,
'trans' => $values['void_refund_transactions'],
'ba' => $values['void_cancel_billing_agreements'],
'ba' => isset( $values['void_cancel_billing_agreements'] ) ? $values['void_cancel_billing_agreements'] : FALSE ,
'purch' => $values['void_cancel_purchases'],
) ), function( $data ) use ( $member )
{
@@ -55,11 +55,7 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
{
$requireBillingOptions['domain'] = 'nexus_require_billing_domain';
}
if ( \IPS\Settings::i()->nexus_subs_enabled and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscription_packages' )->first() )
{
$requireBillingOptions['subscriptions'] = 'nexus_require_billing_subscriptions';
}
$requireBillingOptions['other'] = 'nexus_require_billing_other';
$form = new \IPS\Helpers\Form;
@@ -397,6 +397,7 @@ class _invoices extends \IPS\Dispatcher\Controller
}
/* Display form */
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
return $form;
}
@@ -583,12 +584,12 @@ class _invoices extends \IPS\Dispatcher\Controller
/* What refund options are available? */
$method = $transaction->method;
$refundMethods = array();
$refundMethodToggles = array( 'credit' => array( $transaction->id . '_refund_amount' ) );
$refundMethodToggles = array( 'none' => array( $transaction->id . '_refund_reverse_credit' ) );
$refundReasons = array();
if ( $method and $method::SUPPORTS_REFUNDS )
{
$refundMethods['gateway'] = $method->_title;
$refundMethodToggles['gateway'] = array();
$refundMethods['gateway'] = 'transaction_refund';
$refundMethodToggles['gateway'] = array( $transaction->id . '_refund_reverse_credit' );
if ( $method::SUPPORTS_PARTIAL_REFUNDS )
{
$refundMethodToggles['gateway'][] = $transaction->id . '_refund_amount';
@@ -598,7 +599,11 @@ class _invoices extends \IPS\Dispatcher\Controller
$refundMethodToggles['gateway'][] = $transaction->id . '_refund_reason';
}
}
$refundMethods['credit'] = 'refund_method_credit';
if ( $transaction->credit->amount->compare( $transaction->amount->amount ) === -1 )
{
$refundMethods['credit'] = 'refund_method_credit';
$refundMethodToggles['credit'][] = $transaction->id . '_refund_credit_amount';
}
$refundMethods['none'] = 'refund_method_none';
/* How do we want to refund? */
@@ -613,9 +618,78 @@ class _invoices extends \IPS\Dispatcher\Controller
}
/* Partial refund? */
$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 );
if ( $method and $method::SUPPORTS_REFUNDS and $method::SUPPORTS_PARTIAL_REFUNDS )
{
$field = new \IPS\Helpers\Form\Number( $transaction->id . '_refund_amount', 0, TRUE, array(
'unlimited' => 0,
'unlimitedLang' => (
$transaction->partial_refund->amount->isGreaterThanZero()
? \IPS\Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array(
new \IPS\nexus\Money( $transaction->amount->amount->subtract( $transaction->partial_refund->amount ), $transaction->currency ) )
) )
: \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 );
if ( $transaction->credit->amount->isGreaterThanZero() )
{
\IPS\Member::loggedIn()->language()->words[ $transaction->id . '_refund_amount_desc' ] = sprintf( \IPS\Member::loggedIn()->language()->get('refund_amount_descwarn'), $transaction->credit );
}
}
if ( $transaction->credit->amount->compare( $transaction->amount->amount ) === -1 )
{
$field = new \IPS\Helpers\Form\Number( $transaction->id . '_refund_credit_amount', 0, TRUE, array(
'unlimited' => 0,
'unlimitedLang' => (
$transaction->credit->amount->isGreaterThanZero()
? \IPS\Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array(
new \IPS\nexus\Money( $transaction->amount->amount->subtract( $transaction->credit->amount ), $transaction->currency ) )
) )
: \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) )
),
'max' => (string) $transaction->amount->amount->subtract( $transaction->credit->amount ),
'decimals' => TRUE
), NULL, NULL, $transaction->amount->currency, $transaction->id . '_refund_credit_amount' );
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'refund_credit_amount' );
$form->add( $field );
if ( $transaction->partial_refund->amount->isGreaterThanZero() )
{
\IPS\Member::loggedIn()->language()->words[ $transaction->id . '_refund_credit_amount_desc' ] = sprintf( \IPS\Member::loggedIn()->language()->get('refund_credit_amount_descwarn'), $transaction->partial_refund );
}
}
/* Reverse credit? */
if ( $transaction->credit->amount->isGreaterThanZero() )
{
$field = new \IPS\Helpers\Form\YesNo( $transaction->id . '_refund_reverse_credit', TRUE, TRUE, array( 'togglesOn' => array( "form_{$transaction->id}_refund_reverse_credit_warning" ) ), NULL, NULL, NULL, $transaction->id . '_refund_reverse_credit' );
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'refund_reverse_credit', FALSE, array( 'sprintf' => array( $transaction->credit ) ) );
\IPS\Member::loggedIn()->language()->words[ $transaction->id . '_refund_reverse_credit_desc' ] = \IPS\Member::loggedIn()->language()->addToStack( 'refund_reverse_credit_desc' );
$form->add( $field );
$credits = $transaction->member->cm_credits;
if ( $credits[ $transaction->amount->currency ]->amount->compare( $transaction->credit->amount ) === -1 )
{
\IPS\Member::loggedIn()->language()->words[ $transaction->id . '_refund_reverse_credit_warning' ] = \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_remove_neg' );
}
}
/* Billing Agreement? */
if ( $billingAgreement = $transaction->billing_agreement )
{
$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' );
\IPS\Member::loggedIn()->language()->words[ $transaction->id . '_refund_cancel_billing_agreement_desc' ] = \IPS\Member::loggedIn()->language()->addToStack( 'refund_cancel_billing_agreement_desc' );
if ( !\IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( 't_billing_agreement=? AND t_id<?', $billingAgreement->id, $transaction->id ) )->first() )
{
\IPS\Member::loggedIn()->language()->words[ $transaction->id . '_refund_cancel_billing_agreement_warning' ] = \IPS\Member::loggedIn()->language()->addToStack( 'refund_cancel_billing_agreement_warning' );
}
$form->add( $field );
}
}
}
@@ -655,9 +729,41 @@ class _invoices extends \IPS\Dispatcher\Controller
{
foreach ( $transactions as $transaction )
{
/* Handle billing agreement */
if ( $transaction->billing_agreement )
{
if ( isset( $values[ $transaction->id . '_refund_cancel_billing_agreement' ] ) and $values[ $transaction->id . '_refund_cancel_billing_agreement' ] )
{
try
{
$transaction->billing_agreement->cancel();
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_cancel_error', '3X190/G', 500, '', array(), $e->getMessage() );
}
}
}
/* Reverse credit */
if ( $values[ $transaction->id . '_refund_method' ] !== 'credit' and isset( $values[ $transaction->id . '_refund_reverse_credit' ] ) and $values[ $transaction->id . '_refund_reverse_credit' ] )
{
$transaction->reverseCredit();
}
/* Refund */
try
{
$transaction->refund( $values[ $transaction->id . '_refund_method' ], $values[ $transaction->id . '_refund_amount' ], isset( $values[ $transaction->id . '_refund_reason' ] ) ? $values[ $transaction->id . '_refund_reason' ] : NULL );
$amount = NULL;
if ( $values[ $transaction->id . '_refund_method' ] === 'gateway' and isset( $values[ $transaction->id . '_refund_amount' ] ) )
{
$amount = $values[ $transaction->id . '_refund_amount' ];
}
elseif ( $values[ $transaction->id . '_refund_method' ] === 'credit' and isset( $values[ $transaction->id . '_refund_credit_amount' ] ) )
{
$amount = $values[ $transaction->id . '_refund_credit_amount' ];
}
$transaction->refund( $values[ $transaction->id . '_refund_method' ], $amount, isset( $values[ $transaction->id . '_refund_reason' ] ) ? $values[ $transaction->id . '_refund_reason' ] : NULL );
}
catch ( \LogicException $e )
{
@@ -308,12 +308,12 @@ class _transactions extends \IPS\Dispatcher\Controller
/* What are the refund methods? */
$refundMethods = array();
$refundMethodToggles = array( 'credit' => array( 'refund_amount' ) );
$refundMethodToggles = array( 'none' => array( 'refund_reverse_credit' ) );
$refundReasons = array();
if ( $method and $method::SUPPORTS_REFUNDS )
{
$refundMethods['gateway'] = $method->_title;
$refundMethodToggles['gateway'] = array();
$refundMethods['gateway'] = 'transaction_refund';
$refundMethodToggles['gateway'] = array( 'refund_reverse_credit' );
if ( $method::SUPPORTS_PARTIAL_REFUNDS )
{
$refundMethodToggles['gateway'][] = 'refund_amount';
@@ -323,7 +323,11 @@ class _transactions extends \IPS\Dispatcher\Controller
$refundMethodToggles['gateway'][] = 'refund_reason';
}
}
$refundMethods['credit'] = 'refund_method_credit';
if ( $transaction->credit->amount->compare( $transaction->amount->amount ) === -1 )
{
$refundMethods['credit'] = 'refund_method_credit';
$refundMethodToggles['credit'][] = 'refund_credit_amount';
}
$refundMethods['none'] = 'refund_method_none';
/* Build form */
@@ -333,16 +337,57 @@ class _transactions extends \IPS\Dispatcher\Controller
{
$form->add( new \IPS\Helpers\Form\Radio( 'refund_reason', NULL, FALSE, array( 'options' => $refundReasons ), NULL, NULL, NULL, 'refund_reason' ) );
}
$form->add( new \IPS\Helpers\Form\Number( 'refund_amount', 0, TRUE, array(
'unlimited' => 0,
'unlimitedLang' => (
$transaction->status === \IPS\nexus\Transaction::STATUS_PART_REFUNDED
? \IPS\Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array( new \IPS\nexus\Money( $transaction->amount->amount->subtract( $transaction->partial_refund->amount ), $transaction->currency ) ) ) )
: \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 ( $method and $method::SUPPORTS_REFUNDS and $method::SUPPORTS_PARTIAL_REFUNDS )
{
$form->add( new \IPS\Helpers\Form\Number( 'refund_amount', 0, TRUE, array(
'unlimited' => 0,
'unlimitedLang' => (
$transaction->partial_refund->amount->isGreaterThanZero()
? \IPS\Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array(
new \IPS\nexus\Money( $transaction->amount->amount->subtract( $transaction->partial_refund->amount ), $transaction->currency ) )
) )
: \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->credit->amount->isGreaterThanZero() )
{
\IPS\Member::loggedIn()->language()->words['refund_amount_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get('refund_amount_descwarn'), $transaction->credit );
}
}
if ( $transaction->credit->amount->compare( $transaction->amount->amount ) === -1 )
{
$form->add( new \IPS\Helpers\Form\Number( 'refund_credit_amount', 0, TRUE, array(
'unlimited' => 0,
'unlimitedLang' => (
$transaction->credit->amount->isGreaterThanZero()
? \IPS\Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array(
new \IPS\nexus\Money( $transaction->amount->amount->subtract( $transaction->credit->amount ), $transaction->currency ) )
) )
: \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) )
),
'max' => (string) $transaction->amount->amount->subtract( $transaction->credit->amount ),
'decimals' => TRUE
), NULL, NULL, $transaction->amount->currency, 'refund_credit_amount' ) );
if ( $transaction->partial_refund->amount->isGreaterThanZero() )
{
\IPS\Member::loggedIn()->language()->words['refund_credit_amount_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get('refund_credit_amount_descwarn'), $transaction->partial_refund );
}
}
if ( $transaction->credit->amount->isGreaterThanZero() )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'refund_reverse_credit', TRUE, TRUE, array( 'togglesOn' => array( 'form_refund_reverse_credit_warning' ) ), NULL, NULL, NULL, 'refund_reverse_credit' ) );
\IPS\Member::loggedIn()->language()->words['refund_reverse_credit'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'refund_reverse_credit' ), $transaction->credit );
$credits = $transaction->member->cm_credits;
if ( $credits[ $transaction->amount->currency ]->amount->compare( $transaction->credit->amount ) === -1 )
{
\IPS\Member::loggedIn()->language()->words['refund_reverse_credit_warning'] = \IPS\Member::loggedIn()->language()->addToStack( 'account_credit_remove_neg' );
}
}
if ( $transaction->invoice !== NULL and $transaction->invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
{
$field = new \IPS\Helpers\Form\Radio( 'refund_invoice_status', \IPS\nexus\Invoice::STATUS_PENDING, TRUE, array(
@@ -359,14 +404,55 @@ class _transactions extends \IPS\Dispatcher\Controller
$field->warningBox = \IPS\Theme::i()->getTemplate('invoices')->unpaidConsequences( $transaction->invoice );
$form->add( $field );
}
if ( $billingAgreement = $transaction->billing_agreement )
{
$form->add( new \IPS\Helpers\Form\YesNo( 'refund_cancel_billing_agreement', TRUE, NULL, array( 'togglesOff' => array( 'form_refund_cancel_billing_agreement_warning' ) ) ) );
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( 't_billing_agreement=? AND t_id<?', $billingAgreement->id, $transaction->id ) )->first() )
{
unset( \IPS\Member::loggedIn()->language()->words['refund_cancel_billing_agreement_warning'] );
}
}
/* Handle submissions */
if ( $values = $form->values() )
{
/* Handle billing agreement */
if ( $transaction->billing_agreement )
{
if ( isset( $values['refund_cancel_billing_agreement'] ) and $values['refund_cancel_billing_agreement'] )
{
try
{
$transaction->billing_agreement->cancel();
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'billing_agreement_cancel_error', '3X186/G', 500, '', array(), $e->getMessage() );
}
}
}
/* Reverse credit */
if ( $values['refund_method'] !== 'credit' and isset( $values['refund_reverse_credit'] ) and $values['refund_reverse_credit'] )
{
$transaction->reverseCredit();
}
/* Refund */
try
{
$transaction->refund( $values['refund_method'], $values['refund_amount'], isset( $values['refund_reason'] ) ? $values['refund_reason'] : NULL );
$amount = NULL;
if ( $values['refund_method'] === 'gateway' and isset( $values['refund_amount'] ) )
{
$amount = $values['refund_amount'];
}
elseif ( $values['refund_method'] === 'credit' and isset( $values['refund_credit_amount'] ) )
{
$amount = $values['refund_credit_amount'];
}
$transaction->refund( $values['refund_method'], $amount, isset( $values['refund_reason'] ) ? $values['refund_reason'] : NULL );
}
catch ( \LogicException $e )
{
@@ -82,7 +82,7 @@ class _income extends \IPS\Dispatcher\Controller
array(),
$activeTab
);
$chart->where[] = array( '( t_status=? OR t_status=? )', \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED );
$chart->where[] = array( '( t_status=? OR t_status=? ) AND t_method>0', \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED );
if ( $activeTab === 'totals' )
{