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

@@ -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 )
{