Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -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 )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user