Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,30 +12,47 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DomainException;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Customer\BillingAgreement;
|
||||
use IPS\nexus\Gateway\PayPal\Exception;
|
||||
use IPS\nexus\Purchase;
|
||||
use IPS\nexus\Transaction;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Billing Agreements
|
||||
*/
|
||||
class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
class billingagreements extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'billingagreements_view' );
|
||||
Dispatcher::i()->checkAcpPermission( 'billingagreements_view' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -44,12 +61,12 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
|
||||
$billingAgreement = BillingAgreement::load( Request::i()->id );
|
||||
|
||||
if ( !$billingAgreement->canceled and $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
|
||||
{
|
||||
@@ -58,13 +75,13 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
$billingAgreement->save();
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X320/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X320/1', 404, '' );
|
||||
}
|
||||
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error_public', '4X320/9', 500, 'billing_agreement_error', array(), $e->getName() );
|
||||
Output::i()->error( 'billing_agreement_error_public', '4X320/9', 500, 'billing_agreement_error', array(), $e->getName() );
|
||||
}
|
||||
|
||||
/* Show */
|
||||
@@ -72,20 +89,20 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/* Purchases */
|
||||
$purchases = NULL;
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) and ( !isset( \IPS\Request::i()->table ) ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'purchases_view' ) and ( !isset( Request::i()->table ) ) )
|
||||
{
|
||||
$purchases = \IPS\nexus\Purchase::tree( $billingAgreement->acpUrl(), array( array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'ba' );
|
||||
$purchases = 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 ) ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_manage' ) and ( !isset( 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 = Transaction::table( array( array( 't_billing_agreement=? AND t_status<>?', $billingAgreement->id, Transaction::STATUS_PENDING ) ), $billingAgreement->acpUrl(), 'ba' );
|
||||
$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 ] );
|
||||
}
|
||||
@@ -93,27 +110,27 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Action Buttons */
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'billingagreements_manage' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'billingagreements_manage' ) )
|
||||
{
|
||||
if ( $billingAgreement->status() == $billingAgreement::STATUS_ACTIVE )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['refresh'] = array(
|
||||
Output::i()->sidebar['actions']['refresh'] = array(
|
||||
'icon' => 'refresh',
|
||||
'title' => 'billing_agreement_check',
|
||||
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'refresh' ) )->csrf(),
|
||||
'data' => array( 'confirm' => '' )
|
||||
);
|
||||
|
||||
\IPS\Output::i()->sidebar['actions']['suspend'] = array(
|
||||
Output::i()->sidebar['actions']['suspend'] = array(
|
||||
'icon' => 'times',
|
||||
'title' => 'billing_agreement_suspend',
|
||||
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'suspend' ) )->csrf(),
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('billing_agreement_suspend_confirm') )
|
||||
'data' => array( 'confirm' => '', 'confirmSubMessage' => Member::loggedIn()->language()->addToStack('billing_agreement_suspend_confirm') )
|
||||
);
|
||||
}
|
||||
elseif ( $billingAgreement->status() == $billingAgreement::STATUS_SUSPENDED )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['reactivate'] = array(
|
||||
Output::i()->sidebar['actions']['reactivate'] = array(
|
||||
'icon' => 'check',
|
||||
'title' => 'billing_agreement_reactivate',
|
||||
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'reactivate' ) )->csrf(),
|
||||
@@ -122,7 +139,7 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
if ( $billingAgreement->status() != $billingAgreement::STATUS_CANCELED )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['cancel'] = array(
|
||||
Output::i()->sidebar['actions']['cancel'] = array(
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'billing_agreement_cancel',
|
||||
'link' => $billingAgreement->acpUrl()->setQueryString( array( 'do' => 'act', 'act' => 'cancel' ) )->csrf(),
|
||||
@@ -131,16 +148,16 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\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 );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'billing_agreement_id', FALSE, array( 'sprintf' => array( $billingAgreement->gw_id ) ) );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'billingagreements' )->view( $billingAgreement, $purchases, $transactions );
|
||||
}
|
||||
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/2', 500, '', array(), $e->getName() );
|
||||
Output::i()->error( 'billing_agreement_error', '1X320/2', 500, '', array(), $e->getName() );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
catch ( DomainException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/3', 500 );
|
||||
Output::i()->error( 'billing_agreement_error', '1X320/3' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,18 +166,18 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconcile()
|
||||
public function reconcile() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
|
||||
$billingAgreement = BillingAgreement::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X320/5', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X320/5', 404, '' );
|
||||
}
|
||||
|
||||
/* Reconcile */
|
||||
@@ -169,15 +186,15 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
$billingAgreement->next_cycle = $billingAgreement->nextPaymentDate();
|
||||
$billingAgreement->save();
|
||||
|
||||
\IPS\Output::i()->redirect( $billingAgreement->acpUrl() );
|
||||
Output::i()->redirect( $billingAgreement->acpUrl() );
|
||||
}
|
||||
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/6', 500, '', array(), $e->getName() );
|
||||
Output::i()->error( 'billing_agreement_error', '1X320/6', 500, '', array(), $e->getName() );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
catch ( DomainException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/7', 500 );
|
||||
Output::i()->error( 'billing_agreement_error', '1X320/7' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,25 +203,25 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function act()
|
||||
public function act() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Check act */
|
||||
$act = \IPS\Request::i()->act;
|
||||
if ( !\in_array( $act, array( 'suspend', 'reactivate', 'cancel', 'refresh' ) ) )
|
||||
$act = Request::i()->act;
|
||||
if ( !in_array( $act, array( 'suspend', 'reactivate', 'cancel', 'refresh' ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '3X320/8', 403, '' );
|
||||
Output::i()->error( 'node_error', '3X320/8', 403, '' );
|
||||
}
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( \IPS\Request::i()->id );
|
||||
$billingAgreement = BillingAgreement::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X320/8', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X320/8', 404, '' );
|
||||
}
|
||||
|
||||
/* Perform Action */
|
||||
@@ -212,15 +229,15 @@ class _billingagreements extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$billingAgreement->$act();
|
||||
|
||||
\IPS\Output::i()->redirect( $billingAgreement->acpUrl() );
|
||||
Output::i()->redirect( $billingAgreement->acpUrl() );
|
||||
}
|
||||
catch ( \IPS\nexus\Gateway\PayPal\Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/9', 500, '', array(), $e->getName() );
|
||||
Output::i()->error( 'billing_agreement_error', '1X320/9', 500, '', array(), $e->getName() );
|
||||
}
|
||||
catch ( \DomainException $e )
|
||||
catch ( DomainException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_error', '1X320/A', 500 );
|
||||
Output::i()->error( 'billing_agreement_error', '1X320/A' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,30 +12,47 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Form\Money;
|
||||
use IPS\Output;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use function count;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkout Settings
|
||||
*/
|
||||
class _checkoutsettings extends \IPS\Dispatcher\Controller
|
||||
class checkoutsettings extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'checkout_settings' );
|
||||
Dispatcher::i()->checkAcpPermission( 'checkout_settings' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -44,32 +61,32 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
$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( Settings::i()->nexus_gift_vouchers, TRUE ) and count( $giftVouchers ) ) or Settings::i()->nexus_gift_vouchers_free )
|
||||
{
|
||||
$requireBillingOptions['giftvoucher'] = 'nexus_require_billing_gift';
|
||||
}
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_donate_goals' )->first() )
|
||||
if ( Db::i()->select( 'COUNT(*)', 'nexus_donate_goals' )->first() )
|
||||
{
|
||||
$requireBillingOptions['donation'] = 'nexus_require_billing_donation';
|
||||
}
|
||||
|
||||
if ( \IPS\Settings::i()->nexus_subs_enabled and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_member_subscription_packages' )->first() )
|
||||
if ( Settings::i()->nexus_subs_enabled and 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;
|
||||
$form = new Form;
|
||||
$form->addHeader( 'checkout_settings' );
|
||||
$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(
|
||||
$form->add( new CheckboxSet( 'nexus_require_billing', explode( ',', Settings::i()->nexus_require_billing ), FALSE, array( 'options' => $requireBillingOptions ) ) );
|
||||
$form->add( new YesNo( 'nexus_split_payments_on', Settings::i()->nexus_split_payments != -1, FALSE, array( 'togglesOn' => array( 'nexus_split_payments' ) ) ) );
|
||||
$form->add( new Money( 'nexus_split_payments', Settings::i()->nexus_split_payments ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_split_payments' ) );
|
||||
$form->add( new Radio( 'nexus_tac', Settings::i()->nexus_tac, FALSE, array(
|
||||
'options' => array(
|
||||
'none' => 'nexus_tac_none',
|
||||
'button' => 'nexus_tac_button',
|
||||
@@ -80,26 +97,26 @@ class _checkoutsettings extends \IPS\Dispatcher\Controller
|
||||
'checkbox' => array( 'nexus_tac_link' )
|
||||
)
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'nexus_tac_link', \IPS\Settings::i()->nexus_tac_link, FALSE, array(), NULL, NULL, NULL, 'nexus_tac_link' ) );
|
||||
$form->add( new Form\Url( 'nexus_tac_link', Settings::i()->nexus_tac_link, FALSE, array(), NULL, NULL, NULL, 'nexus_tac_link' ) );
|
||||
$form->addHeader( 'nexus_checkreg' );
|
||||
$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 YesNo( 'nexus_checkreg_usernames', Settings::i()->nexus_checkreg_usernames ) );
|
||||
$form->add( new YesNo( 'nexus_checkreg_captcha', Settings::i()->nexus_checkreg_captcha ) );
|
||||
if ( Settings::i()->reg_auth_type != 'none' )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_checkreg_validate', \IPS\Settings::i()->nexus_checkreg_validate ) );
|
||||
$form->add( new YesNo( 'nexus_checkreg_validate', 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;
|
||||
unset( $values['nexus_split_payments_on'] );
|
||||
$values['nexus_require_billing'] = \count( $values['nexus_require_billing'] ) ? implode( ',', $values['nexus_require_billing'] ) : 'none';
|
||||
$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' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=checkoutsettings' ) );
|
||||
Session::i()->log( 'acplogs__checkout_settings' );
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=checkoutsettings' ) );
|
||||
}
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('checkout_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('checkout_settings');
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -13,34 +13,48 @@ namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form\Checkbox;
|
||||
use IPS\Helpers\Form\Matrix;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
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' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currencies
|
||||
*/
|
||||
class _currencies extends \IPS\Dispatcher\Controller
|
||||
class currencies extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'currencies_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'currencies_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -49,23 +63,23 @@ class _currencies extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
$languages = \IPS\Lang::languages();
|
||||
$languages = Lang::languages();
|
||||
|
||||
$matrix = new \IPS\Helpers\Form\Matrix;
|
||||
$matrix = new Matrix;
|
||||
$matrix->squashFields = FALSE; // This has issues with select fields
|
||||
$matrix->langPrefix = 'currency_';
|
||||
$matrix->columns = array(
|
||||
'code' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value, FALSE, array( 'minLength' => 3, 'maxLength' => 3, 'placeholder' => 'USD' ) );
|
||||
return new Text( $key, $value, FALSE, array( 'minLength' => 3, 'maxLength' => 3, 'placeholder' => 'USD' ) );
|
||||
},
|
||||
'default' => function( $key, $value, $data ) use ( $languages )
|
||||
{
|
||||
if ( \count( $languages ) === 1 )
|
||||
if ( count( $languages ) === 1 )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Checkbox( $key, $value );
|
||||
return new Checkbox( $key, $value );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -75,13 +89,13 @@ class _currencies extends \IPS\Dispatcher\Controller
|
||||
$options[ $v->id ] = $v->_title;
|
||||
}
|
||||
|
||||
return new \IPS\Helpers\Form\Select( $key, $value, FALSE, array( 'options' => $options, 'multiple' => TRUE ) );
|
||||
return new Select( $key, $value, FALSE, array( 'options' => $options, 'multiple' => TRUE ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$warnings = '';
|
||||
if ( $currencies = json_decode( \IPS\Settings::i()->nexus_currency, TRUE ) )
|
||||
if ( $currencies = json_decode( Settings::i()->nexus_currency, TRUE ) )
|
||||
{
|
||||
foreach ( $currencies as $code => $defaults )
|
||||
{
|
||||
@@ -92,124 +106,63 @@ class _currencies extends \IPS\Dispatcher\Controller
|
||||
|
||||
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' );
|
||||
$warnings .= Theme::i()->getTemplate( 'global', 'core', 'global' )->message( Member::loggedIn()->language()->addToStack( 'currency_code_invalid', FALSE, array( 'sprintf' => array( $code ) ) ), 'warning' );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$matrix->rows[] = array(
|
||||
'code' => \IPS\Settings::i()->nexus_currency,
|
||||
'default' => \count( $languages ) === 1 ? TRUE : array_keys( $languages )
|
||||
'code' => Settings::i()->nexus_currency,
|
||||
'default' => count( $languages ) === 1 ? TRUE : array_keys( $languages )
|
||||
);
|
||||
}
|
||||
|
||||
$currencies = json_decode( \IPS\Settings::i()->nexus_currency, true );
|
||||
if( empty( $currencies ) )
|
||||
{
|
||||
$currencies = \IPS\Settings::i()->nexus_currency;
|
||||
}
|
||||
$errors = $this->_checkCurrencies( $currencies );
|
||||
|
||||
|
||||
if ( $values = $matrix->values() )
|
||||
{
|
||||
$save = array();
|
||||
|
||||
$definition = \IPS\Db::i()->getTableDefinition( 'nexus_package_base_prices' );
|
||||
/* @var array $definition */
|
||||
$definition = 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(
|
||||
Db::i()->addColumn( 'nexus_package_base_prices', array(
|
||||
'name' => $data['code'],
|
||||
'type' => 'FLOAT'
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $save ) ) );
|
||||
|
||||
/* Sanity check the final result */
|
||||
$errors = $this->_checkCurrencies( $save );
|
||||
if( !$errors )
|
||||
foreach ( $definition['columns'] AS $key => $value )
|
||||
{
|
||||
\IPS\Settings::i()->changeValues( array( 'nexus_currency' => json_encode( $save ) ) );
|
||||
|
||||
foreach ( $definition['columns'] AS $key => $value )
|
||||
if ( $key === 'id' )
|
||||
{
|
||||
if ( $key === 'id' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !isset( $save[$key] ) )
|
||||
{
|
||||
\IPS\Db::i()->dropColumn( 'nexus_package_base_prices', $key );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__currencies' );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=currencies' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear the elements from the matrix so that they are forced to rebuild.
|
||||
Otherwise, it hides the last row in the table */
|
||||
$matrix->elements = null;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $errors . $matrix . $warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanity check on currency settings
|
||||
*
|
||||
* @param array|string $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _checkCurrencies( array|string $values ) : string
|
||||
{
|
||||
$errors = '';
|
||||
|
||||
/* If we have a string here, then we're good to go, we only have one currency */
|
||||
if( \is_string( $values ) )
|
||||
{
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$languages = Lang::languages();
|
||||
|
||||
foreach( array_keys( $languages ) as $langId )
|
||||
{
|
||||
$langUsed = 0;
|
||||
foreach( $values as $code => $defaults )
|
||||
{
|
||||
if( in_array( $langId, $defaults ) )
|
||||
|
||||
if ( !isset( $save[$key] ) )
|
||||
{
|
||||
$langUsed++;
|
||||
Db::i()->dropColumn( 'nexus_package_base_prices', $key );
|
||||
}
|
||||
}
|
||||
|
||||
/* If the language doesn't have a default, throw an error */
|
||||
if( !$langUsed )
|
||||
{
|
||||
$errors .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'currency_code_lang_missing', FALSE, array( 'sprintf' => array( $languages[ $langId ]->_title ) ) ), 'error' );
|
||||
}
|
||||
|
||||
/* A language can't have more than one default */
|
||||
if( $langUsed > 1 )
|
||||
{
|
||||
$errors .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'currency_code_multiple_default', false, array( 'sprintf' => array( $languages[ $langId ]->_title ) ) ), 'error' );
|
||||
}
|
||||
|
||||
Session::i()->log( 'acplogs__currencies' );
|
||||
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=currencies' ) );
|
||||
}
|
||||
|
||||
return $errors;
|
||||
|
||||
Output::i()->output = $matrix . $warnings;
|
||||
}
|
||||
}
|
||||
@@ -12,35 +12,40 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Node\Controller;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* donations
|
||||
*/
|
||||
class _donationgoals extends \IPS\Node\Controller
|
||||
class donationgoals extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Donation\Goal';
|
||||
protected string $nodeClass = 'IPS\nexus\Donation\Goal';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'donationgoals_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'donationgoals_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -12,30 +12,53 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Application;
|
||||
use IPS\DateTime;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Table\Db;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Donation\Goal;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
|
||||
use const IPS\Helpers\Table\SEARCH_MEMBER;
|
||||
use const IPS\Helpers\Table\SEARCH_NODE;
|
||||
use const IPS\Helpers\Table\SEARCH_NUMERIC;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* donations
|
||||
*/
|
||||
class _donations extends \IPS\Dispatcher\Controller
|
||||
class donations extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'donations_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'donations_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -44,18 +67,18 @@ class _donations extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'donationgoals_manage' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'donationgoals_manage' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'][] = array(
|
||||
Output::i()->sidebar['actions'][] = array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'donation_goals',
|
||||
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=donationgoals" )
|
||||
'link' => Url::internal( "app=nexus&module=payments&controller=donationgoals" )
|
||||
);
|
||||
}
|
||||
|
||||
$table = new \IPS\Helpers\Table\Db( 'nexus_donate_logs', \IPS\Http\Url::internal('app=nexus&module=payments&controller=donations') );
|
||||
$table = new Db( 'nexus_donate_logs', Url::internal('app=nexus&module=payments&controller=donations') );
|
||||
|
||||
$table->include = array( 'dl_goal', 'dl_amount', 'dl_member', 'dl_invoice', 'dl_date' );
|
||||
$table->parsers = array(
|
||||
@@ -63,24 +86,24 @@ class _donations extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Donation\Goal::load( $val )->_title;
|
||||
return Goal::load( $val )->_title;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
},
|
||||
'dl_member' => function ( $val )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('global')->userLink( \IPS\Member::load( $val ) );
|
||||
return Theme::i()->getTemplate('global')->userLink( Member::load( $val ) );
|
||||
},
|
||||
'dl_amount' => function( $val, $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
return (string) new \IPS\nexus\Money( $val, \IPS\nexus\Donation\Goal::load( $row['dl_goal'] )->currency );
|
||||
return (string) new Money( $val, Goal::load( $row['dl_goal'] )->currency );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception )
|
||||
{
|
||||
return $val;
|
||||
}
|
||||
@@ -89,32 +112,38 @@ class _donations extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate('invoices')->link( \IPS\nexus\Invoice::load( $val ), TRUE );
|
||||
return Theme::i()->getTemplate('invoices')->link( Invoice::load( $val ), TRUE );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
},
|
||||
'dl_date' => function( $val )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val );
|
||||
return DateTime::ts( $val );
|
||||
}
|
||||
);
|
||||
|
||||
foreach ( \IPS\nexus\Donation\Goal::roots() as $goal )
|
||||
foreach ( Goal::roots() as $goal )
|
||||
{
|
||||
$table->filters[ "nexus_donategoal_{$goal->_id}" ] = "dl_goal={$goal->_id}";
|
||||
}
|
||||
$table->advancedSearch = array(
|
||||
'dl_goal' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => '\IPS\nexus\Donation\Goal' ) ),
|
||||
'dl_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
'dl_amount' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
'dl_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
'dl_goal' => array( SEARCH_NODE, array( 'class' => '\IPS\nexus\Donation\Goal' ) ),
|
||||
'dl_member' => SEARCH_MEMBER,
|
||||
'dl_amount' => SEARCH_NUMERIC,
|
||||
'dl_date' => SEARCH_DATE_RANGE,
|
||||
);
|
||||
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_donations');
|
||||
|
||||
$message = '';
|
||||
if ( ! count( Widget::usedWhere( Application::load('nexus'), 'donations' ) ) )
|
||||
{
|
||||
/* Nudge the admin to add the sidebar block */
|
||||
$message = Theme::i()->getTemplate('forms', 'core' )->blurb( 'commerce_donation_goals_widget_not_in_use' );
|
||||
}
|
||||
|
||||
Output::i()->output = $message . $table;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__nexus_payments_donations');
|
||||
}
|
||||
}
|
||||
@@ -12,30 +12,42 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Stack;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Output;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification Copy Settings
|
||||
*/
|
||||
class _emails extends \IPS\Dispatcher\Controller
|
||||
class emails extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'email_copies_settings' );
|
||||
Dispatcher::i()->checkAcpPermission( 'email_copies_settings' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -44,10 +56,10 @@ class _emails extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_notify_copy_types', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ), FALSE, array( 'options' => array(
|
||||
$form = new Form;
|
||||
$form->add( new CheckboxSet( 'nexus_notify_copy_types', explode( ',', Settings::i()->nexus_notify_copy_types ), FALSE, array( 'options' => array(
|
||||
'invoice_warn' => 'nexus_notify_copy_invoice_warn',
|
||||
'new_invoice' => 'nexus_notify_copy_new_invoice',
|
||||
'payment_received' => 'nexus_notify_copy_payment_received',
|
||||
@@ -57,16 +69,16 @@ class _emails extends \IPS\Dispatcher\Controller
|
||||
'payment_refunded' => 'nexus_notify_copy_payment_refunded',
|
||||
'commission_earned' => 'nexus_notify_copy_commission_earned',
|
||||
) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'nexus_notify_copy_email', explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) ) );
|
||||
$form->add( new Stack( 'nexus_notify_copy_email', explode( ',', Settings::i()->nexus_notify_copy_email ) ) );
|
||||
|
||||
if ( $form->values() )
|
||||
{
|
||||
$form->saveAsSettings();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__email_copies_setting' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=emails' ), 'saved' );
|
||||
Session::i()->log( 'acplogs__email_copies_setting' );
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=emails' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -12,45 +12,52 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anti-Fraud Rules
|
||||
*/
|
||||
class _fraud extends \IPS\Node\Controller
|
||||
class fraud extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Fraud\Rule';
|
||||
protected string $nodeClass = 'IPS\nexus\Fraud\Rule';
|
||||
|
||||
/**
|
||||
* Description can contain HTML?
|
||||
*/
|
||||
public $_descriptionHtml = TRUE;
|
||||
public bool $_descriptionHtml = TRUE;
|
||||
|
||||
/**
|
||||
* Show the "add" button in the page root rather than the table root
|
||||
*/
|
||||
protected $_addButtonInRoot = FALSE;
|
||||
protected bool $_addButtonInRoot = FALSE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'fraud_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'fraud_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -59,9 +66,9 @@ class _fraud extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
public function manage() : void
|
||||
{
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'fraud_rule_blurb', TRUE, TRUE );
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'forms', 'core' )->blurb( 'fraud_rule_blurb', TRUE, TRUE );
|
||||
|
||||
parent::manage();
|
||||
}
|
||||
|
||||
@@ -12,35 +12,52 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Wizard;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Lang;
|
||||
use IPS\nexus\Gateway;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Task;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment Gateways
|
||||
*/
|
||||
class _gateways extends \IPS\Node\Controller
|
||||
class gateways extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Gateway';
|
||||
protected string $nodeClass = 'IPS\nexus\Gateway';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'gateways_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'gateways_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -49,7 +66,7 @@ class _gateways extends \IPS\Node\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
public function _getRootButtons(): array
|
||||
{
|
||||
$buttons = parent::_getRootButtons();
|
||||
|
||||
@@ -66,39 +83,34 @@ class _gateways extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
protected function form() : void
|
||||
{
|
||||
if ( \IPS\Request::i()->id )
|
||||
if ( Request::i()->id )
|
||||
{
|
||||
return parent::form();
|
||||
parent::form();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \IPS\IN_DEV )
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'plupload/moxie.js', 'core', 'interface' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'plupload/plupload.dev.js', 'core', 'interface' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'plupload/plupload.full.min.js', 'core', 'interface' ) );
|
||||
}
|
||||
\IPS\Output::i()->output = (string) new \IPS\Helpers\Wizard( array(
|
||||
Output::i()->output = (string) new Wizard( array(
|
||||
'gateways_gateway' => function( $data )
|
||||
{
|
||||
$options = array();
|
||||
foreach ( \IPS\nexus\Gateway::gateways() as $key => $class )
|
||||
foreach ( Gateway::gateways() as $key => $class )
|
||||
{
|
||||
/* Deprecate Authorize.net, Braintree and 2Checkout don't allow them to be used for new gateways */
|
||||
if( \in_array( $key, array( 'AuthorizeNet', 'TwoCheckout', 'Braintree' ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$options[ $key ] = 'gateway__' . $key;
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'gateways_gateway', TRUE, NULL, array( 'options' => $options ) ) );
|
||||
$form = new Form;
|
||||
$form->add( new Radio( 'gateways_gateway', TRUE, NULL, array( 'options' => $options ) ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
return array( 'gateway' => $values['gateways_gateway'] );
|
||||
@@ -107,8 +119,8 @@ class _gateways extends \IPS\Node\Controller
|
||||
},
|
||||
'gateways_details' => function( $data )
|
||||
{
|
||||
$form = new \IPS\Helpers\Form('gw');
|
||||
$class = \IPS\nexus\Gateway::gateways()[ $data['gateway'] ];
|
||||
$form = new Form('gw');
|
||||
$class = Gateway::gateways()[ $data['gateway'] ];
|
||||
$obj = new $class;
|
||||
$obj->gateway = $data['gateway'];
|
||||
$obj->active = TRUE;
|
||||
@@ -128,7 +140,7 @@ class _gateways extends \IPS\Node\Controller
|
||||
{
|
||||
$settings = $obj->testSettings( $settings );
|
||||
}
|
||||
catch ( \InvalidArgumentException $e )
|
||||
catch ( InvalidArgumentException $e )
|
||||
{
|
||||
$form->error = $e->getMessage();
|
||||
return $form;
|
||||
@@ -144,14 +156,14 @@ class _gateways extends \IPS\Node\Controller
|
||||
}
|
||||
|
||||
$obj->save();
|
||||
\IPS\Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $name );
|
||||
\IPS\Session::i()->log( 'acplogs__nexus_added_gateway', array( "nexus_paymethod_{$obj->id}" => TRUE ) );
|
||||
Lang::saveCustom( 'nexus', "nexus_paymethod_{$obj->id}", $name );
|
||||
Session::i()->log( 'acplogs__nexus_added_gateway', array( "nexus_paymethod_{$obj->id}" => TRUE ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways') );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways') );
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
), \IPS\Http\Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways&do=form') );
|
||||
), Url::internal('app=nexus&module=payments&controller=paymentsettings&tab=gateways&do=form') );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,42 +172,43 @@ class _gateways extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
/* Get node */
|
||||
/* @var Gateway $nodeClass */
|
||||
$nodeClass = $this->nodeClass;
|
||||
if ( \IPS\Request::i()->subnode )
|
||||
if ( Request::i()->subnode )
|
||||
{
|
||||
$nodeClass = $nodeClass::$subnodeClass;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$node = $nodeClass::load( \IPS\Request::i()->id );
|
||||
$node = $nodeClass::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X411/1', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X411/1', 404, '' );
|
||||
}
|
||||
|
||||
/* Permission check */
|
||||
if( !$node->canDelete() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_noperm_delete', '2X411/2', 403, '' );
|
||||
Output::i()->error( 'node_noperm_delete', '2X411/2', 403, '' );
|
||||
}
|
||||
|
||||
if( $node->hasActiveBillingAgreements() )
|
||||
{
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
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' );
|
||||
Task::queue( 'nexus', 'DeletePaymentMethod', array( 'id' => $node->id ), 3, array( 'id' ) );
|
||||
Session::i()->log( 'acplog__node_deleted_c', array( $node->_title => TRUE, $node->titleForLog() => FALSE ) );
|
||||
Output::i()->redirect( $this->url->setQueryString( array( 'root' => ( $node->parent() ? $node->parent()->_id : '' ) ) ), 'deleted' );
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::delete();
|
||||
parent::delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,30 +12,36 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoice Timeline
|
||||
*/
|
||||
class _invoiceTimeline extends \IPS\Dispatcher\Controller
|
||||
class invoiceTimeline extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'invoiceTimeline.css', 'nexus', 'admin' ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('invoices')->invoiceTimeline();
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'invoiceTimeline.css', 'nexus', 'admin' ) );
|
||||
Output::i()->output = Theme::i()->getTemplate('invoices')->invoiceTimeline();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,21 +12,30 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment Settings
|
||||
*/
|
||||
class _paymentsettings extends \IPS\Dispatcher\Controller
|
||||
class paymentsettings extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Call
|
||||
@@ -36,38 +45,34 @@ class _paymentsettings extends \IPS\Dispatcher\Controller
|
||||
public function __call( $method, $args )
|
||||
{
|
||||
$tabs = array();
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'currencies_manage' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'currencies_manage' ) )
|
||||
{
|
||||
$tabs['currencies'] = 'currencies';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'gateways_manage' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'gateways_manage' ) )
|
||||
{
|
||||
$tabs['gateways'] = 'payment_methods';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'tax_manage' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'tax_manage' ) )
|
||||
{
|
||||
$tabs['tax'] = 'tax_rates';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'checkout_settings' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'checkout_settings' ) )
|
||||
{
|
||||
$tabs['checkoutsettings'] = 'checkout_settings';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'fraud_manage' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'fraud_manage' ) )
|
||||
{
|
||||
$tabs['fraud'] = 'anti_fraud_rules';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transaction_review_settings' ) )
|
||||
{
|
||||
$tabs['review'] = 'transaction_review';
|
||||
}
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'email_copies_settings' ) )
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'email_copies_settings' ) )
|
||||
{
|
||||
$tabs['emails'] = 'notification_copies';
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->tab ) and isset( $tabs[ \IPS\Request::i()->tab ] ) )
|
||||
if ( isset( Request::i()->tab ) and isset( $tabs[ Request::i()->tab ] ) )
|
||||
{
|
||||
$activeTab = \IPS\Request::i()->tab;
|
||||
$activeTab = Request::i()->tab;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -77,15 +82,15 @@ class _paymentsettings extends \IPS\Dispatcher\Controller
|
||||
|
||||
$classname = 'IPS\nexus\modules\admin\payments\\' . $activeTab;
|
||||
$class = new $classname;
|
||||
$class->url = \IPS\Http\Url::internal("app=nexus&module=payments&controller=paymentsettings&tab={$activeTab}");
|
||||
$class->url = Url::internal("app=nexus&module=payments&controller=paymentsettings&tab={$activeTab}");
|
||||
$class->execute();
|
||||
|
||||
if ( $method !== 'manage' or \IPS\Request::i()->isAjax() )
|
||||
if ( $method !== 'manage' or Request::i()->isAjax() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('payment_settings');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, \IPS\Output::i()->output, \IPS\Http\Url::internal( "app=nexus&module=payments&controller=paymentsettings" ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('payment_settings');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, Output::i()->output, Url::internal( "app=nexus&module=payments&controller=paymentsettings" ) );
|
||||
}
|
||||
}
|
||||
@@ -12,30 +12,58 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\core\AdminNotification;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\nexus\Form\Money;
|
||||
use IPS\nexus\Gateway;
|
||||
use IPS\nexus\Payout;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Task;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payouts
|
||||
*/
|
||||
class _payouts extends \IPS\Dispatcher\Controller
|
||||
class payouts extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -44,48 +72,48 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* Redirect to settings if we haven't set it up */
|
||||
if ( !\IPS\Settings::i()->nexus_payout )
|
||||
if ( !Settings::i()->nexus_payout )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' ) );
|
||||
}
|
||||
|
||||
/* Build table */
|
||||
$table = \IPS\nexus\Payout::table( array(), \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
$table = Payout::table( array(), Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_payouts');
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'payouts_settings' ) )
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__nexus_payments_payouts');
|
||||
if( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'payouts_settings' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'] = array(
|
||||
Output::i()->sidebar['actions'] = array(
|
||||
'settings' => array(
|
||||
'icon' => 'cog',
|
||||
'title' => 'account_credit_settings',
|
||||
'link' => \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' )
|
||||
'link' => Url::internal( 'app=nexus&module=payments&controller=payouts&do=settings' )
|
||||
),
|
||||
);
|
||||
|
||||
foreach ( \IPS\Db::i()->select( 'po_gateway', 'nexus_payouts', array( 'po_status=?', \IPS\nexus\Payout::STATUS_PENDING ), NULL, NULL, 'po_gateway' ) as $gateway )
|
||||
foreach ( Db::i()->select( 'po_gateway', 'nexus_payouts', array( 'po_status=?', Payout::STATUS_PENDING ), NULL, NULL, 'po_gateway' ) as $gateway )
|
||||
{
|
||||
$classname = \IPS\nexus\Gateway::payoutGateways()[ $gateway ];
|
||||
$classname = Gateway::payoutGateways()[ $gateway ];
|
||||
if ( class_exists( $classname ) and method_exists( $classname, 'massProcess' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions'][] = [
|
||||
Output::i()->sidebar['actions'][] = [
|
||||
'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 )->csrf(),
|
||||
'title' => Member::loggedIn()->language()->addToStack( 'account_credit_mass_payout', TRUE, array( 'sprintf' => array( Member::loggedIn()->language()->addToStack( 'payout__admin_' . $gateway ) ) ) ),
|
||||
'link' => Url::internal( 'app=nexus&module=payments&controller=payouts&do=massprocess&gateway=' . $gateway )->csrf(),
|
||||
'data' => [
|
||||
'confirm' => '',
|
||||
'confirmMessage' => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_title' ),
|
||||
'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_text' )
|
||||
'confirmMessage' => Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_title' ),
|
||||
'confirmSubMessage' => Member::loggedIn()->language()->addToStack( 'nexus_payout_confirm_text' )
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
Output::i()->output = (string) $table;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,20 +121,20 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function view()
|
||||
protected function view() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/2', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/2', 404, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sidebar['actions'] = $payout->buttons( 'v' );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'payout_number', FALSE, array( 'sprintf' => array( $payout->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('payouts')->view( $payout );
|
||||
Output::i()->sidebar['actions'] = $payout->buttons( 'v' );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'payout_number', FALSE, array( 'sprintf' => array( $payout->id ) ) );
|
||||
Output::i()->output = Theme::i()->getTemplate('payouts')->view( $payout );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,48 +142,48 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function process()
|
||||
protected function process() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/3', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/3', 404, '' );
|
||||
}
|
||||
|
||||
if ( $payout->status !== $payout::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/4', 403, '' );
|
||||
Output::i()->error( 'err_payout_not_pending', '1X200/4', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$payout->process();
|
||||
$payout->status = $payout->process();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X200/1', 500, '' );
|
||||
Output::i()->error( $e->getMessage(), '1X200/1', 500, '' );
|
||||
}
|
||||
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->processed_by = Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
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 ) );
|
||||
|
||||
/* If the payout was actually completed, notify the user */
|
||||
if( $payout->status == \IPS\nexus\Payout::STATUS_COMPLETE )
|
||||
if( $payout->status == Payout::STATUS_COMPLETE )
|
||||
{
|
||||
$payout->markCompleted();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use task if the payout is pending */
|
||||
$task = \IPS\Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task = Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task->enabled = TRUE;
|
||||
$task->save();
|
||||
}
|
||||
@@ -168,38 +196,39 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function massprocess()
|
||||
protected function massprocess() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
\IPS\Request::i()->confirmedDelete( 'nexus_payout_confirm_title', 'nexus_payout_confirm_text', 'nexus_payout_proceed' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_process' );
|
||||
Request::i()->confirmedDelete( 'nexus_payout_confirm_title', 'nexus_payout_confirm_text', 'nexus_payout_proceed' );
|
||||
|
||||
$classname = \IPS\nexus\Gateway::payoutGateways()[ \IPS\Request::i()->gateway ];
|
||||
$classname = Gateway::payoutGateways()[ Request::i()->gateway ];
|
||||
if ( !class_exists( $classname ) or !method_exists( $classname, 'massProcess' ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'generic_error', '2X200/8', 403, '' );
|
||||
Output::i()->error( 'generic_error', '2X200/8', 403, '' );
|
||||
}
|
||||
|
||||
$payouts = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_payouts', array( 'po_status=? AND po_gateway=?', \IPS\nexus\Payout::STATUS_PENDING, \IPS\Request::i()->gateway ) ), $classname );
|
||||
$payouts = new ActiveRecordIterator( Db::i()->select( '*', 'nexus_payouts', array( 'po_status=? AND po_gateway=?', Payout::STATUS_PENDING, Request::i()->gateway ) ), $classname );
|
||||
|
||||
try
|
||||
{
|
||||
$classname::massProcess( $payouts );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X200/9', 403, '' );
|
||||
Output::i()->error( $e->getMessage(), '1X200/9', 403, '' );
|
||||
}
|
||||
|
||||
$pending = 0;
|
||||
foreach ( $payouts as $payout )
|
||||
{
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
/* @var Payout $payout */
|
||||
$payout->processed_by = Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_processed', array( $payout->id => FALSE ) );
|
||||
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 ) );
|
||||
|
||||
/* Only do this if the payout is actually complete! */
|
||||
if( $payout->status == \IPS\nexus\Payout::STATUS_COMPLETE )
|
||||
if( $payout->status == Payout::STATUS_COMPLETE )
|
||||
{
|
||||
$payout->markCompleted();
|
||||
continue;
|
||||
@@ -211,12 +240,12 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
/* Use task if there are incomplete payouts */
|
||||
if( $pending )
|
||||
{
|
||||
$task = \IPS\Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task = Task::load( 'payoutPending', 'key', [ 'app=?', 'nexus' ] );
|
||||
$task->enabled = TRUE;
|
||||
$task->save();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,33 +253,33 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function cancel()
|
||||
protected function cancel() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_cancel' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/6', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/6', 404, '' );
|
||||
}
|
||||
|
||||
if ( $payout->status !== $payout::STATUS_PENDING )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_payout_not_pending', '1X200/5', 403, '' );
|
||||
Output::i()->error( 'err_payout_not_pending', '1X200/5', 403, '' );
|
||||
}
|
||||
|
||||
$payout->status = $payout::STATUS_CANCELED;
|
||||
$payout->completed = new \IPS\DateTime;
|
||||
$payout->processed_by = \IPS\Member::loggedIn();
|
||||
$payout->completed = new DateTime;
|
||||
$payout->processed_by = Member::loggedIn();
|
||||
$payout->save();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_cancelled', array( $payout->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__payout_cancelled', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'cancel', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
if ( \IPS\Request::i()->prompt )
|
||||
if ( Request::i()->prompt )
|
||||
{
|
||||
$credits = $payout->member->cm_credits;
|
||||
$credits[ $payout->amount->currency ]->amount = $credits[ $payout->amount->currency ]->amount->add( $payout->amount->amount );
|
||||
@@ -266,27 +295,27 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function delete()
|
||||
protected function delete() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_delete' );
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
try
|
||||
{
|
||||
$payout = \IPS\nexus\Payout::load( \IPS\Request::i()->id );
|
||||
$payout = Payout::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X200/7', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X200/7', 404, '' );
|
||||
}
|
||||
|
||||
$payout->delete();
|
||||
\IPS\Session::i()->log( 'acplogs__payout_deleted', array( $payout->id => FALSE ) );
|
||||
Session::i()->log( 'acplogs__payout_deleted', array( $payout->id => FALSE ) );
|
||||
$payout->member->log( 'payout', array( 'type' => 'dismissed', 'amount' => $payout->amount->amount, 'currency' => $payout->amount->currency, 'payout_id' => $payout->id ) );
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts') );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,18 +323,19 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function settings()
|
||||
protected function settings() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'payouts_settings' );
|
||||
Dispatcher::i()->checkAcpPermission( 'payouts_settings' );
|
||||
|
||||
$options = array();
|
||||
$toggles = array();
|
||||
$fields = array();
|
||||
foreach ( \IPS\nexus\Gateway::payoutGateways() as $key => $class )
|
||||
foreach ( Gateway::payoutGateways() as $key => $class )
|
||||
{
|
||||
$options[ $key ] = 'payout__admin_' . $key;
|
||||
$toggles[ $key ] = array( 'form_header_payout_settings' );
|
||||
|
||||
|
||||
/* @var Payout $class */
|
||||
foreach ( $class::settings() as $field )
|
||||
{
|
||||
if ( !$field->htmlId )
|
||||
@@ -319,41 +349,41 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups( TRUE, FALSE ) as $group )
|
||||
foreach ( Group::groups( TRUE, FALSE ) as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
$settings = \IPS\Settings::i()->nexus_payout ? json_decode( \IPS\Settings::i()->nexus_payout, TRUE ) : array();
|
||||
$settings = \is_array( $settings ) ? array_keys( $settings ) : array();
|
||||
$settings = Settings::i()->nexus_payout ? json_decode( Settings::i()->nexus_payout, TRUE ) : array();
|
||||
$settings = is_array( $settings ) ? array_keys( $settings ) : array();
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->addMessage('payout_description');
|
||||
$form = new Form;
|
||||
$form->addMessage('payout_description', 'ipsMessage--transparent');
|
||||
$form->addHeader('commission_settings');
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_no_commission', explode( ',', \IPS\Settings::i()->nexus_no_commission ), FALSE, array( 'multiple' => TRUE, 'options' => $groups ) ) );
|
||||
$form->add( new CheckboxSet( 'nexus_no_commission', explode( ',', Settings::i()->nexus_no_commission ), FALSE, array( 'multiple' => TRUE, 'options' => $groups ) ) );
|
||||
$form->addHeader('withdrawal_methods');
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'nexus_payout', $settings, FALSE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
$form->add( new CheckboxSet( 'nexus_payout', $settings, FALSE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
foreach ( $fields as $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
$form->addHeader('payout_settings');
|
||||
$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 Money( 'nexus_payout_min', ( Settings::i()->nexus_payout_min AND Settings::i()->nexus_payout_min != '*' ) ? json_decode( 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 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' );
|
||||
$form->add( new Custom( 'nexus_payout_maximum', NULL, FALSE, array( 'getHtml' => function( $element ) {
|
||||
$amount = new Money( 'nexus_payout_maximum[2]', ( Settings::i()->nexus_payout_max AND Settings::i()->nexus_payout_max != '*' ) ? json_decode( Settings::i()->nexus_payout_max, TRUE ) : '*', FALSE, array( 'unlimitedLang' => 'no_restriction', 'unlimitedTogglesOff' => array( 'payout_max_limited' ) ), NULL, NULL, NULL, 'nexus_payout_max' );
|
||||
$period = Settings::i()->nexus_payout_max_period ? json_decode( Settings::i()->nexus_payout_max_period, TRUE ) : array( 1, 'day' );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'payouts' )->maximumLimits( $amount->html(), (int) $period[0], $period[1] );
|
||||
return 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->add( new \IPS\Helpers\Form\YesNo( 'nexus_payout_unlimited_times', \IPS\Settings::i()->nexus_payout_unlimited_times, TRUE ) );
|
||||
$form->add( new YesNo( 'nexus_payout_approve', Settings::i()->nexus_payout_approve, FALSE, array(), NULL, NULL, NULL, 'nexus_payout_approve' ) );
|
||||
$form->add( new YesNo( 'nexus_payout_unlimited_times', Settings::i()->nexus_payout_unlimited_times, TRUE ) );
|
||||
|
||||
$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' ) ) ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_min_topup', \IPS\Settings::i()->nexus_min_topup ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_min_topup' ) );
|
||||
$form->add( new \IPS\nexus\Form\Money( 'nexus_max_credit', \IPS\Settings::i()->nexus_max_credit ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_max_credit' ) );
|
||||
$form->add( new YesNo( 'allow_topups', Settings::i()->nexus_min_topup, FALSE, array( 'togglesOn' => array( 'nexus_min_topup', 'nexus_max_credit' ) ) ) );
|
||||
$form->add( new Money( 'nexus_min_topup', Settings::i()->nexus_min_topup ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_min_topup' ) );
|
||||
$form->add( new Money( 'nexus_max_credit', Settings::i()->nexus_max_credit ?: '*', FALSE, array( 'unlimitedLang' => 'no_restriction' ), NULL, NULL, NULL, 'nexus_max_credit' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -378,8 +408,8 @@ 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_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_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'] )
|
||||
@@ -397,51 +427,51 @@ class _payouts extends \IPS\Dispatcher\Controller
|
||||
$values['nexus_no_commission'] = implode( ',', $values['nexus_no_commission'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
\IPS\Session::i()->log( 'acplogs__payout_settings' );
|
||||
Session::i()->log( 'acplogs__payout_settings' );
|
||||
|
||||
/* Remove any ACP notifications related to Payout Settings */
|
||||
foreach( \IPS\nexus\Gateway::payoutGateways() as $key => $class )
|
||||
foreach( Gateway::payoutGateways() as $key => $class )
|
||||
{
|
||||
\IPS\core\AdminNotification::remove( 'nexus', 'ConfigurationError', "po{$key}" );
|
||||
AdminNotification::remove( 'nexus', 'ConfigurationError', "po{$key}" );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts'), 'saved' );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts'), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('account_credit_settings');
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('account_credit_settings');
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Payout $payout The payout
|
||||
* @param Payout $payout The payout
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Payout $payout )
|
||||
protected function _redirect( Payout $payout ) : void
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
if ( isset( Request::i()->r ) )
|
||||
{
|
||||
switch ( mb_substr( \IPS\Request::i()->r, 0, 1 ) )
|
||||
switch ( mb_substr( Request::i()->r, 0, 1 ) )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $payout->acpUrl() );
|
||||
Output::i()->redirect( $payout->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $payout->member->acpUrl() );
|
||||
Output::i()->redirect( $payout->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', \IPS\Request::i()->filter ) );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=payouts')->setQueryString( 'filter', Request::i()->filter ) );
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=notifications') );
|
||||
Output::i()->redirect( Url::internal('app=core&module=overview&controller=notifications') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $payout->acpUrl() );
|
||||
Output::i()->redirect( $payout->acpUrl() );
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Transaction Review
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 26 Mar 2014
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction Review
|
||||
*/
|
||||
class _review extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transaction_review_settings' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function manage()
|
||||
{
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'nexus_revw_sa_on', \IPS\Settings::i()->nexus_revw_sa != -1, FALSE, array( 'togglesOn' => array( 'nexus_revw_sa' ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'nexus_revw_sa', \IPS\Settings::i()->nexus_revw_sa ?: 0, FALSE, array( 'class' => 'IPS\nexus\Support\StockAction', 'zeroVal' => 'do_not_suggest_stock_action' ), NULL, NULL, NULL, 'nexus_revw_sa' ) );
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if ( !$values['nexus_revw_sa_on'] )
|
||||
{
|
||||
$values['nexus_revw_sa'] = -1;
|
||||
}
|
||||
elseif ( $values['nexus_revw_sa'] )
|
||||
{
|
||||
$values['nexus_revw_sa'] = $values['nexus_revw_sa']->id;
|
||||
}
|
||||
unset( $values['nexus_revw_sa_on'] );
|
||||
|
||||
$form->saveAsSettings( $values );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__transaction_review_settings' );
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=paymentsettings&tab=review' ), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
}
|
||||
@@ -1,642 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Shipments
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 20 Mar 2014
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipments
|
||||
*/
|
||||
class _shipping extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'shipmethods_manage' ) )
|
||||
{
|
||||
\IPS\Output::i()->sidebar['actions']['settings'] = array(
|
||||
'title' => 'shipping_rates',
|
||||
'icon' => 'cog',
|
||||
'link' => \IPS\Http\Url::internal('app=nexus&module=payments&controller=shippingrates'),
|
||||
);
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('shipping');
|
||||
\IPS\Output::i()->output = (string) \IPS\nexus\Shipping\Order::table( \IPS\Http\Url::internal( 'app=nexus&module=payments&controller=shipping' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* View
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/1', 404, '' );
|
||||
}
|
||||
|
||||
$easyPost = NULL;
|
||||
if ( \IPS\Settings::i()->easypost_api_key )
|
||||
{
|
||||
$extra = json_decode( $shipment->extra, TRUE );
|
||||
if ( isset( $extra['shipment'] ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . $extra['shipment'] )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->get()->decodeJson();
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
/* Add Buttons */
|
||||
\IPS\Output::i()->sidebar['actions'] = $shipment->buttons( 'v' );
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = $shipment->method ? \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number_with_method', FALSE, array( 'sprintf' => array( $shipment->id, $shipment->method->_title ) ) ) : \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'shiporders' )->view( $shipment, $easyPost );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ship
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function ship()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/2', 404, '' );
|
||||
}
|
||||
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form( 'form', 'shipment_ship' );
|
||||
if ( \IPS\Settings::i()->easypost_api_key )
|
||||
{
|
||||
/* Calculate stuff */
|
||||
$weightInOz = 0;
|
||||
$lengthInInches = 0;
|
||||
$widthInInches = 0;
|
||||
$heightInInches = 0;
|
||||
foreach ( $shipment->items as $item )
|
||||
{
|
||||
$weight = new \IPS\nexus\Shipping\Weight( $item['weight']['kilograms'] );
|
||||
$weightInOz += ( $weight->float('oz') * $item['quantity'] );
|
||||
|
||||
foreach ( array( 'length', 'width', 'height' ) as $k )
|
||||
{
|
||||
$dim = new \IPS\nexus\Shipping\Length( $item[ $k ]['metres'] );
|
||||
$v = "{$k}InInches";
|
||||
$$v += ( $dim->float('in') * $item['quantity'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Method */
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'shipment_ship_method', 'easypost', TRUE, array(
|
||||
'options' => array( 'easypost' => 'shipment_ship_easypost', 'manual' => 'shipment_ship_manual' ),
|
||||
'toggles' => array(
|
||||
'easypost' => array( 'form_header_easypost_package_header', 'easypost_package', 'easypost_package_weight', 'form_header_easypost_customs_header', 'easypost_customs_details' ),
|
||||
'manual' => array( 'o_tracknumber', 'tracking_url' )
|
||||
)
|
||||
) ) );
|
||||
|
||||
/* Parcel */
|
||||
$form->addHeader( 'easypost_package_header' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'easypost_package', 'custom', NULL, array(
|
||||
'options' => array(
|
||||
'custom' => 'easypost_package_custom',
|
||||
'easypost_package_usps' => array(
|
||||
'Card' => 'easypost_package_usps_Card',
|
||||
'Letter' => 'easypost_package_usps_Letter',
|
||||
'Flat' => 'easypost_package_usps_Flat',
|
||||
'Parcel' => 'easypost_package_usps_Parcel',
|
||||
'LargeParcel' => 'easypost_package_usps_LargeParcel',
|
||||
'IrregularParcel' => 'easypost_package_usps_IrregularParcel',
|
||||
'FlatRateEnvelope' => 'easypost_package_usps_FlatRateEnvelope',
|
||||
'FlatRateLegalEnvelope' => 'easypost_package_usps_FlatRateLegalEnvelope',
|
||||
'FlatRatePaddedEnvelope' => 'easypost_package_usps_FlatRatePaddedEnvelope',
|
||||
'FlatRateGiftCardEnvelope' => 'easypost_package_usps_FlatRateGiftCardEnvelope',
|
||||
'FlatRateWindowEnvelope' => 'easypost_package_usps_FlatRateWindowEnvelope',
|
||||
'FlatRateCardboardEnvelope' => 'easypost_package_usps_FlatRateCardboardEnvelope',
|
||||
'SmallFlatRateEnvelope' => 'easypost_package_usps_SmallFlatRateEnvelope',
|
||||
'SmallFlatRateBox' => 'easypost_package_usps_SmallFlatRateBox',
|
||||
'MediumFlatRateBox' => 'easypost_package_usps_MediumFlatRateBox',
|
||||
'LargeFlatRateBox' => 'easypost_package_usps_LargeFlatRateBox',
|
||||
'RegionalRateBoxA' => 'easypost_package_usps_RegionalRateBoxA',
|
||||
'RegionalRateBoxB' => 'easypost_package_usps_RegionalRateBoxB',
|
||||
'RegionalRateBoxC' => 'easypost_package_usps_RegionalRateBoxC',
|
||||
'LargeFlatRateBoardGameBox' => 'easypost_package_usps_LargeFlatRateBoardGameBox',
|
||||
),
|
||||
'easypost_package_ups' => array(
|
||||
'UPSLetter' => 'easypost_package_ups_UPSLetter',
|
||||
'UPSExpressBox' => 'easypost_package_ups_UPSExpressBox',
|
||||
'UPS25kgBox' => 'easypost_package_ups_UPS25kgBox',
|
||||
'UPS10kgBox' => 'easypost_package_ups_UPS10kgBox',
|
||||
'Tube' => 'easypost_package_ups_Tube',
|
||||
'Pak' => 'easypost_package_ups_Pak',
|
||||
'Pallet' => 'easypost_package_ups_Pallet',
|
||||
'SmallExpressBox' => 'easypost_package_ups_SmallExpressBox',
|
||||
'MediumExpressBox' => 'easypost_package_ups_MediumExpressBox',
|
||||
'LargeExpressBox' => 'easypost_package_ups_LargeExpressBox',
|
||||
),
|
||||
'easypost_package_fedex' => array(
|
||||
'FedExEnvelope' => 'easypost_package_fedex_FedExEnvelope',
|
||||
'FedExBox' => 'easypost_package_fedex_FedExBox',
|
||||
'FedExPak' => 'easypost_package_fedex_FedExPak',
|
||||
'FedExTube' => 'easypost_package_fedex_FedExTube',
|
||||
'FedEx10kgBox' => 'easypost_package_fedex_FedEx10kgBox',
|
||||
'FedEx25kgBox' => 'easypost_package_fedex_FedEx25kgBox',
|
||||
),
|
||||
),
|
||||
'toggles' => array(
|
||||
'custom' => array( 'easypost_package_length', 'easypost_package_width', 'easypost_package_height' )
|
||||
)
|
||||
), NULL, NULL, NULL, 'easypost_package' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_length', $lengthInInches, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_length' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_width', $widthInInches, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_width' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_height', $heightInInches, NULL, array(), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' and \IPS\Request::i()->easypost_package == 'custom' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, \IPS\Member::loggedIn()->language()->addToStack('inches'), 'easypost_package_height' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'easypost_package_weight', $weightInOz, NULL, array( 'decimals' => 1 ), function( $val )
|
||||
{
|
||||
if ( !$val and \IPS\Request::i()->shipment_ship_method == 'easypost' )
|
||||
{
|
||||
throw new \DomainException('form_required');
|
||||
}
|
||||
}, NULL, 'oz', 'easypost_package_weight' ) );
|
||||
|
||||
$matrix = NULL;
|
||||
$fromCountry = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->easypost_address ?: \IPS\Settings::i()->site_address )->country;
|
||||
if ( $fromCountry != $shipment->data['address']['country'] )
|
||||
{
|
||||
$originCountries = array();
|
||||
foreach ( \IPS\GeoLocation::$countries as $code )
|
||||
{
|
||||
$originCountries[ $code ] = 'country-' . $code;
|
||||
}
|
||||
|
||||
$matrix = new \IPS\Helpers\Form\Matrix;
|
||||
$matrix->columns = array(
|
||||
'epc_description' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value, TRUE );
|
||||
},
|
||||
'epc_quantity' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Number( $key, $value ?: 1, TRUE );
|
||||
},
|
||||
'epc_value' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Number( $key, $value ?: 0, TRUE, array( 'decimals' => TRUE ) );
|
||||
},
|
||||
'epc_weight' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value ?: 0, TRUE, array( 'decimals' => 1 ) );
|
||||
},
|
||||
'epc_origin' => function( $key, $value, $data ) use ( $originCountries, $fromCountry )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Select( $key, $value ?: $fromCountry, FALSE, array( 'options' => $originCountries ) );
|
||||
},
|
||||
'epc_hs_tarrif' => function( $key, $value, $data )
|
||||
{
|
||||
return new \IPS\Helpers\Form\Text( $key, $value, FALSE, array( 'maxLength' => 6, 'placeholder' => \IPS\Member::loggedIn()->language()->addToStack('optional') ) );
|
||||
},
|
||||
);
|
||||
foreach ( $shipment->items as $item )
|
||||
{
|
||||
$weight = new \IPS\nexus\Shipping\Weight( $item['weight']['kilograms'] );
|
||||
$matrix->rows[] = array(
|
||||
'epc_description' => $item['name'],
|
||||
'epc_quantity' => $item['quantity'],
|
||||
'epc_value' => $item['price']['currency'] === 'USD' ? $item['price']['amount'] : 0,
|
||||
'epc_weight' => round( $weight->float('oz'), 1 )
|
||||
);
|
||||
}
|
||||
|
||||
$form->addHeader( 'easypost_customs_header' );
|
||||
$form->addMatrix( 'easypost_customs_details', $matrix );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'o_tracknumber', NULL, FALSE, array( 'maxLength' => 255 ), NULL, NULL, NULL, 'o_tracknumber' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'tracking_url', NULL, FALSE, array( 'maxLength' => 255 ), NULL, NULL, NULL, 'tracking_url' ) );
|
||||
|
||||
/* Handle Submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
/* EasyPost */
|
||||
if ( isset( $values['shipment_ship_method'] ) AND $values['shipment_ship_method'] === 'easypost' )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Parcel Data */
|
||||
if ( $values['easypost_package'] === 'custom' )
|
||||
{
|
||||
$parcelData = array(
|
||||
'length' => $values['easypost_package_length'],
|
||||
'width' => $values['easypost_package_width'],
|
||||
'height' => $values['easypost_package_height'],
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$parcelData = array( 'predefined_package' => $values['easypost_package'] );
|
||||
}
|
||||
$parcelData['weight'] = $values['easypost_package_weight'];
|
||||
|
||||
/* Customs Info */
|
||||
$customsInfo = NULL;
|
||||
if ( isset( $values['easypost_customs_details'] ) )
|
||||
{
|
||||
$customItems = array();
|
||||
$totalValue = 0;
|
||||
foreach ( $values['easypost_customs_details'] as $customItem )
|
||||
{
|
||||
if ( $customItem['epc_description'] )
|
||||
{
|
||||
$totalValue += $customItem['epc_value'];
|
||||
$customItems[] = array(
|
||||
'description' => $customItem['epc_description'],
|
||||
'quantity' => $customItem['epc_quantity'],
|
||||
'value' => $customItem['epc_value'],
|
||||
'weight' => $customItem['epc_weight'],
|
||||
'hs_tariff_number' => $customItem['epc_hs_tarrif'],
|
||||
'origin_country' => $customItem['epc_origin'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$customsInfo = array(
|
||||
'eel_pfc' => ( $totalValue < 2500 ) ? 'NOEEI 30.37(a)' : '',
|
||||
'contents_type' => 'merchandise',
|
||||
'customs_items' => $customItems
|
||||
);
|
||||
}
|
||||
|
||||
/* Send API call */
|
||||
$toAddress = $shipment->data['address'];
|
||||
$fromAddress = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->easypost_address ?: \IPS\Settings::i()->site_address );
|
||||
$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,
|
||||
'city' => $toAddress['city'],
|
||||
'state' => $toAddress['region'],
|
||||
'zip' => $toAddress['postalCode'],
|
||||
'country' => $toAddress['country'],
|
||||
'name' => $shipment->data['cm_first_name'] . ' ' . $shipment->data['cm_last_name'],
|
||||
'phone' => $shipment->data['cm_phone'],
|
||||
'email' => $shipment->invoice->member->email
|
||||
),
|
||||
'from_address' => array(
|
||||
'street1' => array_shift( $fromAddress->addressLines ),
|
||||
'street2' => \count( $fromAddress->addressLines ) ? implode( ', ', $fromAddress->addressLines ) : NULL,
|
||||
'city' => $fromAddress->city,
|
||||
'state' => $fromAddress->region,
|
||||
'zip' => $fromAddress->postalCode,
|
||||
'country' => $fromAddress->country,
|
||||
'company' => \IPS\Settings::i()->board_name,
|
||||
'phone' => \IPS\Settings::i()->easypost_phone,
|
||||
'email' => \IPS\Settings::i()->email_in
|
||||
),
|
||||
'parcel' => $parcelData,
|
||||
'customs_info' => $customsInfo
|
||||
) ) )->decodeJson();
|
||||
|
||||
if ( !\count( $easyPost['rates'] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_no_easypost', '1X193/6', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=payments&controller=shipping&do=easypost&id={$easyPost['id']}&shipment={$shipment->id}" ) );
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/7', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
}
|
||||
/* Manual */
|
||||
else
|
||||
{
|
||||
$shipment->status = \IPS\nexus\Shipping\Order::STATUS_SHIPPED;
|
||||
$shipment->shipped_date = new \IPS\DateTime;
|
||||
if ( $values['o_tracknumber'] )
|
||||
{
|
||||
$shipment->tracknumber = $values['o_tracknumber'];
|
||||
}
|
||||
if ( $values['tracking_url'] )
|
||||
{
|
||||
$shipment->service = $values['tracking_url'];
|
||||
}
|
||||
$shipment->save();
|
||||
$shipment->sendNotification();
|
||||
}
|
||||
|
||||
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id ) );
|
||||
$this->_redirect( $shipment );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* EasyPost
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function easypost()
|
||||
{
|
||||
/* Get Data */
|
||||
try
|
||||
{
|
||||
$easyPost = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . \IPS\Request::i()->id )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->get()->decodeJson();
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->shipment );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/8', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
|
||||
/* Gigure out our options */
|
||||
$selected = NULL;
|
||||
$options = array();
|
||||
$descriptions = array();
|
||||
foreach ( $easyPost['rates'] as $rate )
|
||||
{
|
||||
if ( $rate['service'] === $shipment->api_service )
|
||||
{
|
||||
$selected = $rate['id'];
|
||||
}
|
||||
|
||||
$service = '';
|
||||
for ( $i=0; $i<\strlen( $rate['service'] ); $i++ )
|
||||
{
|
||||
if ( \strtoupper( $rate['service'][ $i ] ) === $rate['service'][ $i ] )
|
||||
{
|
||||
$service .= " {$rate['service'][ $i ]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$service .= $rate['service'][ $i ];
|
||||
}
|
||||
}
|
||||
|
||||
$options[ $rate['id'] ] = $rate['carrier'] . $service . ' - ' . new \IPS\nexus\Money( $rate['rate'], $rate['currency'] );
|
||||
if ( $rate['est_delivery_days'] )
|
||||
{
|
||||
$descriptions[ $rate['id'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'easypost_rates_desc', FALSE, array( 'sprintf' => array( $rate['est_delivery_days'] ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Build form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'easypost_rate', $selected, TRUE, array( 'options' => $options, 'descriptions' => $descriptions ) ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$response = \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments/' . \IPS\Request::i()->id . '/buy' )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->post( array(
|
||||
'rate' => array(
|
||||
'id' => $values['easypost_rate']
|
||||
)
|
||||
) )->decodeJson();
|
||||
|
||||
if ( isset( $response['error'] ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/9', 500, '', array(), $response['error']['message'] );
|
||||
}
|
||||
|
||||
$shipment->label = $response['postage_label']['label_url'];
|
||||
$shipment->tracknumber = $response['tracking_code'];
|
||||
$shipment->extra = json_encode( array( 'shipment' => $response['selected_rate']['shipment_id'], 'rate' => $response['selected_rate']['id'] ) );
|
||||
$shipment->status = \IPS\nexus\Shipping\Order::STATUS_SHIPPED;
|
||||
$shipment->shipped_date = new \IPS\DateTime;
|
||||
$shipment->save();
|
||||
$shipment->sendNotification();
|
||||
|
||||
\IPS\Output::i()->redirect( $shipment->acpUrl() );
|
||||
}
|
||||
catch ( \IPS\Http\Request\Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'err_err_easypost', '3X193/A', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/* How much did the customer pay for shipping? */
|
||||
$invoiceSummary = $shipment->invoice->summary();
|
||||
$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;
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'shipment_number', FALSE, array( 'sprintf' => array( $shipment->id ) ) );
|
||||
\IPS\Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cancel()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_edit' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/4', 404, '' );
|
||||
}
|
||||
|
||||
/* Cancel */
|
||||
$shipment->status = $shipment::STATUS_CANCELED;
|
||||
$shipment->save();
|
||||
|
||||
/* Log */
|
||||
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'type' => 'canc' ) );
|
||||
|
||||
/* Redirect */
|
||||
$this->_redirect( $shipment );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'shiporders_delete' );
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/5', 404, '' );
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
$shipment->delete();
|
||||
|
||||
/* Log */
|
||||
try
|
||||
{
|
||||
$shipment->invoice->member->log( 'shipping', array( 'id' => $shipment->id, 'deleted' => TRUE ) );
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) {}
|
||||
|
||||
/* Redirect */
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printout()
|
||||
{
|
||||
/* Load */
|
||||
try
|
||||
{
|
||||
$shipment = \IPS\nexus\Shipping\Order::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X193/3', 404, '' );
|
||||
}
|
||||
$data = $shipment->data;
|
||||
|
||||
if ( \IPS\Request::i()->print === 'apilabel' )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $shipment->label, 200, 'application/pdf' );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->print === 'label' )
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate('shiporders', 'nexus', 'global')->packingLabel( $shipment );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'shipping.css', 'nexus' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = \IPS\Theme::i()->getTemplate('shiporders', 'nexus', 'global')->packingSheet( $shipment );
|
||||
\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' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Shipping\Order $shipment The shipment
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Shipping\Order $shipment )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
{
|
||||
switch ( \IPS\Request::i()->r )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $shipment->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
\IPS\Output::i()->redirect( $shipment->invoice->acpUrl() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $shipment->member->acpUrl() );
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=shipping') );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl() );
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Shipping Rates
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 13 Feb 2014
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shipping
|
||||
*/
|
||||
class _shippingrates extends \IPS\Node\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Shipping\FlatRate';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
\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', 'global' )->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' => $this->url,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect after save
|
||||
*
|
||||
* @param \IPS\Node\Model|NULL $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, \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 ( (int) $val !== 0 )
|
||||
{
|
||||
$allAreZero = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $allAreZero )
|
||||
{
|
||||
$haveNoLowerLimit = TRUE;
|
||||
}
|
||||
}
|
||||
elseif ( (int) $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.02 ) # @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.02 ) # @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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,35 +12,40 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Node\Controller;
|
||||
use function defined;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* tax
|
||||
*/
|
||||
class _tax extends \IPS\Node\Controller
|
||||
class tax extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = 'IPS\nexus\Tax';
|
||||
protected string $nodeClass = 'IPS\nexus\Tax';
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'tax_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'tax_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
}
|
||||
@@ -12,31 +12,62 @@
|
||||
namespace IPS\nexus\modules\admin\payments;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\core\AdminNotification;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\nexus\Transaction;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use RuntimeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
|
||||
use const IPS\Helpers\Table\SEARCH_DATE_RANGE;
|
||||
use const IPS\Helpers\Table\SEARCH_MEMBER;
|
||||
use const IPS\Helpers\Table\SEARCH_NODE;
|
||||
use const IPS\Helpers\Table\SEARCH_NUMERIC;
|
||||
use const IPS\Helpers\Table\SEARCH_SELECT;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transactions
|
||||
*/
|
||||
class _transactions extends \IPS\Dispatcher\Controller
|
||||
class transactions extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_manage' );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'transaction.css', 'nexus', 'admin' ) );
|
||||
Dispatcher::i()->checkAcpPermission( 'transactions_manage' );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'transaction.css', 'nexus', 'admin' ) );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -45,30 +76,30 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* 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 = Transaction::table( array( array( 't_status<>?', Transaction::STATUS_PENDING ) ), Url::internal( 'app=nexus&module=payments&controller=transactions' ), 't' );
|
||||
$table->filters = array(
|
||||
'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 ) ) ),
|
||||
'trans_attention_required' => array( Db::i()->in( 't_status', array( Transaction::STATUS_HELD, Transaction::STATUS_WAITING, Transaction::STATUS_REVIEW, Transaction::STATUS_DISPUTED ) ) ),
|
||||
);
|
||||
$table->advancedSearch = array(
|
||||
't_id' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
't_status' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => \IPS\nexus\Transaction::statuses(), 'multiple' => TRUE ) ),
|
||||
't_member' => \IPS\Helpers\Table\SEARCH_MEMBER,
|
||||
't_amount' => \IPS\Helpers\Table\SEARCH_NUMERIC,
|
||||
't_method' => array( \IPS\Helpers\Table\SEARCH_NODE, array( 'class' => '\IPS\nexus\Gateway' ) ),
|
||||
't_date' => \IPS\Helpers\Table\SEARCH_DATE_RANGE,
|
||||
't_id' => SEARCH_CONTAINS_TEXT,
|
||||
't_status' => array( SEARCH_SELECT, array( 'options' => Transaction::statuses(), 'multiple' => TRUE ) ),
|
||||
't_member' => SEARCH_MEMBER,
|
||||
't_amount' => SEARCH_NUMERIC,
|
||||
't_method' => array( SEARCH_NODE, array( 'class' => '\IPS\nexus\Gateway' ) ),
|
||||
't_date' => SEARCH_DATE_RANGE,
|
||||
);
|
||||
$table->quickSearch = 't_id';
|
||||
|
||||
/* Display */
|
||||
if ( isset( \IPS\Request::i()->attn ) and \IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( '( t_status=? OR t_status=? OR t_status=? )', \IPS\nexus\Transaction::STATUS_HELD, \IPS\nexus\Transaction::STATUS_REVIEW, \IPS\nexus\Transaction::STATUS_DISPUTED ) ) )
|
||||
if ( isset( Request::i()->attn ) and Db::i()->select( 'COUNT(*)', 'nexus_transactions', array( '( t_status=? OR t_status=? OR t_status=? )', Transaction::STATUS_HELD, Transaction::STATUS_REVIEW, Transaction::STATUS_DISPUTED ) ) )
|
||||
{
|
||||
$table->filter = 'trans_attention_required';
|
||||
}
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__nexus_payments_transactions');
|
||||
\IPS\Output::i()->output = (string) $table;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__nexus_payments_transactions');
|
||||
Output::i()->output = (string) $table;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,21 +107,21 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function view()
|
||||
public function view() : void
|
||||
{
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
$transaction = Transaction::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/8', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X186/8', 404, '' );
|
||||
}
|
||||
|
||||
/* Output */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_number', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'transactions' )->view( $transaction );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'transaction_number', FALSE, array( 'sprintf' => array( $transaction->id ) ) );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'transactions' )->view( $transaction );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,26 +129,27 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function approve()
|
||||
public function approve() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
$transaction = Transaction::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/9', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X186/9', 404, '' );
|
||||
}
|
||||
|
||||
$method = $transaction->method;
|
||||
|
||||
/* Can we approve it? */
|
||||
if ( !$method or !\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 ) ) )
|
||||
if ( !$method or !in_array( $transaction->status, array( Transaction::STATUS_WAITING, Transaction::STATUS_HELD, Transaction::STATUS_REVIEW, Transaction::STATUS_GATEWAY_PENDING, Transaction::STATUS_DISPUTED ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/A', 403, '' );
|
||||
Output::i()->error( 'transaction_status_err', '2X186/A', 403, '' );
|
||||
}
|
||||
|
||||
/* Log it */
|
||||
@@ -125,7 +157,7 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'status' => Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id
|
||||
) );
|
||||
}
|
||||
@@ -133,28 +165,29 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
/* Do it */
|
||||
try
|
||||
{
|
||||
if ( $transaction->status !== \IPS\nexus\Transaction::STATUS_DISPUTED )
|
||||
if ( $transaction->status !== Transaction::STATUS_DISPUTED )
|
||||
{
|
||||
$transaction->capture();
|
||||
}
|
||||
$transaction->approve( \IPS\Member::loggedIn() );
|
||||
|
||||
$transaction->approve( Member::loggedIn() );
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
catch ( LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '3X186/2', 500, '' );
|
||||
Output::i()->error( $e->getMessage(), '3X186/2', 500, '' );
|
||||
}
|
||||
catch ( \RuntimeException $e )
|
||||
catch ( RuntimeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_capture_err', '3X186/3', 500, '' );
|
||||
Output::i()->error( 'transaction_capture_err', '3X186/3', 500, '' );
|
||||
}
|
||||
|
||||
/* Send Email */
|
||||
$transaction->sendNotification();
|
||||
|
||||
/* Redirect */
|
||||
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->queueStatus )
|
||||
if ( Request::i()->isAjax() and 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 ) ) );
|
||||
Output::i()->json( array( 'message' => Member::loggedIn()->language()->addToStack('tstatus_okay_set'), 'queue' => \IPS\nexus\extensions\core\AdminNotifications\Transaction::queueHtml( Request::i()->queueStatus ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -167,33 +200,32 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function review()
|
||||
public function review() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
$transaction = Transaction::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/C', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X186/C', 404, '' );
|
||||
}
|
||||
$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( Transaction::STATUS_WAITING, Transaction::STATUS_HELD ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/B', 403, '' );
|
||||
Output::i()->error( 'transaction_status_err', '2X186/B', 403, '' );
|
||||
}
|
||||
|
||||
/* Set it */
|
||||
$extra = $transaction->extra;
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REVIEW, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
|
||||
$extra['history'][] = array( 's' => Transaction::STATUS_REVIEW, 'on' => time(), 'by' => Member::loggedIn()->member_id );
|
||||
$transaction->extra = $extra;
|
||||
$transaction->status = \IPS\nexus\Transaction::STATUS_REVIEW;
|
||||
$transaction->status = Transaction::STATUS_REVIEW;
|
||||
$transaction->save();
|
||||
|
||||
/* Log it */
|
||||
@@ -201,59 +233,18 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_REVIEW,
|
||||
'status' => Transaction::STATUS_REVIEW,
|
||||
'id' => $transaction->id
|
||||
) );
|
||||
}
|
||||
|
||||
/* 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 )
|
||||
{
|
||||
$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 )
|
||||
{
|
||||
$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"] = $extraData;
|
||||
if ( \count( \IPS\nexus\Support\StockAction::roots() ) )
|
||||
{
|
||||
$_SESSION["wizard-{$key}-step"] = 'stock_action';
|
||||
}
|
||||
else
|
||||
{
|
||||
$_SESSION["wizard-{$key}-step"] = 'request_details';
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION["wizard-{$key}-data"]['transaction'] = $transaction->id;
|
||||
$_SESSION["wizard-{$key}-data"]['ref'] = isset( \IPS\Request::i()->r ) ? \IPS\Request::i()->r : 'v';
|
||||
|
||||
\IPS\Output::i()->redirect( $createUrl );
|
||||
}
|
||||
AdminNotification::send( 'nexus', 'Transaction', Transaction::STATUS_REVIEW, TRUE, $transaction );
|
||||
|
||||
/* Redirect */
|
||||
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->queueStatus )
|
||||
if ( Request::i()->isAjax() and 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 ) ) );
|
||||
Output::i()->json( array( 'message' => Member::loggedIn()->language()->addToStack('tstatus_revw_set'), 'queue' => \IPS\nexus\extensions\core\AdminNotifications\Transaction::queueHtml( Request::i()->queueStatus ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -266,38 +257,37 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function void()
|
||||
public function void() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Dispatcher::i()->checkAcpPermission( 'transactions_edit' );
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
$transaction = Transaction::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/4', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X186/4', 404, '' );
|
||||
}
|
||||
$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( Transaction::STATUS_WAITING, Transaction::STATUS_GATEWAY_PENDING ) ) and ( !$transaction->auth or !in_array( $transaction->status, array( Transaction::STATUS_HELD, Transaction::STATUS_REVIEW ) ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/5', 403, '' );
|
||||
Output::i()->error( 'transaction_status_err', '2X186/5', 403, '' );
|
||||
}
|
||||
|
||||
/* Void it */
|
||||
try
|
||||
{
|
||||
$transaction->void( $transaction );
|
||||
$transaction->void();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
if ( !isset( \IPS\Request::i()->override ) )
|
||||
if ( !isset( Request::i()->override ) )
|
||||
{
|
||||
\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() );
|
||||
Output::i()->error( 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() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,9 +295,9 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
$transaction->sendNotification();
|
||||
|
||||
/* Redirect */
|
||||
if ( \IPS\Request::i()->isAjax() and \IPS\Request::i()->queueStatus )
|
||||
if ( Request::i()->isAjax() and 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 ) ) );
|
||||
Output::i()->json( array( 'message' => Member::loggedIn()->language()->addToStack('tstatus_fail_set'), 'queue' => \IPS\nexus\extensions\core\AdminNotifications\Transaction::queueHtml( Request::i()->queueStatus ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -320,25 +310,25 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function refund()
|
||||
public function refund() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_refund' );
|
||||
Dispatcher::i()->checkAcpPermission( 'transactions_refund' );
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
$transaction = Transaction::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/D', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X186/D', 404, '' );
|
||||
}
|
||||
$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, \IPS\nexus\Transaction::STATUS_DISPUTED ) ) )
|
||||
if ( !in_array( $transaction->status, array( Transaction::STATUS_PAID, Transaction::STATUS_HELD, Transaction::STATUS_REVIEW, Transaction::STATUS_PART_REFUNDED, Transaction::STATUS_DISPUTED ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'transaction_status_err', '2X186/E', 403, '' );
|
||||
Output::i()->error( 'transaction_status_err', '2X186/E', 403, '' );
|
||||
}
|
||||
|
||||
/* What are the refund methods? */
|
||||
@@ -366,22 +356,22 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
$refundMethods['none'] = 'refund_method_none';
|
||||
|
||||
/* 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 = new Form;
|
||||
$form->add( new Radio( 'refund_method', ( $method and $method::SUPPORTS_REFUNDS ) ? 'gateway' : 'credit', TRUE, array( 'options' => $refundMethods, 'toggles' => $refundMethodToggles ) ) );
|
||||
if ( $refundReasons )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'refund_reason', NULL, FALSE, array( 'options' => $refundReasons ), NULL, NULL, NULL, 'refund_reason' ) );
|
||||
$form->add( new Radio( 'refund_reason', NULL, FALSE, array( 'options' => $refundReasons ), NULL, NULL, NULL, 'refund_reason' ) );
|
||||
}
|
||||
if ( $method and $method::SUPPORTS_REFUNDS and $method::SUPPORTS_PARTIAL_REFUNDS )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'refund_amount', 0, TRUE, array(
|
||||
$form->add( new 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 ) )
|
||||
? Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array(
|
||||
new Money( $transaction->amount->amount->subtract( $transaction->partial_refund->amount ), $transaction->currency ) )
|
||||
) )
|
||||
: \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) )
|
||||
: Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) )
|
||||
),
|
||||
'max' => (string) $transaction->amount->amount->subtract( $transaction->partial_refund->amount ),
|
||||
'decimals' => TRUE
|
||||
@@ -389,19 +379,19 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( $transaction->credit->amount->isGreaterThanZero() )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['refund_amount_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get('refund_amount_descwarn'), $transaction->credit );
|
||||
Member::loggedIn()->language()->words['refund_amount_desc'] = sprintf( 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(
|
||||
$form->add( new 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 ) )
|
||||
? Member::loggedIn()->language()->addToStack( 'refund_full_remaining', FALSE, array( 'sprintf' => array(
|
||||
new Money( $transaction->amount->amount->subtract( $transaction->credit->amount ), $transaction->currency ) )
|
||||
) )
|
||||
: \IPS\Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) )
|
||||
: Member::loggedIn()->language()->addToStack( 'refund_full', FALSE, array( 'sprintf' => array( $transaction->amount ) ) )
|
||||
),
|
||||
'max' => (string) $transaction->amount->amount->subtract( $transaction->credit->amount ),
|
||||
'decimals' => TRUE
|
||||
@@ -409,43 +399,43 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
|
||||
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 );
|
||||
Member::loggedIn()->language()->words['refund_credit_amount_desc'] = sprintf( 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 );
|
||||
$form->add( new YesNo( 'refund_reverse_credit', TRUE, TRUE, array( 'togglesOn' => array( 'form_refund_reverse_credit_warning' ) ), NULL, NULL, NULL, 'refund_reverse_credit' ) );
|
||||
Member::loggedIn()->language()->words['refund_reverse_credit'] = sprintf( 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' );
|
||||
Member::loggedIn()->language()->words['refund_reverse_credit_warning'] = Member::loggedIn()->language()->addToStack( 'account_credit_remove_neg' );
|
||||
}
|
||||
}
|
||||
if ( $transaction->invoice !== NULL and $transaction->invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
|
||||
if ( $transaction->invoice !== NULL and $transaction->invoice->status === Invoice::STATUS_PAID )
|
||||
{
|
||||
$field = new \IPS\Helpers\Form\Radio( 'refund_invoice_status', \IPS\nexus\Invoice::STATUS_PENDING, TRUE, array(
|
||||
$field = new Radio( 'refund_invoice_status', Invoice::STATUS_PENDING, TRUE, array(
|
||||
'options' => array(
|
||||
\IPS\nexus\Invoice::STATUS_PAID => 'refund_invoice_paid',
|
||||
\IPS\nexus\Invoice::STATUS_PENDING => 'refund_invoice_pending',
|
||||
\IPS\nexus\Invoice::STATUS_CANCELED => 'refund_invoice_canceled',
|
||||
Invoice::STATUS_PAID => 'refund_invoice_paid',
|
||||
Invoice::STATUS_PENDING => 'refund_invoice_pending',
|
||||
Invoice::STATUS_CANCELED => 'refund_invoice_canceled',
|
||||
),
|
||||
'toggles' => array(
|
||||
\IPS\nexus\Invoice::STATUS_PENDING => array( 'form_refund_invoice_status_warning' ),
|
||||
\IPS\nexus\Invoice::STATUS_CANCELED => array( 'form_refund_invoice_status_warning' )
|
||||
Invoice::STATUS_PENDING => array( 'form_refund_invoice_status_warning' ),
|
||||
Invoice::STATUS_CANCELED => array( 'form_refund_invoice_status_warning' )
|
||||
)
|
||||
) );
|
||||
$field->warningBox = \IPS\Theme::i()->getTemplate('invoices')->unpaidConsequences( $transaction->invoice );
|
||||
$field->warningBox = 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' ) ) ) );
|
||||
$form->add( new 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() )
|
||||
if ( 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'] );
|
||||
unset( Member::loggedIn()->language()->words['refund_cancel_billing_agreement_warning'] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,9 +451,9 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$transaction->billing_agreement->cancel();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'billing_agreement_cancel_error', '3X186/G', 500, '', array(), $e->getMessage() );
|
||||
Output::i()->error( 'billing_agreement_cancel_error', '3X186/G', 500, '', array(), $e->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -487,21 +477,21 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
$amount = $values['refund_credit_amount'];
|
||||
}
|
||||
|
||||
$transaction->refund( $values['refund_method'], $amount, isset( $values['refund_reason'] ) ? $values['refund_reason'] : NULL );
|
||||
$transaction->refund( $values['refund_method'], $amount, $values['refund_reason'] ?? NULL);
|
||||
}
|
||||
catch ( \LogicException $e )
|
||||
catch ( LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( $e->getMessage(), '1X186/1', 500, '' );
|
||||
Output::i()->error( $e->getMessage(), '1X186/1', 500, '' );
|
||||
}
|
||||
catch ( \RuntimeException $e )
|
||||
catch ( RuntimeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'refund_failed', '3X186/7', 500, '' );
|
||||
Output::i()->error( 'refund_failed', '3X186/7', 500, '' );
|
||||
}
|
||||
|
||||
/* Handle invoice */
|
||||
if( $transaction->invoice !== NULL )
|
||||
{
|
||||
if ( isset( $values['refund_invoice_status'] ) and $values['refund_invoice_status'] !== \IPS\nexus\Invoice::STATUS_PAID )
|
||||
if ( isset( $values['refund_invoice_status'] ) and $values['refund_invoice_status'] !== Invoice::STATUS_PAID )
|
||||
{
|
||||
$transaction->invoice->markUnpaid( $values['refund_invoice_status'] );
|
||||
|
||||
@@ -524,8 +514,8 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
$this->_redirect( $transaction );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'transaction_refund_title', FALSE, array( 'sprintf' => array( $transaction->amount ) ) );
|
||||
\IPS\Output::i()->output = $form;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'transaction_refund_title', FALSE, array( 'sprintf' => array( $transaction->amount ) ) );
|
||||
Output::i()->output = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -533,21 +523,21 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'transactions_delete' );
|
||||
Dispatcher::i()->checkAcpPermission( 'transactions_delete' );
|
||||
|
||||
/* Make sure the user confirmed the deletion */
|
||||
\IPS\Request::i()->confirmedDelete();
|
||||
Request::i()->confirmedDelete();
|
||||
|
||||
/* Load Transaction */
|
||||
try
|
||||
{
|
||||
$transaction = \IPS\nexus\Transaction::load( \IPS\Request::i()->id );
|
||||
$transaction = Transaction::load( Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2X186/F', 404, '' );
|
||||
Output::i()->error( 'node_error', '2X186/F', 404, '' );
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
@@ -565,50 +555,50 @@ class _transactions extends \IPS\Dispatcher\Controller
|
||||
) );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException )
|
||||
{
|
||||
// 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')->getSafeUrlFromFilters());
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=transactions')->getSafeUrlFromFilters());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redirect
|
||||
*
|
||||
* @param \IPS\nexus\Transaction $transaction The transaction
|
||||
* @param Transaction $transaction The transaction
|
||||
* @return void
|
||||
*/
|
||||
protected function _redirect( \IPS\nexus\Transaction $transaction )
|
||||
protected function _redirect( Transaction $transaction ) : void
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->r ) )
|
||||
if ( isset( Request::i()->r ) )
|
||||
{
|
||||
switch ( \IPS\Request::i()->r )
|
||||
switch ( Request::i()->r )
|
||||
{
|
||||
case 'v':
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl()->getSafeUrlFromFilters() );
|
||||
Output::i()->redirect( $transaction->acpUrl()->getSafeUrlFromFilters() );
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
\IPS\Output::i()->redirect( $transaction->invoice->acpUrl()->getSafeUrlFromFilters() );
|
||||
Output::i()->redirect( $transaction->invoice->acpUrl()->getSafeUrlFromFilters() );
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
\IPS\Output::i()->redirect( $transaction->member->acpUrl()->getSafeUrlFromFilters());
|
||||
Output::i()->redirect( $transaction->member->acpUrl()->getSafeUrlFromFilters());
|
||||
break;
|
||||
|
||||
case 't':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=nexus&module=payments&controller=transactions')->getSafeUrlFromFilters() );
|
||||
Output::i()->redirect( Url::internal('app=nexus&module=payments&controller=transactions')->getSafeUrlFromFilters() );
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=overview&controller=notifications')->getSafeUrlFromFilters());
|
||||
Output::i()->redirect( Url::internal('app=core&module=overview&controller=notifications')->getSafeUrlFromFilters());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $transaction->acpUrl()->getSafeUrlFromFilters());
|
||||
Output::i()->redirect( $transaction->acpUrl()->getSafeUrlFromFilters());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user